Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | *------------------------------------------------------------------------ |
michael@0 | 8 | * File: uxwrap.c |
michael@0 | 9 | * |
michael@0 | 10 | * Our wrapped versions of the Unix select() and poll() system calls. |
michael@0 | 11 | * |
michael@0 | 12 | *------------------------------------------------------------------------ |
michael@0 | 13 | */ |
michael@0 | 14 | |
michael@0 | 15 | #include "primpl.h" |
michael@0 | 16 | |
michael@0 | 17 | #if defined(_PR_PTHREADS) || defined(_PR_GLOBAL_THREADS_ONLY) || defined(QNX) |
michael@0 | 18 | /* Do not wrap select() and poll(). */ |
michael@0 | 19 | #else /* defined(_PR_PTHREADS) || defined(_PR_GLOBAL_THREADS_ONLY) */ |
michael@0 | 20 | /* The include files for select() */ |
michael@0 | 21 | #ifdef IRIX |
michael@0 | 22 | #include <unistd.h> |
michael@0 | 23 | #include <bstring.h> |
michael@0 | 24 | #endif |
michael@0 | 25 | |
michael@0 | 26 | #include <string.h> |
michael@0 | 27 | #include <sys/types.h> |
michael@0 | 28 | #include <sys/time.h> |
michael@0 | 29 | |
michael@0 | 30 | #define ZAP_SET(_to, _width) \ |
michael@0 | 31 | PR_BEGIN_MACRO \ |
michael@0 | 32 | memset(_to, 0, \ |
michael@0 | 33 | ((_width + 8*sizeof(int)-1) / (8*sizeof(int))) \ |
michael@0 | 34 | * sizeof(int) \ |
michael@0 | 35 | ); \ |
michael@0 | 36 | PR_END_MACRO |
michael@0 | 37 | |
michael@0 | 38 | /* see comments in ns/cmd/xfe/mozilla.c (look for "PR_XGetXtHackFD") */ |
michael@0 | 39 | static int _pr_xt_hack_fd = -1; |
michael@0 | 40 | |
michael@0 | 41 | int PR_XGetXtHackFD(void) |
michael@0 | 42 | { |
michael@0 | 43 | int fds[2]; |
michael@0 | 44 | |
michael@0 | 45 | if (_pr_xt_hack_fd == -1) { |
michael@0 | 46 | if (!pipe(fds)) { |
michael@0 | 47 | _pr_xt_hack_fd = fds[0]; |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | return _pr_xt_hack_fd; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | static int (*_pr_xt_hack_okayToReleaseXLock)(void) = 0; |
michael@0 | 54 | |
michael@0 | 55 | void PR_SetXtHackOkayToReleaseXLockFn(int (*fn)(void)) |
michael@0 | 56 | { |
michael@0 | 57 | _pr_xt_hack_okayToReleaseXLock = fn; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | |
michael@0 | 61 | /* |
michael@0 | 62 | *----------------------------------------------------------------------- |
michael@0 | 63 | * select() -- |
michael@0 | 64 | * |
michael@0 | 65 | * Wrap up the select system call so that we can deschedule |
michael@0 | 66 | * a thread that tries to wait for i/o. |
michael@0 | 67 | * |
michael@0 | 68 | *----------------------------------------------------------------------- |
michael@0 | 69 | */ |
michael@0 | 70 | |
michael@0 | 71 | #if defined(HPUX9) |
michael@0 | 72 | int select(size_t width, int *rl, int *wl, int *el, const struct timeval *tv) |
michael@0 | 73 | #elif defined(AIX_RENAME_SELECT) |
michael@0 | 74 | int wrap_select(unsigned long width, void *rl, void *wl, void *el, |
michael@0 | 75 | struct timeval *tv) |
michael@0 | 76 | #elif defined(_PR_SELECT_CONST_TIMEVAL) |
michael@0 | 77 | int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, |
michael@0 | 78 | const struct timeval *tv) |
michael@0 | 79 | #else |
michael@0 | 80 | int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv) |
michael@0 | 81 | #endif |
michael@0 | 82 | { |
michael@0 | 83 | int osfd; |
michael@0 | 84 | _PRUnixPollDesc *unixpds, *unixpd, *eunixpd; |
michael@0 | 85 | PRInt32 pdcnt; |
michael@0 | 86 | PRIntervalTime timeout; |
michael@0 | 87 | int retVal; |
michael@0 | 88 | #if defined(HPUX9) || defined(AIX_RENAME_SELECT) |
michael@0 | 89 | fd_set *rd = (fd_set*) rl; |
michael@0 | 90 | fd_set *wr = (fd_set*) wl; |
michael@0 | 91 | fd_set *ex = (fd_set*) el; |
michael@0 | 92 | #endif |
michael@0 | 93 | |
michael@0 | 94 | #if 0 |
michael@0 | 95 | /* |
michael@0 | 96 | * Easy special case: zero timeout. Simply call the native |
michael@0 | 97 | * select() with no fear of blocking. |
michael@0 | 98 | */ |
michael@0 | 99 | if (tv != NULL && tv->tv_sec == 0 && tv->tv_usec == 0) { |
michael@0 | 100 | #if defined(HPUX9) || defined(AIX_RENAME_SELECT) |
michael@0 | 101 | return _MD_SELECT(width, rl, wl, el, tv); |
michael@0 | 102 | #else |
michael@0 | 103 | return _MD_SELECT(width, rd, wr, ex, tv); |
michael@0 | 104 | #endif |
michael@0 | 105 | } |
michael@0 | 106 | #endif |
michael@0 | 107 | |
michael@0 | 108 | if (!_pr_initialized) { |
michael@0 | 109 | _PR_ImplicitInitialization(); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | #ifndef _PR_LOCAL_THREADS_ONLY |
michael@0 | 113 | if (_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) { |
michael@0 | 114 | return _MD_SELECT(width, rd, wr, ex, tv); |
michael@0 | 115 | } |
michael@0 | 116 | #endif |
michael@0 | 117 | |
michael@0 | 118 | if (width < 0 || width > FD_SETSIZE) { |
michael@0 | 119 | errno = EINVAL; |
michael@0 | 120 | return -1; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | /* Compute timeout */ |
michael@0 | 124 | if (tv) { |
michael@0 | 125 | /* |
michael@0 | 126 | * These acceptable ranges for t_sec and t_usec are taken |
michael@0 | 127 | * from the select() man pages. |
michael@0 | 128 | */ |
michael@0 | 129 | if (tv->tv_sec < 0 || tv->tv_sec > 100000000 |
michael@0 | 130 | || tv->tv_usec < 0 || tv->tv_usec >= 1000000) { |
michael@0 | 131 | errno = EINVAL; |
michael@0 | 132 | return -1; |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | /* Convert microseconds to ticks */ |
michael@0 | 136 | timeout = PR_MicrosecondsToInterval(1000000*tv->tv_sec + tv->tv_usec); |
michael@0 | 137 | } else { |
michael@0 | 138 | /* tv being a NULL pointer means blocking indefinitely */ |
michael@0 | 139 | timeout = PR_INTERVAL_NO_TIMEOUT; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | /* Check for no descriptors case (just doing a timeout) */ |
michael@0 | 143 | if ((!rd && !wr && !ex) || !width) { |
michael@0 | 144 | PR_Sleep(timeout); |
michael@0 | 145 | return 0; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | /* |
michael@0 | 149 | * Set up for PR_Poll(). The PRPollDesc array is allocated |
michael@0 | 150 | * dynamically. If this turns out to have high performance |
michael@0 | 151 | * penalty, one can change to use a large PRPollDesc array |
michael@0 | 152 | * on the stack, and allocate dynamically only when it turns |
michael@0 | 153 | * out to be not large enough. |
michael@0 | 154 | * |
michael@0 | 155 | * I allocate an array of size 'width', which is the maximum |
michael@0 | 156 | * number of fds we may need to poll. |
michael@0 | 157 | */ |
michael@0 | 158 | unixpds = (_PRUnixPollDesc *) PR_CALLOC(width * sizeof(_PRUnixPollDesc)); |
michael@0 | 159 | if (!unixpds) { |
michael@0 | 160 | errno = ENOMEM; |
michael@0 | 161 | return -1; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | pdcnt = 0; |
michael@0 | 165 | unixpd = unixpds; |
michael@0 | 166 | for (osfd = 0; osfd < width; osfd++) { |
michael@0 | 167 | int in_flags = 0; |
michael@0 | 168 | if (rd && FD_ISSET(osfd, rd)) { |
michael@0 | 169 | in_flags |= _PR_UNIX_POLL_READ; |
michael@0 | 170 | } |
michael@0 | 171 | if (wr && FD_ISSET(osfd, wr)) { |
michael@0 | 172 | in_flags |= _PR_UNIX_POLL_WRITE; |
michael@0 | 173 | } |
michael@0 | 174 | if (ex && FD_ISSET(osfd, ex)) { |
michael@0 | 175 | in_flags |= _PR_UNIX_POLL_EXCEPT; |
michael@0 | 176 | } |
michael@0 | 177 | if (in_flags) { |
michael@0 | 178 | unixpd->osfd = osfd; |
michael@0 | 179 | unixpd->in_flags = in_flags; |
michael@0 | 180 | unixpd->out_flags = 0; |
michael@0 | 181 | unixpd++; |
michael@0 | 182 | pdcnt++; |
michael@0 | 183 | } |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | /* |
michael@0 | 187 | * see comments in mozilla/cmd/xfe/mozilla.c (look for |
michael@0 | 188 | * "PR_XGetXtHackFD") |
michael@0 | 189 | */ |
michael@0 | 190 | { |
michael@0 | 191 | int needToLockXAgain; |
michael@0 | 192 | |
michael@0 | 193 | needToLockXAgain = 0; |
michael@0 | 194 | if (rd && (_pr_xt_hack_fd != -1) |
michael@0 | 195 | && FD_ISSET(_pr_xt_hack_fd, rd) && PR_XIsLocked() |
michael@0 | 196 | && (!_pr_xt_hack_okayToReleaseXLock |
michael@0 | 197 | || _pr_xt_hack_okayToReleaseXLock())) { |
michael@0 | 198 | PR_XUnlock(); |
michael@0 | 199 | needToLockXAgain = 1; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | /* This is the potentially blocking step */ |
michael@0 | 203 | retVal = _PR_WaitForMultipleFDs(unixpds, pdcnt, timeout); |
michael@0 | 204 | |
michael@0 | 205 | if (needToLockXAgain) { |
michael@0 | 206 | PR_XLock(); |
michael@0 | 207 | } |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | if (retVal > 0) { |
michael@0 | 211 | /* Compute select results */ |
michael@0 | 212 | if (rd) ZAP_SET(rd, width); |
michael@0 | 213 | if (wr) ZAP_SET(wr, width); |
michael@0 | 214 | if (ex) ZAP_SET(ex, width); |
michael@0 | 215 | |
michael@0 | 216 | /* |
michael@0 | 217 | * The return value can be either the number of ready file |
michael@0 | 218 | * descriptors or the number of set bits in the three fd_set's. |
michael@0 | 219 | */ |
michael@0 | 220 | retVal = 0; /* we're going to recompute */ |
michael@0 | 221 | eunixpd = unixpds + pdcnt; |
michael@0 | 222 | for (unixpd = unixpds; unixpd < eunixpd; unixpd++) { |
michael@0 | 223 | if (unixpd->out_flags) { |
michael@0 | 224 | int nbits = 0; /* The number of set bits on for this fd */ |
michael@0 | 225 | |
michael@0 | 226 | if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) { |
michael@0 | 227 | errno = EBADF; |
michael@0 | 228 | PR_LOG(_pr_io_lm, PR_LOG_ERROR, |
michael@0 | 229 | ("select returns EBADF for %d", unixpd->osfd)); |
michael@0 | 230 | retVal = -1; |
michael@0 | 231 | break; |
michael@0 | 232 | } |
michael@0 | 233 | /* |
michael@0 | 234 | * If a socket has a pending error, it is considered |
michael@0 | 235 | * both readable and writable. (See W. Richard Stevens, |
michael@0 | 236 | * Unix Network Programming, Vol. 1, 2nd Ed., Section 6.3, |
michael@0 | 237 | * pp. 153-154.) We also consider a socket readable if |
michael@0 | 238 | * it has a hangup condition. |
michael@0 | 239 | */ |
michael@0 | 240 | if (rd && (unixpd->in_flags & _PR_UNIX_POLL_READ) |
michael@0 | 241 | && (unixpd->out_flags & (_PR_UNIX_POLL_READ |
michael@0 | 242 | | _PR_UNIX_POLL_ERR | _PR_UNIX_POLL_HUP))) { |
michael@0 | 243 | FD_SET(unixpd->osfd, rd); |
michael@0 | 244 | nbits++; |
michael@0 | 245 | } |
michael@0 | 246 | if (wr && (unixpd->in_flags & _PR_UNIX_POLL_WRITE) |
michael@0 | 247 | && (unixpd->out_flags & (_PR_UNIX_POLL_WRITE |
michael@0 | 248 | | _PR_UNIX_POLL_ERR))) { |
michael@0 | 249 | FD_SET(unixpd->osfd, wr); |
michael@0 | 250 | nbits++; |
michael@0 | 251 | } |
michael@0 | 252 | if (ex && (unixpd->in_flags & _PR_UNIX_POLL_WRITE) |
michael@0 | 253 | && (unixpd->out_flags & PR_POLL_EXCEPT)) { |
michael@0 | 254 | FD_SET(unixpd->osfd, ex); |
michael@0 | 255 | nbits++; |
michael@0 | 256 | } |
michael@0 | 257 | PR_ASSERT(nbits > 0); |
michael@0 | 258 | #if defined(HPUX) || defined(SOLARIS) || defined(OSF1) || defined(AIX) |
michael@0 | 259 | retVal += nbits; |
michael@0 | 260 | #else /* IRIX */ |
michael@0 | 261 | retVal += 1; |
michael@0 | 262 | #endif |
michael@0 | 263 | } |
michael@0 | 264 | } |
michael@0 | 265 | } |
michael@0 | 266 | |
michael@0 | 267 | PR_ASSERT(tv || retVal != 0); |
michael@0 | 268 | PR_LOG(_pr_io_lm, PR_LOG_MIN, ("select returns %d", retVal)); |
michael@0 | 269 | PR_DELETE(unixpds); |
michael@0 | 270 | |
michael@0 | 271 | return retVal; |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | /* |
michael@0 | 275 | * Redefine poll, when supported on platforms, for local threads |
michael@0 | 276 | */ |
michael@0 | 277 | |
michael@0 | 278 | /* |
michael@0 | 279 | * I am commenting out the poll() wrapper for Linux for now |
michael@0 | 280 | * because it is difficult to define _MD_POLL that works on all |
michael@0 | 281 | * Linux varieties. People reported that glibc 2.0.7 on Debian |
michael@0 | 282 | * 2.0 Linux machines doesn't have the __syscall_poll symbol |
michael@0 | 283 | * defined. (WTC 30 Nov. 1998) |
michael@0 | 284 | */ |
michael@0 | 285 | #if defined(_PR_POLL_AVAILABLE) && !defined(LINUX) |
michael@0 | 286 | |
michael@0 | 287 | /* |
michael@0 | 288 | *----------------------------------------------------------------------- |
michael@0 | 289 | * poll() -- |
michael@0 | 290 | * |
michael@0 | 291 | * RETURN VALUES: |
michael@0 | 292 | * -1: fails, errno indicates the error. |
michael@0 | 293 | * 0: timed out, the revents bitmasks are not set. |
michael@0 | 294 | * positive value: the number of file descriptors for which poll() |
michael@0 | 295 | * has set the revents bitmask. |
michael@0 | 296 | * |
michael@0 | 297 | *----------------------------------------------------------------------- |
michael@0 | 298 | */ |
michael@0 | 299 | |
michael@0 | 300 | #include <poll.h> |
michael@0 | 301 | |
michael@0 | 302 | #if defined(AIX_RENAME_SELECT) |
michael@0 | 303 | int wrap_poll(void *listptr, unsigned long nfds, long timeout) |
michael@0 | 304 | #elif (defined(AIX) && !defined(AIX_RENAME_SELECT)) |
michael@0 | 305 | int poll(void *listptr, unsigned long nfds, long timeout) |
michael@0 | 306 | #elif defined(OSF1) || (defined(HPUX) && !defined(HPUX9)) |
michael@0 | 307 | int poll(struct pollfd filedes[], unsigned int nfds, int timeout) |
michael@0 | 308 | #elif defined(HPUX9) |
michael@0 | 309 | int poll(struct pollfd filedes[], int nfds, int timeout) |
michael@0 | 310 | #elif defined(NETBSD) |
michael@0 | 311 | int poll(struct pollfd *filedes, nfds_t nfds, int timeout) |
michael@0 | 312 | #elif defined(OPENBSD) |
michael@0 | 313 | int poll(struct pollfd filedes[], nfds_t nfds, int timeout) |
michael@0 | 314 | #elif defined(FREEBSD) |
michael@0 | 315 | int poll(struct pollfd *filedes, unsigned nfds, int timeout) |
michael@0 | 316 | #else |
michael@0 | 317 | int poll(struct pollfd *filedes, unsigned long nfds, int timeout) |
michael@0 | 318 | #endif |
michael@0 | 319 | { |
michael@0 | 320 | #ifdef AIX |
michael@0 | 321 | struct pollfd *filedes = (struct pollfd *) listptr; |
michael@0 | 322 | #endif |
michael@0 | 323 | struct pollfd *pfd, *epfd; |
michael@0 | 324 | _PRUnixPollDesc *unixpds, *unixpd, *eunixpd; |
michael@0 | 325 | PRIntervalTime ticks; |
michael@0 | 326 | PRInt32 pdcnt; |
michael@0 | 327 | int ready; |
michael@0 | 328 | |
michael@0 | 329 | /* |
michael@0 | 330 | * Easy special case: zero timeout. Simply call the native |
michael@0 | 331 | * poll() with no fear of blocking. |
michael@0 | 332 | */ |
michael@0 | 333 | if (timeout == 0) { |
michael@0 | 334 | #if defined(AIX) |
michael@0 | 335 | return _MD_POLL(listptr, nfds, timeout); |
michael@0 | 336 | #else |
michael@0 | 337 | return _MD_POLL(filedes, nfds, timeout); |
michael@0 | 338 | #endif |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | if (!_pr_initialized) { |
michael@0 | 342 | _PR_ImplicitInitialization(); |
michael@0 | 343 | } |
michael@0 | 344 | |
michael@0 | 345 | #ifndef _PR_LOCAL_THREADS_ONLY |
michael@0 | 346 | if (_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) { |
michael@0 | 347 | return _MD_POLL(filedes, nfds, timeout); |
michael@0 | 348 | } |
michael@0 | 349 | #endif |
michael@0 | 350 | |
michael@0 | 351 | /* We do not support the pollmsg structures on AIX */ |
michael@0 | 352 | #ifdef AIX |
michael@0 | 353 | PR_ASSERT((nfds & 0xff00) == 0); |
michael@0 | 354 | #endif |
michael@0 | 355 | |
michael@0 | 356 | if (timeout < 0 && timeout != -1) { |
michael@0 | 357 | errno = EINVAL; |
michael@0 | 358 | return -1; |
michael@0 | 359 | } |
michael@0 | 360 | |
michael@0 | 361 | /* Convert timeout from miliseconds to ticks */ |
michael@0 | 362 | if (timeout == -1) { |
michael@0 | 363 | ticks = PR_INTERVAL_NO_TIMEOUT; |
michael@0 | 364 | } else { |
michael@0 | 365 | ticks = PR_MillisecondsToInterval(timeout); |
michael@0 | 366 | } |
michael@0 | 367 | |
michael@0 | 368 | /* Check for no descriptor case (just do a timeout) */ |
michael@0 | 369 | if (nfds == 0) { |
michael@0 | 370 | PR_Sleep(ticks); |
michael@0 | 371 | return 0; |
michael@0 | 372 | } |
michael@0 | 373 | |
michael@0 | 374 | unixpds = (_PRUnixPollDesc *) |
michael@0 | 375 | PR_MALLOC(nfds * sizeof(_PRUnixPollDesc)); |
michael@0 | 376 | if (NULL == unixpds) { |
michael@0 | 377 | errno = EAGAIN; |
michael@0 | 378 | return -1; |
michael@0 | 379 | } |
michael@0 | 380 | |
michael@0 | 381 | pdcnt = 0; |
michael@0 | 382 | epfd = filedes + nfds; |
michael@0 | 383 | unixpd = unixpds; |
michael@0 | 384 | for (pfd = filedes; pfd < epfd; pfd++) { |
michael@0 | 385 | /* |
michael@0 | 386 | * poll() ignores negative fd's. |
michael@0 | 387 | */ |
michael@0 | 388 | if (pfd->fd >= 0) { |
michael@0 | 389 | unixpd->osfd = pfd->fd; |
michael@0 | 390 | #ifdef _PR_USE_POLL |
michael@0 | 391 | unixpd->in_flags = pfd->events; |
michael@0 | 392 | #else |
michael@0 | 393 | /* |
michael@0 | 394 | * Map the poll events to one of the three that can be |
michael@0 | 395 | * represented by the select fd_sets: |
michael@0 | 396 | * POLLIN, POLLRDNORM ===> readable |
michael@0 | 397 | * POLLOUT, POLLWRNORM ===> writable |
michael@0 | 398 | * POLLPRI, POLLRDBAND ===> exception |
michael@0 | 399 | * POLLNORM, POLLWRBAND (and POLLMSG on some platforms) |
michael@0 | 400 | * are ignored. |
michael@0 | 401 | * |
michael@0 | 402 | * The output events POLLERR and POLLHUP are never turned on. |
michael@0 | 403 | * POLLNVAL may be turned on. |
michael@0 | 404 | */ |
michael@0 | 405 | unixpd->in_flags = 0; |
michael@0 | 406 | if (pfd->events & (POLLIN |
michael@0 | 407 | #ifdef POLLRDNORM |
michael@0 | 408 | | POLLRDNORM |
michael@0 | 409 | #endif |
michael@0 | 410 | )) { |
michael@0 | 411 | unixpd->in_flags |= _PR_UNIX_POLL_READ; |
michael@0 | 412 | } |
michael@0 | 413 | if (pfd->events & (POLLOUT |
michael@0 | 414 | #ifdef POLLWRNORM |
michael@0 | 415 | | POLLWRNORM |
michael@0 | 416 | #endif |
michael@0 | 417 | )) { |
michael@0 | 418 | unixpd->in_flags |= _PR_UNIX_POLL_WRITE; |
michael@0 | 419 | } |
michael@0 | 420 | if (pfd->events & (POLLPRI |
michael@0 | 421 | #ifdef POLLRDBAND |
michael@0 | 422 | | POLLRDBAND |
michael@0 | 423 | #endif |
michael@0 | 424 | )) { |
michael@0 | 425 | unixpd->in_flags |= PR_POLL_EXCEPT; |
michael@0 | 426 | } |
michael@0 | 427 | #endif /* _PR_USE_POLL */ |
michael@0 | 428 | unixpd->out_flags = 0; |
michael@0 | 429 | unixpd++; |
michael@0 | 430 | pdcnt++; |
michael@0 | 431 | } |
michael@0 | 432 | } |
michael@0 | 433 | |
michael@0 | 434 | ready = _PR_WaitForMultipleFDs(unixpds, pdcnt, ticks); |
michael@0 | 435 | if (-1 == ready) { |
michael@0 | 436 | if (PR_GetError() == PR_PENDING_INTERRUPT_ERROR) { |
michael@0 | 437 | errno = EINTR; /* XXX we aren't interrupted by a signal, but... */ |
michael@0 | 438 | } else { |
michael@0 | 439 | errno = PR_GetOSError(); |
michael@0 | 440 | } |
michael@0 | 441 | } |
michael@0 | 442 | if (ready <= 0) { |
michael@0 | 443 | goto done; |
michael@0 | 444 | } |
michael@0 | 445 | |
michael@0 | 446 | /* |
michael@0 | 447 | * Copy the out_flags from the _PRUnixPollDesc structures to the |
michael@0 | 448 | * user's pollfd structures and free the allocated memory |
michael@0 | 449 | */ |
michael@0 | 450 | unixpd = unixpds; |
michael@0 | 451 | for (pfd = filedes; pfd < epfd; pfd++) { |
michael@0 | 452 | pfd->revents = 0; |
michael@0 | 453 | if (pfd->fd >= 0) { |
michael@0 | 454 | #ifdef _PR_USE_POLL |
michael@0 | 455 | pfd->revents = unixpd->out_flags; |
michael@0 | 456 | #else |
michael@0 | 457 | if (0 != unixpd->out_flags) { |
michael@0 | 458 | if (unixpd->out_flags & _PR_UNIX_POLL_READ) { |
michael@0 | 459 | if (pfd->events & POLLIN) { |
michael@0 | 460 | pfd->revents |= POLLIN; |
michael@0 | 461 | } |
michael@0 | 462 | #ifdef POLLRDNORM |
michael@0 | 463 | if (pfd->events & POLLRDNORM) { |
michael@0 | 464 | pfd->revents |= POLLRDNORM; |
michael@0 | 465 | } |
michael@0 | 466 | #endif |
michael@0 | 467 | } |
michael@0 | 468 | if (unixpd->out_flags & _PR_UNIX_POLL_WRITE) { |
michael@0 | 469 | if (pfd->events & POLLOUT) { |
michael@0 | 470 | pfd->revents |= POLLOUT; |
michael@0 | 471 | } |
michael@0 | 472 | #ifdef POLLWRNORM |
michael@0 | 473 | if (pfd->events & POLLWRNORM) { |
michael@0 | 474 | pfd->revents |= POLLWRNORM; |
michael@0 | 475 | } |
michael@0 | 476 | #endif |
michael@0 | 477 | } |
michael@0 | 478 | if (unixpd->out_flags & _PR_UNIX_POLL_EXCEPT) { |
michael@0 | 479 | if (pfd->events & POLLPRI) { |
michael@0 | 480 | pfd->revents |= POLLPRI; |
michael@0 | 481 | } |
michael@0 | 482 | #ifdef POLLRDBAND |
michael@0 | 483 | if (pfd->events & POLLRDBAND) { |
michael@0 | 484 | pfd->revents |= POLLRDBAND; |
michael@0 | 485 | } |
michael@0 | 486 | #endif |
michael@0 | 487 | } |
michael@0 | 488 | if (unixpd->out_flags & _PR_UNIX_POLL_ERR) { |
michael@0 | 489 | pfd->revents |= POLLERR; |
michael@0 | 490 | } |
michael@0 | 491 | if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) { |
michael@0 | 492 | pfd->revents |= POLLNVAL; |
michael@0 | 493 | } |
michael@0 | 494 | if (unixpd->out_flags & _PR_UNIX_POLL_HUP) { |
michael@0 | 495 | pfd->revents |= POLLHUP; |
michael@0 | 496 | } |
michael@0 | 497 | } |
michael@0 | 498 | #endif /* _PR_USE_POLL */ |
michael@0 | 499 | unixpd++; |
michael@0 | 500 | } |
michael@0 | 501 | } |
michael@0 | 502 | |
michael@0 | 503 | done: |
michael@0 | 504 | PR_DELETE(unixpds); |
michael@0 | 505 | return ready; |
michael@0 | 506 | } |
michael@0 | 507 | |
michael@0 | 508 | #endif /* !defined(LINUX) */ |
michael@0 | 509 | |
michael@0 | 510 | #endif /* defined(_PR_PTHREADS) || defined(_PR_GLOBAL_THREADS_ONLY) */ |
michael@0 | 511 | |
michael@0 | 512 | /* uxwrap.c */ |
michael@0 | 513 |