X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4368b1a640fde01f92a675f2e159a8a71d5c0a66..04633c190f5a6eafe607a5712647aaa131522b1f:/src/msw/gsocket.c diff --git a/src/msw/gsocket.c b/src/msw/gsocket.c index 2ca87dd305..86cfc7b913 100644 --- a/src/msw/gsocket.c +++ b/src/msw/gsocket.c @@ -25,13 +25,22 @@ * warning: unreferenced formal parameter. */ # pragma warning(disable:4100) + +#ifdef __WXWINCE__ + /* + "unreferenced inline function has been removed": this is not + suppressed by push above as it is given at the end of the + compilation unit + */ +# pragma warning(disable:4514) +#endif /* __WXWINCE__ */ #endif /* _MSC_VER */ #include #ifndef __GSOCKET_STANDALONE__ -# include "wx/defs.h" -# include "wx/setup.h" +# include "wx/platform.h" +# include "wx/setup.h" #endif #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) @@ -376,6 +385,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 +773,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 || flags & GSOCK_CONNECTION_FLAG) + FD_SET(socket->m_fd, &writefds); FD_SET(socket->m_fd, &exceptfds); /* Check 'sticky' CONNECTION flag first */ @@ -784,7 +798,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 +810,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; } @@ -1346,7 +1361,7 @@ GSocketError GAddress_INET_SetHostAddress(GAddress *address, CHECK_ADDRESS(address, INET); addr = &(((struct sockaddr_in *)address->m_addr)->sin_addr); - addr->s_addr = hostaddr; + addr->s_addr = htonl(hostaddr);; return GSOCK_NOERROR; } @@ -1435,7 +1450,7 @@ unsigned long GAddress_INET_GetHostAddress(GAddress *address) addr = (struct sockaddr_in *)address->m_addr; - return addr->sin_addr.s_addr; + return ntohl(addr->sin_addr.s_addr); } unsigned short GAddress_INET_GetPort(GAddress *address) @@ -1464,6 +1479,10 @@ GSocketError _GAddress_Init_UNIX(GAddress *address) GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path) { +#if defined(__BORLANDC__) + /* prevents unused variable message in Borland */ + (void)path; +#endif assert (address != NULL); address->m_error = GSOCK_INVADDR; return GSOCK_INVADDR; @@ -1471,6 +1490,11 @@ GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path) GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf) { +#if defined(__BORLANDC__) + /* prevents unused variable message in Borland */ + (void)path; + (void)sbuf; +#endif assert (address != NULL); address->m_error = GSOCK_INVADDR; return GSOCK_INVADDR;