diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 3706c62893..6e40e90f91 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -678,6 +678,10 @@ bool wxSocketBase::_Wait(long seconds, else timeout = m_timeout * 1000; +#if !defined(wxUSE_GUI) || !wxUSE_GUI + GSocket_SetTimeout(m_socket, timeout); +#endif + // Wait in an active polling loop. // // NOTE: We duplicate some of the code in OnRequest, but this doesn't diff --git a/src/msw/gsocket.c b/src/msw/gsocket.c index 450ce2b844..b4156f5afe 100644 --- a/src/msw/gsocket.c +++ b/src/msw/gsocket.c @@ -759,15 +759,15 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) fd_set readfds; fd_set writefds; fd_set exceptfds; - static const struct timeval tv = { 0, 0 }; - + assert(socket != NULL); FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); FD_SET(socket->m_fd, &readfds); - FD_SET(socket->m_fd, &writefds); + if (flags & GSOCK_OUTPUT_FLAG) + FD_SET(socket->m_fd, &writefds); FD_SET(socket->m_fd, &exceptfds); /* Check 'sticky' CONNECTION flag first */ @@ -784,7 +784,8 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) } /* Try select now */ - if (select(socket->m_fd + 1, &readfds, &writefds, &exceptfds, &tv) <= 0) + if (select(socket->m_fd + 1, &readfds, &writefds, &exceptfds, + &socket->m_timeout) <= 0) { /* What to do here? */ return (result & flags); @@ -795,7 +796,7 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) { char c; - if (recv(socket->m_fd, &c, 1, MSG_PEEK) > 0) + if (!socket->m_stream || recv(socket->m_fd, &c, 1, MSG_PEEK) > 0) { result |= GSOCK_INPUT_FLAG; } diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c index 9566043c43..c7b0d7cf49 100644 --- a/src/unix/gsocket.c +++ b/src/unix/gsocket.c @@ -914,8 +914,8 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) struct timeval tv; /* Do not use a static struct, Linux can garble it */ - tv.tv_sec = 0; - tv.tv_usec = 0; + tv.tv_sec = socket->m_timeout / 1000; + tv.tv_usec = (socket->m_timeout % 1000) / 1000; assert(socket != NULL); @@ -923,7 +923,8 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) FD_ZERO(&writefds); FD_ZERO(&exceptfds); FD_SET(socket->m_fd, &readfds); - FD_SET(socket->m_fd, &writefds); + if (flags & GSOCK_OUTPUT_FLAG) + FD_SET(socket->m_fd, &writefds); FD_SET(socket->m_fd, &exceptfds); /* Check 'sticky' CONNECTION flag first */