12 #include "mono-poll.h"
14 #include <mono/utils/mono-errno.h>
16 #ifdef DISABLE_SOCKETS
20 mono_poll_can_add (mono_pollfd
*ufds
, unsigned int nfds
, int fd
)
26 mono_poll (mono_pollfd
*ufds
, unsigned int nfds
, int timeout
)
28 g_assert_not_reached ();
34 #if defined(HAVE_POLL) && !defined(__APPLE__)
37 mono_poll_can_add (mono_pollfd
*ufds
, unsigned int nfds
, int fd
)
43 mono_poll (mono_pollfd
*ufds
, unsigned int nfds
, int timeout
)
45 return poll (ufds
, nfds
, timeout
);
50 mono_poll_can_add (mono_pollfd
*ufds
, unsigned int nfds
, int fd
)
55 return (nfds
< FD_SETSIZE
);
57 return (fd
< FD_SETSIZE
);
62 mono_poll (mono_pollfd
*ufds
, unsigned int nfds
, int timeout
)
64 struct timeval tv
, *tvptr
;
65 int i
, fd
, events
, affected
, count
;
66 fd_set rfds
, wfds
, efds
;
73 tv
.tv_sec
= timeout
/ 1000;
74 tv
.tv_usec
= (timeout
% 1000) * 1000;
82 for (i
= 0; i
< nfds
; i
++) {
89 if (nexc
>= FD_SETSIZE
) {
90 ufds
[i
].revents
= MONO_POLLNVAL
;
94 if (fd
>= FD_SETSIZE
) {
95 ufds
[i
].revents
= MONO_POLLNVAL
;
100 events
= ufds
[i
].events
;
101 if ((events
& MONO_POLLIN
) != 0)
104 if ((events
& MONO_POLLOUT
) != 0)
114 affected
= select (maxfd
+ 1, &rfds
, &wfds
, &efds
, tvptr
);
115 if (affected
== -1) {
117 int error
= WSAGetLastError ();
119 case WSAEFAULT
: mono_set_errno (EFAULT
); break;
120 case WSAEINVAL
: mono_set_errno (EINVAL
); break;
121 case WSAEINTR
: mono_set_errno (EINTR
); break;
122 /* case WSAEINPROGRESS: mono_set_errno (EINPROGRESS); break; */
123 case WSAEINPROGRESS
: mono_set_errno (EINTR
); break;
124 case WSAENOTSOCK
: mono_set_errno (EBADF
); break;
126 case WSAENETDOWN
: mono_set_errno (ENOSR
); break;
128 default: mono_set_errno (0);
136 for (i
= 0; i
< nfds
&& affected
> 0; i
++) {
141 events
= ufds
[i
].events
;
142 if ((events
& MONO_POLLIN
) != 0 && FD_ISSET (fd
, &rfds
)) {
143 ufds
[i
].revents
|= MONO_POLLIN
;
147 if ((events
& MONO_POLLOUT
) != 0 && FD_ISSET (fd
, &wfds
)) {
148 ufds
[i
].revents
|= MONO_POLLOUT
;
152 if (FD_ISSET (fd
, &efds
)) {
153 ufds
[i
].revents
|= MONO_POLLERR
;
157 if (ufds
[i
].revents
!= 0)
166 #endif /* #ifndef DISABLE_SOCKETS */