1 /*****************************************************************************
2 * poll.c: I/O event multiplexing
3 *****************************************************************************
4 * Copyright © 2007 Rémi Denis-Courmont
7 * Author: Rémi Denis-Courmont
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
29 #include <vlc_network.h>
31 int poll (struct pollfd *fds, unsigned nfds, int timeout)
33 fd_set rdset, wrset, exset;
34 struct timeval tv = { 0, 0 };
41 for (unsigned i = 0; i < nfds; i++)
47 /* I assume the OS has a solution select overflow if it does not have
48 * poll(). If it did not, we are screwed anyway. */
49 if (fds[i].events & POLLIN)
51 if (fds[i].events & POLLOUT)
53 if (fds[i].events & POLLPRI)
59 div_t d = div (timeout, 1000);
61 tv.tv_usec = d.rem * 1000;
64 val = select (val + 1, &rdset, &wrset, NULL,
65 (timeout >= 0) ? &tv : NULL);
69 for (unsigned i = 0; i < nfds; i++)
72 fds[i].revents = (FD_ISSET (fd, &rdset) ? POLLIN : 0)
73 | (FD_ISSET (fd, &wrset) ? POLLOUT : 0)
74 | (FD_ISSET (fd, &exset) ? POLLPRI : 0);
78 #endif /* !HAVE_POLL */