From 1c7edd1d3c1393145db803b9d616bb2a069180c8 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Wed, 24 Dec 2003 02:49:07 +0000 Subject: [PATCH] In GSocket_Destroy reorder GUI_Destroy and Shutdown when compiling for Darwin. This is necessary to comply with the Apple documentation for CFSocket which states quite explcitly that the CFSocket must be invalidated prior to close. Likewise in GSocket_Read don't enable input events until we have finished reading the data. This is necessary because an input event will be immediately generated but all the data will have been read by the current callback which leads to the GSocket code thinking the connection has been lost and when wxYield recursion is involved will lead to crashes or an assert. Because we are doing a compile time test only for Darwin this will also affect wxGTK running on Darwin. It appears possible for the new order to work on all platforms but more testing would be required. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24997 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/unix/gsocket.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c index bda9f5f035..9566043c43 100644 --- a/src/unix/gsocket.c +++ b/src/unix/gsocket.c @@ -269,12 +269,20 @@ 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) @@ -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; } -- 2.45.2