jscript: Call expressions needling EXPR_NEWREF flag directly.
[wine.git] / libs / port / poll.c
blob7ee585203f4e05d2aa9a93fe5d233a6dd946da32
1 /*
2 * poll function
4 * Copyright 2008 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #ifndef HAVE_POLL
26 #ifdef HAVE_SYS_TIME_H
27 #include <sys/time.h>
28 #endif
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
33 /* we can't include winsock2.h here so we have to duplicate the definitions for Windows */
34 #if defined(__MINGW32__) || defined(_MSC_VER)
36 #define FD_SETSIZE 64
38 typedef struct
40 unsigned int fd_count;
41 int fd_array[FD_SETSIZE]; /* an array of SOCKETs */
42 } fd_set;
44 #define FD_ZERO(set) ((set)->fd_count = 0)
45 #define FD_ISSET(fd, set) __WSAFDIsSet((fd), (set))
46 #define FD_SET(fd, set) do { if ((set)->fd_count < FD_SETSIZE) (set)->fd_array[(set)->fd_count++]=(fd); } while(0)
48 int __stdcall select(int,fd_set*,fd_set*,fd_set*,const struct timeval*);
49 int __stdcall __WSAFDIsSet(int,fd_set*);
51 #endif
53 int poll( struct pollfd *fds, unsigned int count, int timeout )
55 fd_set read_set, write_set, except_set;
56 unsigned int i;
57 int maxfd = -1, ret;
59 FD_ZERO( &read_set );
60 FD_ZERO( &write_set );
61 FD_ZERO( &except_set );
63 for (i = 0; i < count; i++)
65 if (fds[i].fd == -1) continue;
66 if (fds[i].events & (POLLIN|POLLPRI)) FD_SET( fds[i].fd, &read_set );
67 if (fds[i].events & POLLOUT) FD_SET( fds[i].fd, &write_set );
68 FD_SET( fds[i].fd, &except_set ); /* POLLERR etc. are always selected */
69 if (fds[i].fd > maxfd) maxfd = fds[i].fd;
71 if (timeout != -1)
73 struct timeval tv;
74 tv.tv_sec = timeout / 1000;
75 tv.tv_usec = timeout % 1000;
76 ret = select( maxfd + 1, &read_set, &write_set, &except_set, &tv );
78 else ret = select( maxfd + 1, &read_set, &write_set, &except_set, NULL );
80 if (ret >= 0)
82 for (i = 0; i < count; i++)
84 fds[i].revents = 0;
85 if (fds[i].fd == -1) continue;
86 if (FD_ISSET( fds[i].fd, &read_set )) fds[i].revents |= POLLIN;
87 if (FD_ISSET( fds[i].fd, &write_set )) fds[i].revents |= POLLOUT;
88 if (FD_ISSET( fds[i].fd, &except_set )) fds[i].revents |= POLLERR;
91 return ret;
94 #endif /* HAVE_POLL */