]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/gsockosx.c
replaced my recent GSocket_SetReuseAddr() addition with GSocket_SetReusable() from...
[wxWidgets.git] / src / mac / carbon / gsockosx.c
index ba191edbdeb823fc38f8cca6a0615183e217b378..bb3756c7fd4c52dd783f58bc5849e6581f544416 100644 (file)
@@ -53,6 +53,9 @@ struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket)
   /* If socket is already created, returns a pointer to the data */
   /* Otherwise, creates socket and returns the pointer */
   CFSocketContext cont;
+  CFSocketRef cf;
+  CFRunLoopSourceRef source;
+
   struct MacGSocketData* data = (struct MacGSocketData*)socket->m_gui_dependent;
 
   if (data && data->source) return data;
@@ -63,17 +66,10 @@ struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket)
   cont.release = NULL; cont.copyDescription = NULL;
   cont.info = socket;
 
-  CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd,
+  cf = CFSocketCreateWithNative(NULL, socket->m_fd,
                        ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont);
-  CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, cf, 0);
+  source = CFSocketCreateRunLoopSource(NULL, cf, 0);
   assert(source);
-  /* Turn off kCFSocketCloseOnInvalidate  (NOTE: > 10.2 only!) */
-  /* Another default flag that we don't turn on here is for DataCallBack and
-     also AcceptCallback (which overlap in bits) which we don't use anyway */
-  /* FIXME: For < 10.2 compatibility fix GSocket to call a platform-dependent
-     function to close the socket so that we can just call invalidate and
-     avoid having to set any special flags at all. */
-  CFSocketSetSocketFlags(cf, kCFSocketAutomaticallyReenableReadCallBack | kCFSocketAutomaticallyReenableWriteCallBack);
   socket->m_gui_dependent = (char*)data;
 
   /* Keep the source and the socket around. */
@@ -110,7 +106,6 @@ void _GSocket_GUI_Destroy_Socket(GSocket *socket)
     struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
     if (data)
     {
-        CFSocketInvalidate(data->socket);
         CFRelease(data->socket);
         free(data);
     }
@@ -181,7 +176,9 @@ void _GSocket_Disable_Events(GSocket *socket)
     struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
     if (!data) return;
 
+    /* CFSocketInvalidate does CFRunLoopRemoveSource anyway */
     CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes);
+    CFSocketInvalidate(data->socket);
 }
 
 #endif // wxUSE_SOCKETS