* Wait until a file descriptor from the given set becomes readable. * * Returns the number of ready descriptors, or -1 on failure (including * getting a cancel request). */
| 79 | * getting a cancel request). |
| 80 | */ |
| 81 | static int |
| 82 | select_loop(int maxFd, fd_set *workerset) |
| 83 | { |
| 84 | int i; |
| 85 | fd_set saveSet = *workerset; |
| 86 | |
| 87 | if (CancelRequested) |
| 88 | return -1; |
| 89 | |
| 90 | for (;;) |
| 91 | { |
| 92 | /* |
| 93 | * On Windows, we need to check once in a while for cancel requests; |
| 94 | * on other platforms we rely on select() returning when interrupted. |
| 95 | */ |
| 96 | struct timeval *tvp; |
| 97 | #ifdef WIN32 |
| 98 | struct timeval tv = {0, 1000000}; |
| 99 | |
| 100 | tvp = &tv; |
| 101 | #else |
| 102 | tvp = NULL; |
| 103 | #endif |
| 104 | |
| 105 | *workerset = saveSet; |
| 106 | i = select(maxFd + 1, workerset, NULL, NULL, tvp); |
| 107 | |
| 108 | #ifdef WIN32 |
| 109 | if (i == SOCKET_ERROR) |
| 110 | { |
| 111 | i = -1; |
| 112 | |
| 113 | if (WSAGetLastError() == WSAEINTR) |
| 114 | errno = EINTR; |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | if (i < 0 && errno == EINTR) |
| 119 | continue; /* ignore this */ |
| 120 | if (i < 0 || CancelRequested) |
| 121 | return -1; /* but not this */ |
| 122 | if (i == 0) |
| 123 | continue; /* timeout (Win32 only) */ |
| 124 | break; |
| 125 | } |
| 126 | |
| 127 | return i; |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Return the offset of a suitable idle slot, or -1 if none are available. If |