diff options
| author | Kartik Naik <kartik@bugqore.com> | 2026-07-15 15:48:00 +0530 |
|---|---|---|
| committer | Kartik Naik <kartik@bugqore.com> | 2026-07-15 15:48:00 +0530 |
| commit | b901cbc4d84bd4eb5dbb27dabc329ba03457274a (patch) | |
| tree | 76e6cc4fd16b8e8e67b3755065a8cb5140a99cae /apps | |
| parent | 991c2d765dc003e43b8814dc191b9e81140df4cd (diff) | |
| download | portable-b901cbc4d84bd4eb5dbb27dabc329ba03457274a.tar.gz portable-b901cbc4d84bd4eb5dbb27dabc329ba03457274a.tar.bz2 portable-b901cbc4d84bd4eb5dbb27dabc329ba03457274a.zip | |
poll_win: restore fd_sets before each select() retry
select() strips not-ready descriptors from the fd_sets, so a timed-out
pass leaves them empty and the next pass calls select() with three empty
sets, which Windows rejects with WSAEINVAL. Keep a pristine copy and
restore it before each retry so an idle socket waits out the timeout.
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/openssl/compat/poll_win.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/apps/openssl/compat/poll_win.c b/apps/openssl/compat/poll_win.c index c518962..0d15522 100644 --- a/apps/openssl/compat/poll_win.c +++ b/apps/openssl/compat/poll_win.c | |||
| @@ -166,6 +166,7 @@ poll(struct pollfd *pfds, nfds_t nfds, int timeout_ms) | |||
| 166 | * select machinery | 166 | * select machinery |
| 167 | */ | 167 | */ |
| 168 | fd_set rfds, wfds, efds; | 168 | fd_set rfds, wfds, efds; |
| 169 | fd_set rfds_in, wfds_in, efds_in; | ||
| 169 | int rc; | 170 | int rc; |
| 170 | int num_sockets; | 171 | int num_sockets; |
| 171 | 172 | ||
| @@ -250,12 +251,27 @@ poll(struct pollfd *pfds, nfds_t nfds, int timeout_ms) | |||
| 250 | 251 | ||
| 251 | looptime_ms = (timeout_ms > 100 || timeout_ms == -1) ? 100 : timeout_ms; | 252 | looptime_ms = (timeout_ms > 100 || timeout_ms == -1) ? 100 : timeout_ms; |
| 252 | 253 | ||
| 254 | /* | ||
| 255 | * select() clears every descriptor that is not ready from the | ||
| 256 | * fd_sets, so a pass that times out leaves them empty. Keep a | ||
| 257 | * pristine copy and restore it before each select(), otherwise the | ||
| 258 | * next pass hands select() three empty sets and Windows fails it with | ||
| 259 | * WSAEINVAL instead of waiting out the remaining timeout. | ||
| 260 | */ | ||
| 261 | rfds_in = rfds; | ||
| 262 | wfds_in = wfds; | ||
| 263 | efds_in = efds; | ||
| 264 | |||
| 253 | do { | 265 | do { |
| 254 | TIMEVAL tv; | 266 | TIMEVAL tv; |
| 255 | tv.tv_sec = 0; | 267 | tv.tv_sec = 0; |
| 256 | tv.tv_usec = looptime_ms * 1000; | 268 | tv.tv_usec = looptime_ms * 1000; |
| 257 | int handle_signaled = 0; | 269 | int handle_signaled = 0; |
| 258 | 270 | ||
| 271 | rfds = rfds_in; | ||
| 272 | wfds = wfds_in; | ||
| 273 | efds = efds_in; | ||
| 274 | |||
| 259 | /* | 275 | /* |
| 260 | * Check if any file handles have signaled | 276 | * Check if any file handles have signaled |
| 261 | */ | 277 | */ |
