X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7d354cd1df16222df5e75ee82ea6bc96e67a222c..99e839da3c9c40a3dac7cf1bb841d6459fcac1b0:/src/unix/gsocket.c?ds=sidebyside diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c index bda9f5f035..dc6c7e5702 100644 --- a/src/unix/gsocket.c +++ b/src/unix/gsocket.c @@ -261,7 +261,10 @@ GSocket *GSocket_new(void) void GSocket_close(GSocket *socket) { _GSocket_Disable_Events(socket); +// gsockosx.c calls CFSocketInvalidate which closes the socket for us +#if !(defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__))) close(socket->m_fd); +#endif socket->m_fd = INVALID_SOCKET; } @@ -480,6 +483,11 @@ GSocketError GSocket_SetServer(GSocket *sck) #endif _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. @@ -792,8 +800,11 @@ int GSocket_Read(GSocket *socket, char *buffer, int size) assert(socket != NULL); + /* When using CFSocket we MUST NOT reenable events until we finish reading */ +#ifndef __DARWIN__ /* Reenable INPUT events */ _GSocket_Enable(socket, GSOCK_INPUT); +#endif if (socket->m_fd == INVALID_SOCKET || socket->m_server) { @@ -819,6 +830,11 @@ int GSocket_Read(GSocket *socket, char *buffer, int size) socket->m_error = GSOCK_IOERR; } +#ifdef __DARWIN__ + /* Reenable INPUT events */ + _GSocket_Enable(socket, GSOCK_INPUT); +#endif + return ret; } @@ -898,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); @@ -907,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 */