]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/core/sockosx.cpp
Update version to 2.9.4 in version.bkl too and rebake everything.
[wxWidgets.git] / src / osx / core / sockosx.cpp
index ce4926dafa9d8ec0da91b330465e1a6f83aafc17..847b8ac12d63314a221494de291dd46d72a872ca 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        osx/core/gsockosx.cpp
+// Name:        src/osx/core/gsockosx.cpp
 // Purpose:     wxSocketImpl implementation for OS X
 // Authors:     Brian Victor, Vadim Zeitlin
 // Created:     February 2002
 // Purpose:     wxSocketImpl implementation for OS X
 // Authors:     Brian Victor, Vadim Zeitlin
 // Created:     February 2002
@@ -16,6 +16,9 @@
 #include "wx/private/socket.h"
 #include "wx/unix/private/sockunix.h"
 #include "wx/apptrait.h"
 #include "wx/private/socket.h"
 #include "wx/unix/private/sockunix.h"
 #include "wx/apptrait.h"
+#include "wx/link.h"
+
+#include "wx/osx/core/cfstring.h"           // for wxMacWakeUp() only
 
 #include <CoreFoundation/CoreFoundation.h>
 
 
 #include <CoreFoundation/CoreFoundation.h>
 
@@ -75,7 +78,10 @@ private:
         CFSocketInvalidate(m_socket);
 
         CFRelease(m_source);
         CFSocketInvalidate(m_socket);
 
         CFRelease(m_source);
+        m_source = NULL;
+
         CFRelease(m_socket);
         CFRelease(m_socket);
+        m_socket = NULL;
     }
 
     // initialize the data associated with the given socket
     }
 
     // initialize the data associated with the given socket
@@ -110,6 +116,8 @@ private:
         if ( !m_source )
         {
             CFRelease(m_socket);
         if ( !m_source )
         {
             CFRelease(m_socket);
+            m_socket = NULL;
+
             return false;
         }
 
             return false;
         }
 
@@ -133,7 +141,7 @@ private:
                 // KH: If data is non-NULL, the connect failed, do not call Detected_Write,
                 // which will only end up creating a spurious connect event because the
                 // call to getsocketopt SO_ERROR inexplicably returns no error.
                 // KH: If data is non-NULL, the connect failed, do not call Detected_Write,
                 // which will only end up creating a spurious connect event because the
                 // call to getsocketopt SO_ERROR inexplicably returns no error.
-                // The change in behavior cannot be traced to any particular commit or
+                // The change in behaviour cannot be traced to any particular commit or
                 // timeframe so I'm not sure what to think, but after so many hours,
                 // this seems to address the issue and it's time to move on.
                 if (data == NULL)
                 // timeframe so I'm not sure what to think, but after so many hours,
                 // this seems to address the issue and it's time to move on.
                 if (data == NULL)
@@ -151,12 +159,19 @@ private:
             default:
                 wxFAIL_MSG( "unexpected socket callback" );
         }
             default:
                 wxFAIL_MSG( "unexpected socket callback" );
         }
+
+        // receiving a socket event does _not_ make ReceiveNextEvent() (or the
+        // equivalent NSApp:nextEventMatchingMask:untilDate:inMode:dequeue)
+        // return control, i.e. apparently it doesn't count as a real event, so
+        // we need to generate a wake up to return control to the code waiting
+        // for something to happen and process this socket event
+        wxMacWakeUp();
     }
 
     CFSocketRef m_socket;
     CFRunLoopSourceRef m_source;
 
     }
 
     CFSocketRef m_socket;
     CFRunLoopSourceRef m_source;
 
-    DECLARE_NO_COPY_CLASS(wxSocketImplMac)
+    wxDECLARE_NO_COPY_CLASS(wxSocketImplMac);
 };
 
 } // anonymous namespace
 };
 
 } // anonymous namespace
@@ -222,15 +237,14 @@ int wxSocketManagerMac::GetCFCallback(wxSocketImpl *socket, wxSocketNotify event
             return socket->IsServer() ? kCFSocketReadCallBack
                                       : kCFSocketConnectCallBack;
 
             return socket->IsServer() ? kCFSocketReadCallBack
                                       : kCFSocketConnectCallBack;
 
-        case wxSOCKET_LOST:
         case wxSOCKET_INPUT:
             return kCFSocketReadCallBack;
 
         case wxSOCKET_OUTPUT:
             return kCFSocketWriteCallBack;
 
         case wxSOCKET_INPUT:
             return kCFSocketReadCallBack;
 
         case wxSOCKET_OUTPUT:
             return kCFSocketWriteCallBack;
 
-        case wxSOCKET_MAX_EVENT:
-            wxFAIL_MSG( "invalid wxSocketNotify" );
+        case wxSOCKET_LOST:
+            wxFAIL_MSG( "unexpected wxSocketNotify" );
             return 0;
 
         default:
             return 0;
 
         default:
@@ -255,17 +269,24 @@ void wxSocketManagerMac::Uninstall_Callback(wxSocketImpl *socket_,
     CFSocketDisableCallBacks(socket->GetSocket(), GetCFCallback(socket, event));
 }
 
     CFSocketDisableCallBacks(socket->GetSocket(), GetCFCallback(socket, event));
 }
 
-// set the wxBase variable to point to our wxSocketManager implementation
+// set the wxBase variable to point to CF wxSocketManager implementation so
+// that the GUI code in utilsexc_cf.cpp could return it from its traits method
 //
 //
-// see comments in wx/apptrait.h for the explanation of why do we do it
-// like this
-static struct ManagerSetter
+// this is very roundabout but necessary to allow us to have different
+// behaviours in console and GUI applications while avoiding dependencies of
+// GUI library on the network one
+extern WXDLLIMPEXP_BASE wxSocketManager *wxOSXSocketManagerCF;
+
+static struct OSXManagerSetter
 {
 {
-    ManagerSetter()
+    OSXManagerSetter()
     {
         static wxSocketManagerMac s_manager;
     {
         static wxSocketManagerMac s_manager;
-        wxAppTraits::SetDefaultSocketManager(&s_manager);
+        wxOSXSocketManagerCF = &s_manager;
     }
     }
-} gs_managerSetter;
+} gs_OSXManagerSetter;
+
+// see the relative linker macro in socket.cpp
+wxFORCE_LINK_THIS_MODULE(osxsocket)
 
 #endif // wxUSE_SOCKETS
 
 #endif // wxUSE_SOCKETS