diff -c ../psqlodbc/socket.c ./socket.c *** ../psqlodbc/socket.c 2010-01-11 09:56:18.605000000 +0900 --- ./socket.c 2010-05-19 17:03:10.874000000 +0900 *************** *** 350,357 **** --- 350,362 ---- if (connect(self->socket, (struct sockaddr *) &(self->sadr_area), self->sadr_len) < 0) { int ret, optval; + int wait_sec = 0; + #ifdef HAVE_POLL + struct pollfd fds; + #else fd_set fds, except_fds; struct timeval tm; + #endif /* HAVE_POLL */ socklen_t optlen = sizeof(optval); time_t t_now, t_finish = 0; BOOL tm_exp = FALSE; *************** *** 377,391 **** { t_now = time(NULL); t_finish = t_now + timeout; ! tm.tv_sec = timeout; ! tm.tv_usec = 0; } do { FD_ZERO(&fds); FD_ZERO(&except_fds); FD_SET(self->socket, &fds); FD_SET(self->socket, &except_fds); ret = select((int) self->socket + 1, NULL, &fds, &except_fds, timeout > 0 ? &tm : NULL); gerrno = SOCK_ERRNO; if (0 < ret) break; --- 382,404 ---- { t_now = time(NULL); t_finish = t_now + timeout; ! wait_sec = timeout; } do { + #ifdef HAVE_POLL + fds.fd = self->socket; + fds.events = POLLOUT; + fds.revents = 0; + ret = poll(&fds, 1, timeout > 0 ? wait_sec * 1000 : -1); + #else + tm.tv_sec = wait_sec; + tm.tv_usec = 0; FD_ZERO(&fds); FD_ZERO(&except_fds); FD_SET(self->socket, &fds); FD_SET(self->socket, &except_fds); ret = select((int) self->socket + 1, NULL, &fds, &except_fds, timeout > 0 ? &tm : NULL); + #endif /* HAVE_POLL */ gerrno = SOCK_ERRNO; if (0 < ret) break; *************** *** 398,407 **** if (t_now = time(NULL), t_now >= t_finish) tm_exp = TRUE; else ! { ! tm.tv_sec = (long) (t_finish - t_now); ! tm.tv_usec = 0; ! } } } while (!tm_exp); if (tm_exp) --- 411,417 ---- if (t_now = time(NULL), t_now >= t_finish) tm_exp = TRUE; else ! wait_sec = t_finish - t_now; } } while (!tm_exp); if (tm_exp) *************** *** 475,482 **** --- 485,496 ---- static int SOCK_wait_for_ready(SocketClass *sock, BOOL output, int retry_count) { int ret, gerrno; + #ifdef HAVE_POLL + struct pollfd fds; + #else fd_set fds, except_fds; struct timeval tm; + #endif /* HAVE_POLL */ BOOL no_timeout = TRUE; if (0 == retry_count) *************** *** 488,493 **** --- 502,513 ---- no_timeout = TRUE; #endif /* USE_SSL */ do { + #ifdef HAVE_POLL + fds.fd = sock->socket; + fds.events = output ? POLLOUT : POLLIN; + fds.revents = 0; + ret = poll(&fds, 1, no_timeout ? -1 : retry_count * 1000); + #else FD_ZERO(&fds); FD_ZERO(&except_fds); FD_SET(sock->socket, &fds); *************** *** 498,503 **** --- 518,524 ---- tm.tv_usec = 0; } ret = select((int) sock->socket + 1, output ? NULL : &fds, output ? &fds : NULL, &except_fds, no_timeout ? NULL : &tm); + #endif /* HAVE_POLL */ gerrno = SOCK_ERRNO; } while (ret < 0 && EINTR == gerrno); if (retry_count < 0) diff -c ../psqlodbc/socket.h ./socket.h *** ../psqlodbc/socket.h 2010-01-11 09:56:31.371000000 +0900 --- ./socket.h 2010-05-19 13:15:50.157000000 +0900 *************** *** 21,26 **** --- 21,29 ---- #ifndef WIN32 #define WSAAPI + #ifdef HAVE_POLL + #include + #endif /* HAVE_POLL_H */ #include #include #include