From fda20787fca129376f73d6dd61b53a199df41ddf Mon Sep 17 00:00:00 2001 From: David Elliott Date: Wed, 14 Jan 2004 02:17:16 +0000 Subject: [PATCH] * _GSocket_Enable_Events() and _GSocket_Disable_Events() now call CFRunLoopAddSource() and CFRunLoopRemoveSource() respectively. They no longer call CFSocketEnableCallbacks or CFSocketDisableCallbacks. * In _GSocket_Get_Mac_Socket() no longer disable callbacks and also do not add the runloop source which combined with the above change has the same effect as before. * In _GSocket_GUI_Destroy_Socket() do not remove the runloop source because _GSocket_Disable_Events() should have and even if it didn't Mac OS X will clean it up in CFSocketInvalidate() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25166 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/gsockosx.c | 13 +++---------- src/mac/gsockosx.c | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/mac/carbon/gsockosx.c b/src/mac/carbon/gsockosx.c index fd9703227c..ba191edbde 100644 --- a/src/mac/carbon/gsockosx.c +++ b/src/mac/carbon/gsockosx.c @@ -65,8 +65,6 @@ struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket) CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd, ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont); - /* Disable the callbacks until we are asked by GSocket to enable them. */ - CFSocketDisableCallBacks(cf, ALL_CALLBACK_TYPES); CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, cf, 0); assert(source); /* Turn off kCFSocketCloseOnInvalidate (NOTE: > 10.2 only!) */ @@ -77,7 +75,6 @@ struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket) avoid having to set any special flags at all. */ CFSocketSetSocketFlags(cf, kCFSocketAutomaticallyReenableReadCallBack | kCFSocketAutomaticallyReenableWriteCallBack); socket->m_gui_dependent = (char*)data; - CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode); /* Keep the source and the socket around. */ data->source = source; @@ -113,8 +110,6 @@ void _GSocket_GUI_Destroy_Socket(GSocket *socket) struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent); if (data) { - /* CFSocketInvalidate does this anyway, so perhaps get rid of this: */ - CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes); CFSocketInvalidate(data->socket); CFRelease(data->socket); free(data); @@ -175,20 +170,18 @@ void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event) void _GSocket_Enable_Events(GSocket *socket) { - CFOptionFlags callBackTypes = kCFSocketReadCallBack | kCFSocketWriteCallBack; struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket); if (!data) return; - if(!socket->m_server) - callBackTypes |= kCFSocketConnectCallBack; - CFSocketEnableCallBacks(data->socket, callBackTypes); + CFRunLoopAddSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopDefaultMode); } void _GSocket_Disable_Events(GSocket *socket) { struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket); if (!data) return; - CFSocketDisableCallBacks(data->socket, ALL_CALLBACK_TYPES); + + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes); } #endif // wxUSE_SOCKETS diff --git a/src/mac/gsockosx.c b/src/mac/gsockosx.c index fd9703227c..ba191edbde 100644 --- a/src/mac/gsockosx.c +++ b/src/mac/gsockosx.c @@ -65,8 +65,6 @@ struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket) CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd, ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont); - /* Disable the callbacks until we are asked by GSocket to enable them. */ - CFSocketDisableCallBacks(cf, ALL_CALLBACK_TYPES); CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, cf, 0); assert(source); /* Turn off kCFSocketCloseOnInvalidate (NOTE: > 10.2 only!) */ @@ -77,7 +75,6 @@ struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket) avoid having to set any special flags at all. */ CFSocketSetSocketFlags(cf, kCFSocketAutomaticallyReenableReadCallBack | kCFSocketAutomaticallyReenableWriteCallBack); socket->m_gui_dependent = (char*)data; - CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode); /* Keep the source and the socket around. */ data->source = source; @@ -113,8 +110,6 @@ void _GSocket_GUI_Destroy_Socket(GSocket *socket) struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent); if (data) { - /* CFSocketInvalidate does this anyway, so perhaps get rid of this: */ - CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes); CFSocketInvalidate(data->socket); CFRelease(data->socket); free(data); @@ -175,20 +170,18 @@ void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event) void _GSocket_Enable_Events(GSocket *socket) { - CFOptionFlags callBackTypes = kCFSocketReadCallBack | kCFSocketWriteCallBack; struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket); if (!data) return; - if(!socket->m_server) - callBackTypes |= kCFSocketConnectCallBack; - CFSocketEnableCallBacks(data->socket, callBackTypes); + CFRunLoopAddSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopDefaultMode); } void _GSocket_Disable_Events(GSocket *socket) { struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket); if (!data) return; - CFSocketDisableCallBacks(data->socket, ALL_CALLBACK_TYPES); + + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes); } #endif // wxUSE_SOCKETS -- 2.47.2