File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33#include "hdef.h"
44
5+ #ifdef OS_UNIX
6+ #include <poll.h>
7+ #endif
8+
59#ifdef OS_WIN
610#include "hatomic.h"
711static hatomic_flag_t s_wsa_initialized = HATOMIC_FLAG_INIT ;
@@ -260,6 +264,20 @@ static int ListenFD(int sockfd) {
260264static int ConnectFDTimeout (int connfd , int ms ) {
261265 int err = 0 ;
262266 socklen_t optlen = sizeof (err );
267+
268+ #ifdef OS_UNIX
269+ // Use poll() to avoid FD_SETSIZE limit (fd >= 1024 crashes with select)
270+ struct pollfd pfd ;
271+ pfd .fd = connfd ;
272+ pfd .events = POLLOUT ;
273+ pfd .revents = 0 ;
274+ int ret = poll (& pfd , 1 , ms );
275+ if (ret < 0 ) {
276+ perror ("poll" );
277+ goto error ;
278+ }
279+ #else
280+ // Windows: select() is safe (fd_set uses different implementation)
263281 struct timeval tv = { ms / 1000 , (ms % 1000 ) * 1000 };
264282 fd_set writefds ;
265283 FD_ZERO (& writefds );
@@ -269,6 +287,7 @@ static int ConnectFDTimeout(int connfd, int ms) {
269287 perror ("select" );
270288 goto error ;
271289 }
290+ #endif
272291 if (ret == 0 ) {
273292 errno = ETIMEDOUT ;
274293 goto error ;
You can’t perform that action at this time.
0 commit comments