]> git.sesse.net Git - vlc/blob - src/network/poll.c
LGPL
[vlc] / src / network / poll.c
1 /*****************************************************************************
2  * poll.c: I/O event multiplexing
3  *****************************************************************************
4  * Copyright © 2007 Rémi Denis-Courmont
5  * $Id$
6  *
7  * Author: Rémi Denis-Courmont
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29
30 #ifdef HAVE_MAEMO
31 # include <vlc_network.h>
32 # include <signal.h>
33 # include <errno.h>
34 # include <poll.h>
35
36 int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
37 {
38     struct timespec tsbuf, *ts;
39     sigset_t set;
40     int canc, ret;
41
42     if (timeout != -1)
43     {
44         div_t d = div (timeout, 1000);
45         tsbuf.tv_sec = d.quot;
46         tsbuf.tv_nsec = d.rem * 1000000;
47         ts = &tsbuf;
48     }
49     else
50         ts = NULL;
51
52     pthread_sigmask (SIG_BLOCK, NULL, &set);
53     sigdelset (&set, SIGRTMIN);
54
55     canc = vlc_savecancel ();
56     ret = ppoll (fds, nfds, ts, &set);
57     vlc_restorecancel (canc);
58
59     vlc_testcancel ();
60     return ret;
61 }
62
63 #elif defined (HAVE_POLL)
64 # include <vlc_network.h>
65
66 struct pollfd;
67
68 int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
69 {
70     (void)fds; (void)nfds; (void)timeout;
71     abort ();
72 }
73
74 #else
75 # error poll() not implemented!
76 #endif