12 #include "mono-poll.h"
14 #include <mono/utils/mono-errno.h>
16 #ifdef DISABLE_SOCKETS
20 mono_poll (mono_pollfd
*ufds
, unsigned int nfds
, int timeout
)
22 g_assert_not_reached ();
27 #if defined(HAVE_POLL) && !defined(__APPLE__)
29 mono_poll (mono_pollfd
*ufds
, unsigned int nfds
, int timeout
)
31 return poll (ufds
, nfds
, timeout
);
36 mono_poll (mono_pollfd
*ufds
, unsigned int nfds
, int timeout
)
38 struct timeval tv
, *tvptr
;
39 int i
, fd
, events
, affected
, count
;
40 fd_set rfds
, wfds
, efds
;
47 tv
.tv_sec
= timeout
/ 1000;
48 tv
.tv_usec
= (timeout
% 1000) * 1000;
56 for (i
= 0; i
< nfds
; i
++) {
63 if (nexc
>= FD_SETSIZE
) {
64 ufds
[i
].revents
= MONO_POLLNVAL
;
68 if (fd
>= FD_SETSIZE
) {
69 ufds
[i
].revents
= MONO_POLLNVAL
;
74 events
= ufds
[i
].events
;
75 if ((events
& MONO_POLLIN
) != 0)
78 if ((events
& MONO_POLLOUT
) != 0)
88 affected
= select (maxfd
+ 1, &rfds
, &wfds
, &efds
, tvptr
);
91 int error
= WSAGetLastError ();
93 case WSAEFAULT
: mono_set_errno (EFAULT
); break;
94 case WSAEINVAL
: mono_set_errno (EINVAL
); break;
95 case WSAEINTR
: mono_set_errno (EINTR
); break;
96 /* case WSAEINPROGRESS: mono_set_errno (EINPROGRESS); break; */
97 case WSAEINPROGRESS
: mono_set_errno (EINTR
); break;
98 case WSAENOTSOCK
: mono_set_errno (EBADF
); break;
100 case WSAENETDOWN
: mono_set_errno (ENOSR
); break;
102 default: mono_set_errno (0);
110 for (i
= 0; i
< nfds
&& affected
> 0; i
++) {
115 events
= ufds
[i
].events
;
116 if ((events
& MONO_POLLIN
) != 0 && FD_ISSET (fd
, &rfds
)) {
117 ufds
[i
].revents
|= MONO_POLLIN
;
121 if ((events
& MONO_POLLOUT
) != 0 && FD_ISSET (fd
, &wfds
)) {
122 ufds
[i
].revents
|= MONO_POLLOUT
;
126 if (FD_ISSET (fd
, &efds
)) {
127 ufds
[i
].revents
|= MONO_POLLERR
;
131 if (ufds
[i
].revents
!= 0)
140 #endif /* #ifndef DISABLE_SOCKETS */