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 *****************************************************************************/
33 #include <vlc_network.h>
35 int poll (struct pollfd *fds, unsigned nfds, int timeout)
37 fd_set rdset, wrset, exset;
38 struct timeval tv = { 0, 0 };
45 for (unsigned i = 0; i < nfds; i++)
51 /* I assume the OS has a solution select overflow if it does not have
52 * poll(). If it did not, we are screwed anyway. */
53 if (fds[i].events & POLLIN)
55 if (fds[i].events & POLLOUT)
57 if (fds[i].events & POLLPRI)
63 div_t d = div (timeout, 1000);
65 tv.tv_usec = d.rem * 1000;
68 val = select (val + 1, &rdset, &wrset, &exset,
69 (timeout >= 0) ? &tv : NULL);
73 for (unsigned i = 0; i < nfds; i++)
76 fds[i].revents = (FD_ISSET (fd, &rdset) ? POLLIN : 0)
77 | (FD_ISSET (fd, &wrset) ? POLLOUT : 0)
78 | (FD_ISSET (fd, &exset) ? POLLPRI : 0);
82 #endif /* !HAVE_POLL */