1 /*****************************************************************************
2 * poll.c: poll() emulation for OS/2
3 *****************************************************************************
4 * Copyright © 2011 KO Myung-Hun <komh@chollian.et>
5 * Copyright © 2007 Rémi Denis-Courmont
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_network.h>
34 int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
39 struct timeval tv = { 0, 0 };
49 for (unsigned i = 0; i < nfds; i++)
53 if (fds[i].fd >= FD_SETSIZE)
62 if (fds[i].events & POLLIN)
64 if (fds[i].events & POLLOUT)
66 if (fds[i].events & POLLPRI)
70 #ifndef HAVE_ALERTABLE_SELECT
71 # warning FIXME! Fix cancellation and remove this crap.
72 if ((timeout < 0) || (timeout > 50))
81 div_t d = div (timeout, 1000);
83 tv.tv_usec = d.rem * 1000;
86 val = select (val + 1, &rdset, &wrset, &exset, &tv);
88 #ifndef HAVE_ALERTABLE_SELECT
92 timeout -= (timeout > 50) ? 50 : timeout;
101 for (unsigned i = 0; i < nfds; i++)
104 fds[i].revents = (FD_ISSET (fd, &rdset) ? POLLIN : 0)
105 | (FD_ISSET (fd, &wrset) ? POLLOUT : 0)
106 | (FD_ISSET (fd, &exset) ? POLLPRI : 0);