From: David Elliott Date: Wed, 17 Oct 2007 21:52:02 +0000 (+0000) Subject: Apply modified patch 1785299 to trunk and 2.8. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/dd6c8be6e9a41eb90945ac5556840cd297ba8d7f Apply modified patch 1785299 to trunk and 2.8. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49205 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/mac/corefoundation/gsockosx.cpp b/src/mac/corefoundation/gsockosx.cpp index ac4da2300e..a433d71c0c 100644 --- a/src/mac/corefoundation/gsockosx.cpp +++ b/src/mac/corefoundation/gsockosx.cpp @@ -206,6 +206,9 @@ void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket) /* CFSocketInvalidate does CFRunLoopRemoveSource anyway */ CFRunLoopRemoveSource(s_mainRunLoop, data->source, kCFRunLoopCommonModes); CFSocketInvalidate(data->socket); + + // CFSocketInvalidate has closed the socket so we want to make sure GSocket knows this + socket->m_fd = -1 /*INVALID_SOCKET*/; } #endif // wxUSE_SOCKETS diff --git a/src/unix/gsocket.cpp b/src/unix/gsocket.cpp index 0c8f5f9a40..bd71d70be5 100644 --- a/src/unix/gsocket.cpp +++ b/src/unix/gsocket.cpp @@ -550,10 +550,17 @@ GSocket::GSocket() void GSocket::Close() { gs_gui_functions->Disable_Events(this); - /* gsockosx.c calls CFSocketInvalidate which closes the socket for us */ -#if !(defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__))) - close(m_fd); -#endif + + /* When running on OS X, the gsockosx implementation of GSocketGUIFunctionsTable + will close the socket during Disable_Events. However, it will only do this + if it is being used. That is, it won't do it in a console program. To + ensure we get the right behavior, we have gsockosx set m_fd = INVALID_SOCKET + if it has closed the socket which indicates to us (at runtime, instead of + at compile time as this had been before) that the socket has already + been closed. + */ + if(m_fd != INVALID_SOCKET) + close(m_fd); m_fd = INVALID_SOCKET; }