X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a3f7fa6267aa782b7288ce1bdfc555da4d2beb77..2d1715aa46b210e69ddf2dd1cd1c7d2f23c4298a:/src/msw/gsocket.c?ds=sidebyside diff --git a/src/msw/gsocket.c b/src/msw/gsocket.c index 450ce2b844..9eb8d69513 100644 --- a/src/msw/gsocket.c +++ b/src/msw/gsocket.c @@ -376,6 +376,11 @@ GSocketError GSocket_SetServer(GSocket *sck) ioctlsocket(sck->m_fd, FIONBIO, (u_long FAR *) &arg); _GSocket_Enable_Events(sck); + /* allow a socket to re-bind if the socket is in the TIME_WAIT + state after being previously closed. + */ + setsockopt(sck->m_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&arg, sizeof(u_long)); + /* Bind to the local address, * retrieve the actual address bound, * and listen up to 5 connections. @@ -759,15 +764,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 +789,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 +801,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; }