X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e8b7a986a6e8257dbcf2c04183ec2924e7906fd4..f69e200970580080565c8aadc10893c29e46abeb:/src/unix/gsocket.c diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c index 396a93641d..3f1c19c862 100644 --- a/src/unix/gsocket.c +++ b/src/unix/gsocket.c @@ -4,7 +4,7 @@ * Authors: Guilhem Lavaux, * Guillermo Rodriguez Garcia (maintainer) * Purpose: GSocket main Unix and OS/2 file - * Licence: The wxWindows licence + * Licence: The wxWidgets licence * CVSID: $Id$ * ------------------------------------------------------------------------- */ @@ -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; } @@ -269,20 +272,12 @@ void GSocket_destroy(GSocket *socket) { assert(socket != NULL); - /* When using CFSocket we MUST invalidate before closing the fd */ -#ifdef __DARWIN__ - /* Per-socket GUI-specific cleanup */ - _GSocket_GUI_Destroy_Socket(socket); -#endif - /* Check that the socket is really shutdowned */ if (socket->m_fd != INVALID_SOCKET) GSocket_Shutdown(socket); -#ifndef __DARWIN__ /* Per-socket GUI-specific cleanup */ _GSocket_GUI_Destroy_Socket(socket); -#endif /* Destroy private addresses */ if (socket->m_local) @@ -805,27 +800,26 @@ 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) { socket->m_error = GSOCK_INVSOCK; return -1; } + /* Disable events during query of socket status */ + _GSocket_Disable(socket, GSOCK_INPUT); + /* If the socket is blocking, wait for data (with a timeout) */ if (_GSocket_Input_Timeout(socket) == GSOCK_TIMEDOUT) - return -1; - - /* Read the data */ - if (socket->m_stream) - ret = _GSocket_Recv_Stream(socket, buffer, size); - else - ret = _GSocket_Recv_Dgram(socket, buffer, size); + /* We no longer return here immediately, otherwise socket events would not be re-enabled! */ + ret = -1; + else { + /* Read the data */ + if (socket->m_stream) + ret = _GSocket_Recv_Stream(socket, buffer, size); + else + ret = _GSocket_Recv_Dgram(socket, buffer, size); + } if (ret == -1) { @@ -835,11 +829,9 @@ int GSocket_Read(GSocket *socket, char *buffer, int size) socket->m_error = GSOCK_IOERR; } -#ifdef __DARWIN__ - /* Reenable INPUT events */ + /* Enable events again now that we are done processing */ _GSocket_Enable(socket, GSOCK_INPUT); -#endif - + return ret; } @@ -918,17 +910,17 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) fd_set exceptfds; struct timeval tv; + assert(socket != NULL); + /* Do not use a static struct, Linux can garble it */ tv.tv_sec = socket->m_timeout / 1000; tv.tv_usec = (socket->m_timeout % 1000) / 1000; - assert(socket != NULL); - FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); FD_SET(socket->m_fd, &readfds); - if (flags & GSOCK_OUTPUT_FLAG) + if (flags & GSOCK_OUTPUT_FLAG || flags & GSOCK_CONNECTION_FLAG) FD_SET(socket->m_fd, &writefds); FD_SET(socket->m_fd, &exceptfds); @@ -1621,8 +1613,10 @@ GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname) { #else /* Use gethostbyname by default */ - int val = 1; //VA doesn't like constants in conditional expressions at all +#ifndef __WXMAC__ + int val = 1; /* VA doesn't like constants in conditional expressions */ if (val) +#endif { #endif struct in_addr *array_addr; @@ -1656,7 +1650,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; } @@ -1747,7 +1741,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)