* _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
This commit is contained in:
@@ -65,8 +65,6 @@ struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket)
|
|||||||
|
|
||||||
CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd,
|
CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd,
|
||||||
ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont);
|
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);
|
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, cf, 0);
|
||||||
assert(source);
|
assert(source);
|
||||||
/* Turn off kCFSocketCloseOnInvalidate (NOTE: > 10.2 only!) */
|
/* 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. */
|
avoid having to set any special flags at all. */
|
||||||
CFSocketSetSocketFlags(cf, kCFSocketAutomaticallyReenableReadCallBack | kCFSocketAutomaticallyReenableWriteCallBack);
|
CFSocketSetSocketFlags(cf, kCFSocketAutomaticallyReenableReadCallBack | kCFSocketAutomaticallyReenableWriteCallBack);
|
||||||
socket->m_gui_dependent = (char*)data;
|
socket->m_gui_dependent = (char*)data;
|
||||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
|
|
||||||
|
|
||||||
/* Keep the source and the socket around. */
|
/* Keep the source and the socket around. */
|
||||||
data->source = source;
|
data->source = source;
|
||||||
@@ -113,8 +110,6 @@ void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
|||||||
struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
|
struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
/* CFSocketInvalidate does this anyway, so perhaps get rid of this: */
|
|
||||||
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes);
|
|
||||||
CFSocketInvalidate(data->socket);
|
CFSocketInvalidate(data->socket);
|
||||||
CFRelease(data->socket);
|
CFRelease(data->socket);
|
||||||
free(data);
|
free(data);
|
||||||
@@ -175,20 +170,18 @@ void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
|
|||||||
|
|
||||||
void _GSocket_Enable_Events(GSocket *socket)
|
void _GSocket_Enable_Events(GSocket *socket)
|
||||||
{
|
{
|
||||||
CFOptionFlags callBackTypes = kCFSocketReadCallBack | kCFSocketWriteCallBack;
|
|
||||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
if(!socket->m_server)
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopDefaultMode);
|
||||||
callBackTypes |= kCFSocketConnectCallBack;
|
|
||||||
CFSocketEnableCallBacks(data->socket, callBackTypes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _GSocket_Disable_Events(GSocket *socket)
|
void _GSocket_Disable_Events(GSocket *socket)
|
||||||
{
|
{
|
||||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
CFSocketDisableCallBacks(data->socket, ALL_CALLBACK_TYPES);
|
|
||||||
|
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_SOCKETS
|
#endif // wxUSE_SOCKETS
|
||||||
|
@@ -65,8 +65,6 @@ struct MacGSocketData* _GSocket_Get_Mac_Socket(GSocket *socket)
|
|||||||
|
|
||||||
CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd,
|
CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd,
|
||||||
ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont);
|
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);
|
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, cf, 0);
|
||||||
assert(source);
|
assert(source);
|
||||||
/* Turn off kCFSocketCloseOnInvalidate (NOTE: > 10.2 only!) */
|
/* 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. */
|
avoid having to set any special flags at all. */
|
||||||
CFSocketSetSocketFlags(cf, kCFSocketAutomaticallyReenableReadCallBack | kCFSocketAutomaticallyReenableWriteCallBack);
|
CFSocketSetSocketFlags(cf, kCFSocketAutomaticallyReenableReadCallBack | kCFSocketAutomaticallyReenableWriteCallBack);
|
||||||
socket->m_gui_dependent = (char*)data;
|
socket->m_gui_dependent = (char*)data;
|
||||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
|
|
||||||
|
|
||||||
/* Keep the source and the socket around. */
|
/* Keep the source and the socket around. */
|
||||||
data->source = source;
|
data->source = source;
|
||||||
@@ -113,8 +110,6 @@ void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
|||||||
struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
|
struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
/* CFSocketInvalidate does this anyway, so perhaps get rid of this: */
|
|
||||||
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes);
|
|
||||||
CFSocketInvalidate(data->socket);
|
CFSocketInvalidate(data->socket);
|
||||||
CFRelease(data->socket);
|
CFRelease(data->socket);
|
||||||
free(data);
|
free(data);
|
||||||
@@ -175,20 +170,18 @@ void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
|
|||||||
|
|
||||||
void _GSocket_Enable_Events(GSocket *socket)
|
void _GSocket_Enable_Events(GSocket *socket)
|
||||||
{
|
{
|
||||||
CFOptionFlags callBackTypes = kCFSocketReadCallBack | kCFSocketWriteCallBack;
|
|
||||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
if(!socket->m_server)
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopDefaultMode);
|
||||||
callBackTypes |= kCFSocketConnectCallBack;
|
|
||||||
CFSocketEnableCallBacks(data->socket, callBackTypes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _GSocket_Disable_Events(GSocket *socket)
|
void _GSocket_Disable_Events(GSocket *socket)
|
||||||
{
|
{
|
||||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
CFSocketDisableCallBacks(data->socket, ALL_CALLBACK_TYPES);
|
|
||||||
|
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopCommonModes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_SOCKETS
|
#endif // wxUSE_SOCKETS
|
||||||
|
Reference in New Issue
Block a user