Removed unneeded GSocket files
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28646 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
1605c81288
commit
e219748f2c
@ -1,128 +0,0 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: GSocket (Generic Socket) for WX
|
||||
* Name: gsockgtk.c
|
||||
* Purpose: GSocket: GTK part
|
||||
* Licence: The wxWidgets licence
|
||||
* CVSID: $Id$
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
#include "wx/setup.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "wx/gsocket.h"
|
||||
#include "wx/unix/gsockunx.h"
|
||||
|
||||
|
||||
void _GSocket_GDK_Input(gpointer data,
|
||||
gint source,
|
||||
GdkInputCondition condition)
|
||||
{
|
||||
GSocket *socket = (GSocket *)data;
|
||||
|
||||
if (condition & GDK_INPUT_READ)
|
||||
socket->m_functions->Detected_Read(socket);
|
||||
if (condition & GDK_INPUT_WRITE)
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init_Socket(GSocket *socket)
|
||||
{
|
||||
gint *m_id;
|
||||
|
||||
socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
|
||||
m_id = (gint *)(socket->m_gui_dependent);
|
||||
|
||||
m_id[0] = -1;
|
||||
m_id[1] = -1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
||||
{
|
||||
free(socket->m_gui_dependent);
|
||||
}
|
||||
|
||||
void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
gint *m_id = (gint *)(socket->m_gui_dependent);
|
||||
int c;
|
||||
|
||||
if (socket->m_fd == -1)
|
||||
return;
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_LOST: /* fall-through */
|
||||
case GSOCK_INPUT: c = 0; break;
|
||||
case GSOCK_OUTPUT: c = 1; break;
|
||||
case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
if (m_id[c] != -1)
|
||||
gdk_input_remove(m_id[c]);
|
||||
|
||||
m_id[c] = gdk_input_add(socket->m_fd,
|
||||
(c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
|
||||
_GSocket_GDK_Input,
|
||||
(gpointer)socket);
|
||||
}
|
||||
|
||||
void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
gint *m_id = (gint *)(socket->m_gui_dependent);
|
||||
int c;
|
||||
|
||||
assert( m_id != NULL );
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_LOST: /* fall-through */
|
||||
case GSOCK_INPUT: c = 0; break;
|
||||
case GSOCK_OUTPUT: c = 1; break;
|
||||
case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
if (m_id[c] != -1)
|
||||
gdk_input_remove(m_id[c]);
|
||||
|
||||
m_id[c] = -1;
|
||||
}
|
||||
|
||||
void _GSocket_Enable_Events(GSocket *socket)
|
||||
{
|
||||
_GSocket_Install_Callback(socket, GSOCK_INPUT);
|
||||
_GSocket_Install_Callback(socket, GSOCK_OUTPUT);
|
||||
}
|
||||
|
||||
void _GSocket_Disable_Events(GSocket *socket)
|
||||
{
|
||||
_GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
|
||||
_GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
|
||||
}
|
||||
|
||||
#else /* !wxUSE_SOCKETS */
|
||||
|
||||
/* some compilers don't like having empty source files */
|
||||
static int wxDummyGsockVar = 0;
|
||||
|
||||
#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */
|
@ -1,128 +0,0 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: GSocket (Generic Socket) for WX
|
||||
* Name: gsockgtk.c
|
||||
* Purpose: GSocket: GTK part
|
||||
* Licence: The wxWidgets licence
|
||||
* CVSID: $Id$
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
#include "wx/setup.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "wx/gsocket.h"
|
||||
#include "wx/unix/gsockunx.h"
|
||||
|
||||
|
||||
void _GSocket_GDK_Input(gpointer data,
|
||||
gint source,
|
||||
GdkInputCondition condition)
|
||||
{
|
||||
GSocket *socket = (GSocket *)data;
|
||||
|
||||
if (condition & GDK_INPUT_READ)
|
||||
socket->m_functions->Detected_Read(socket);
|
||||
if (condition & GDK_INPUT_WRITE)
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init_Socket(GSocket *socket)
|
||||
{
|
||||
gint *m_id;
|
||||
|
||||
socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
|
||||
m_id = (gint *)(socket->m_gui_dependent);
|
||||
|
||||
m_id[0] = -1;
|
||||
m_id[1] = -1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
||||
{
|
||||
free(socket->m_gui_dependent);
|
||||
}
|
||||
|
||||
void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
gint *m_id = (gint *)(socket->m_gui_dependent);
|
||||
int c;
|
||||
|
||||
if (socket->m_fd == -1)
|
||||
return;
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_LOST: /* fall-through */
|
||||
case GSOCK_INPUT: c = 0; break;
|
||||
case GSOCK_OUTPUT: c = 1; break;
|
||||
case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
if (m_id[c] != -1)
|
||||
gdk_input_remove(m_id[c]);
|
||||
|
||||
m_id[c] = gdk_input_add(socket->m_fd,
|
||||
(c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
|
||||
_GSocket_GDK_Input,
|
||||
(gpointer)socket);
|
||||
}
|
||||
|
||||
void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
gint *m_id = (gint *)(socket->m_gui_dependent);
|
||||
int c;
|
||||
|
||||
assert( m_id != NULL );
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_LOST: /* fall-through */
|
||||
case GSOCK_INPUT: c = 0; break;
|
||||
case GSOCK_OUTPUT: c = 1; break;
|
||||
case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
if (m_id[c] != -1)
|
||||
gdk_input_remove(m_id[c]);
|
||||
|
||||
m_id[c] = -1;
|
||||
}
|
||||
|
||||
void _GSocket_Enable_Events(GSocket *socket)
|
||||
{
|
||||
_GSocket_Install_Callback(socket, GSOCK_INPUT);
|
||||
_GSocket_Install_Callback(socket, GSOCK_OUTPUT);
|
||||
}
|
||||
|
||||
void _GSocket_Disable_Events(GSocket *socket)
|
||||
{
|
||||
_GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
|
||||
_GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
|
||||
}
|
||||
|
||||
#else /* !wxUSE_SOCKETS */
|
||||
|
||||
/* some compilers don't like having empty source files */
|
||||
static int wxDummyGsockVar = 0;
|
||||
|
||||
#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */
|
@ -1,184 +0,0 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: GSocket (Generic Socket) for WX
|
||||
* Name: gsockosx.c
|
||||
* Purpose: GSocket: Mac OS X mach-o part
|
||||
* CVSID: $Id$
|
||||
* Mac code by Brian Victor, February 2002. Email comments to bhv1@psu.edu
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
#include "wx/setup.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "wx/gsocket.h"
|
||||
#include "wx/unix/gsockunx.h"
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
#define ALL_CALLBACK_TYPES (kCFSocketReadCallBack | kCFSocketWriteCallBack | kCFSocketConnectCallBack)
|
||||
|
||||
struct MacGSocketData
|
||||
{
|
||||
CFSocketRef socket;
|
||||
CFRunLoopSourceRef source;
|
||||
};
|
||||
|
||||
void Mac_Socket_Callback(CFSocketRef s, CFSocketCallBackType callbackType,
|
||||
CFDataRef address, const void* data, void* info)
|
||||
{
|
||||
GSocket* socket = (GSocket*)info;
|
||||
struct MacGSocketData* macdata;
|
||||
macdata = (struct MacGSocketData*)socket->m_gui_dependent;
|
||||
if (!macdata) return;
|
||||
switch (callbackType)
|
||||
{
|
||||
case kCFSocketConnectCallBack:
|
||||
assert(!socket->m_server);
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
break;
|
||||
case kCFSocketReadCallBack:
|
||||
socket->m_functions->Detected_Read(socket);
|
||||
break;
|
||||
case kCFSocketWriteCallBack:
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
break;
|
||||
default:
|
||||
break; /* We shouldn't get here. */
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* CFSocket has not been created, create it: */
|
||||
if (socket->m_fd < 0 || !data) return NULL;
|
||||
cont.version = 0; cont.retain = NULL;
|
||||
cont.release = NULL; cont.copyDescription = NULL;
|
||||
cont.info = socket;
|
||||
|
||||
cf = CFSocketCreateWithNative(NULL, socket->m_fd,
|
||||
ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont);
|
||||
source = CFSocketCreateRunLoopSource(NULL, cf, 0);
|
||||
assert(source);
|
||||
socket->m_gui_dependent = (char*)data;
|
||||
|
||||
/* Keep the source and the socket around. */
|
||||
data->source = source;
|
||||
data->socket = cf;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init_Socket(GSocket *socket)
|
||||
{
|
||||
struct MacGSocketData *data = malloc(sizeof(struct MacGSocketData));
|
||||
if (data)
|
||||
{
|
||||
socket->m_gui_dependent = (char*)data;
|
||||
data->socket = NULL;
|
||||
data->source = NULL;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
||||
{
|
||||
struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
|
||||
if (data)
|
||||
{
|
||||
CFRelease(data->socket);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int c;
|
||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||
if (!data) return;
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_CONNECTION:
|
||||
if(socket->m_server)
|
||||
c = kCFSocketReadCallBack;
|
||||
else
|
||||
c = kCFSocketConnectCallBack;
|
||||
break;
|
||||
case GSOCK_LOST:
|
||||
case GSOCK_INPUT:
|
||||
c = kCFSocketReadCallBack;
|
||||
break;
|
||||
case GSOCK_OUTPUT:
|
||||
c = kCFSocketWriteCallBack;
|
||||
break;
|
||||
default:
|
||||
c = 0;
|
||||
}
|
||||
CFSocketEnableCallBacks(data->socket, c);
|
||||
}
|
||||
|
||||
void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int c;
|
||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||
if (!data) return;
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_CONNECTION:
|
||||
if(socket->m_server)
|
||||
c = kCFSocketReadCallBack;
|
||||
else
|
||||
c = kCFSocketConnectCallBack;
|
||||
break;
|
||||
case GSOCK_LOST:
|
||||
case GSOCK_INPUT:
|
||||
c = kCFSocketReadCallBack;
|
||||
break;
|
||||
case GSOCK_OUTPUT:
|
||||
c = kCFSocketWriteCallBack;
|
||||
break;
|
||||
default:
|
||||
c = 0;
|
||||
}
|
||||
CFSocketDisableCallBacks(data->socket, c);
|
||||
}
|
||||
|
||||
void _GSocket_Enable_Events(GSocket *socket)
|
||||
{
|
||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||
if (!data) return;
|
||||
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
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
|
@ -1,181 +0,0 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: GSocket (Generic Socket) for WX
|
||||
* Name: gsockosx.c
|
||||
* Purpose: GSocket: Mac OS X mach-o part
|
||||
* CVSID: $Id$
|
||||
* Mac code by Brian Victor, February 2002. Email comments to bhv1@psu.edu
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
#include "wx/setup.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "wx/gsocket.h"
|
||||
#include "wx/unix/gsockunx.h"
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
#define ALL_CALLBACK_TYPES (kCFSocketReadCallBack | kCFSocketWriteCallBack | kCFSocketConnectCallBack)
|
||||
|
||||
struct MacGSocketData
|
||||
{
|
||||
CFSocketRef socket;
|
||||
CFRunLoopSourceRef source;
|
||||
};
|
||||
|
||||
void Mac_Socket_Callback(CFSocketRef s, CFSocketCallBackType callbackType,
|
||||
CFDataRef address, const void* data, void* info)
|
||||
{
|
||||
GSocket* socket = (GSocket*)info;
|
||||
struct MacGSocketData* macdata;
|
||||
macdata = (struct MacGSocketData*)socket->m_gui_dependent;
|
||||
if (!macdata) return;
|
||||
switch (callbackType)
|
||||
{
|
||||
case kCFSocketConnectCallBack:
|
||||
assert(!socket->m_server);
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
break;
|
||||
case kCFSocketReadCallBack:
|
||||
socket->m_functions->Detected_Read(socket);
|
||||
break;
|
||||
case kCFSocketWriteCallBack:
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
break;
|
||||
default:
|
||||
break; /* We shouldn't get here. */
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
struct MacGSocketData* data = (struct MacGSocketData*)socket->m_gui_dependent;
|
||||
|
||||
if (data && data->source) return data;
|
||||
|
||||
/* CFSocket has not been created, create it: */
|
||||
if (socket->m_fd < 0 || !data) return NULL;
|
||||
cont.version = 0; cont.retain = NULL;
|
||||
cont.release = NULL; cont.copyDescription = NULL;
|
||||
cont.info = socket;
|
||||
|
||||
CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd,
|
||||
ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont);
|
||||
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, cf, 0);
|
||||
assert(source);
|
||||
socket->m_gui_dependent = (char*)data;
|
||||
|
||||
/* Keep the source and the socket around. */
|
||||
data->source = source;
|
||||
data->socket = cf;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init_Socket(GSocket *socket)
|
||||
{
|
||||
struct MacGSocketData *data = malloc(sizeof(struct MacGSocketData));
|
||||
if (data)
|
||||
{
|
||||
socket->m_gui_dependent = (char*)data;
|
||||
data->socket = NULL;
|
||||
data->source = NULL;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
||||
{
|
||||
struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
|
||||
if (data)
|
||||
{
|
||||
CFRelease(data->socket);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int c;
|
||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||
if (!data) return;
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_CONNECTION:
|
||||
if(socket->m_server)
|
||||
c = kCFSocketReadCallBack;
|
||||
else
|
||||
c = kCFSocketConnectCallBack;
|
||||
break;
|
||||
case GSOCK_LOST:
|
||||
case GSOCK_INPUT:
|
||||
c = kCFSocketReadCallBack;
|
||||
break;
|
||||
case GSOCK_OUTPUT:
|
||||
c = kCFSocketWriteCallBack;
|
||||
break;
|
||||
default:
|
||||
c = 0;
|
||||
}
|
||||
CFSocketEnableCallBacks(data->socket, c);
|
||||
}
|
||||
|
||||
void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int c;
|
||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||
if (!data) return;
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_CONNECTION:
|
||||
if(socket->m_server)
|
||||
c = kCFSocketReadCallBack;
|
||||
else
|
||||
c = kCFSocketConnectCallBack;
|
||||
break;
|
||||
case GSOCK_LOST:
|
||||
case GSOCK_INPUT:
|
||||
c = kCFSocketReadCallBack;
|
||||
break;
|
||||
case GSOCK_OUTPUT:
|
||||
c = kCFSocketWriteCallBack;
|
||||
break;
|
||||
default:
|
||||
c = 0;
|
||||
}
|
||||
CFSocketDisableCallBacks(data->socket, c);
|
||||
}
|
||||
|
||||
void _GSocket_Enable_Events(GSocket *socket)
|
||||
{
|
||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||
if (!data) return;
|
||||
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
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
|
@ -1,181 +0,0 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: GSocket (Generic Socket) for WX
|
||||
* Name: gsockosx.c
|
||||
* Purpose: GSocket: Mac OS X mach-o part
|
||||
* CVSID: $Id$
|
||||
* Mac code by Brian Victor, February 2002. Email comments to bhv1@psu.edu
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
#include "wx/setup.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "wx/gsocket.h"
|
||||
#include "wx/unix/gsockunx.h"
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
#define ALL_CALLBACK_TYPES (kCFSocketReadCallBack | kCFSocketWriteCallBack | kCFSocketConnectCallBack)
|
||||
|
||||
struct MacGSocketData
|
||||
{
|
||||
CFSocketRef socket;
|
||||
CFRunLoopSourceRef source;
|
||||
};
|
||||
|
||||
void Mac_Socket_Callback(CFSocketRef s, CFSocketCallBackType callbackType,
|
||||
CFDataRef address, const void* data, void* info)
|
||||
{
|
||||
GSocket* socket = (GSocket*)info;
|
||||
struct MacGSocketData* macdata;
|
||||
macdata = (struct MacGSocketData*)socket->m_gui_dependent;
|
||||
if (!macdata) return;
|
||||
switch (callbackType)
|
||||
{
|
||||
case kCFSocketConnectCallBack:
|
||||
assert(!socket->m_server);
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
break;
|
||||
case kCFSocketReadCallBack:
|
||||
socket->m_functions->Detected_Read(socket);
|
||||
break;
|
||||
case kCFSocketWriteCallBack:
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
break;
|
||||
default:
|
||||
break; /* We shouldn't get here. */
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
struct MacGSocketData* data = (struct MacGSocketData*)socket->m_gui_dependent;
|
||||
|
||||
if (data && data->source) return data;
|
||||
|
||||
/* CFSocket has not been created, create it: */
|
||||
if (socket->m_fd < 0 || !data) return NULL;
|
||||
cont.version = 0; cont.retain = NULL;
|
||||
cont.release = NULL; cont.copyDescription = NULL;
|
||||
cont.info = socket;
|
||||
|
||||
CFSocketRef cf = CFSocketCreateWithNative(NULL, socket->m_fd,
|
||||
ALL_CALLBACK_TYPES, Mac_Socket_Callback, &cont);
|
||||
CFRunLoopSourceRef source = CFSocketCreateRunLoopSource(NULL, cf, 0);
|
||||
assert(source);
|
||||
socket->m_gui_dependent = (char*)data;
|
||||
|
||||
/* Keep the source and the socket around. */
|
||||
data->source = source;
|
||||
data->socket = cf;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init_Socket(GSocket *socket)
|
||||
{
|
||||
struct MacGSocketData *data = malloc(sizeof(struct MacGSocketData));
|
||||
if (data)
|
||||
{
|
||||
socket->m_gui_dependent = (char*)data;
|
||||
data->socket = NULL;
|
||||
data->source = NULL;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
||||
{
|
||||
struct MacGSocketData *data = (struct MacGSocketData*)(socket->m_gui_dependent);
|
||||
if (data)
|
||||
{
|
||||
CFRelease(data->socket);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int c;
|
||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||
if (!data) return;
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_CONNECTION:
|
||||
if(socket->m_server)
|
||||
c = kCFSocketReadCallBack;
|
||||
else
|
||||
c = kCFSocketConnectCallBack;
|
||||
break;
|
||||
case GSOCK_LOST:
|
||||
case GSOCK_INPUT:
|
||||
c = kCFSocketReadCallBack;
|
||||
break;
|
||||
case GSOCK_OUTPUT:
|
||||
c = kCFSocketWriteCallBack;
|
||||
break;
|
||||
default:
|
||||
c = 0;
|
||||
}
|
||||
CFSocketEnableCallBacks(data->socket, c);
|
||||
}
|
||||
|
||||
void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int c;
|
||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||
if (!data) return;
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_CONNECTION:
|
||||
if(socket->m_server)
|
||||
c = kCFSocketReadCallBack;
|
||||
else
|
||||
c = kCFSocketConnectCallBack;
|
||||
break;
|
||||
case GSOCK_LOST:
|
||||
case GSOCK_INPUT:
|
||||
c = kCFSocketReadCallBack;
|
||||
break;
|
||||
case GSOCK_OUTPUT:
|
||||
c = kCFSocketWriteCallBack;
|
||||
break;
|
||||
default:
|
||||
c = 0;
|
||||
}
|
||||
CFSocketDisableCallBacks(data->socket, c);
|
||||
}
|
||||
|
||||
void _GSocket_Enable_Events(GSocket *socket)
|
||||
{
|
||||
struct MacGSocketData* data = _GSocket_Get_Mac_Socket(socket);
|
||||
if (!data) return;
|
||||
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), data->source, kCFRunLoopDefaultMode);
|
||||
}
|
||||
|
||||
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
|
@ -1,136 +0,0 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: GSocket (Generic Socket) for WX
|
||||
* Name: gsockmot.c
|
||||
* Purpose: GSocket: Motif part
|
||||
* CVSID: $Id$
|
||||
* Licence: The wxWidgets licence
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
#include "wx/setup.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
#include "wx/gsocket.h"
|
||||
#include "wx/unix/gsockunx.h"
|
||||
|
||||
extern XtAppContext wxGetAppContext();
|
||||
|
||||
static void _GSocket_Motif_Input(XtPointer data, int *fid,
|
||||
XtInputId *id)
|
||||
{
|
||||
GSocket *socket = (GSocket *)data;
|
||||
|
||||
socket->m_functions->Detected_Read(socket);
|
||||
}
|
||||
|
||||
static void _GSocket_Motif_Output(XtPointer data, int *fid,
|
||||
XtInputId *id)
|
||||
{
|
||||
GSocket *socket = (GSocket *)data;
|
||||
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init_Socket(GSocket *socket)
|
||||
{
|
||||
int *m_id;
|
||||
|
||||
socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
|
||||
m_id = (int *)(socket->m_gui_dependent);
|
||||
|
||||
m_id[0] = -1;
|
||||
m_id[1] = -1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
||||
{
|
||||
free(socket->m_gui_dependent);
|
||||
}
|
||||
|
||||
void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int *m_id = (int *)(socket->m_gui_dependent);
|
||||
int c;
|
||||
|
||||
if (socket->m_fd == -1)
|
||||
return;
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_LOST: /* fall-through */
|
||||
case GSOCK_INPUT: c = 0; break;
|
||||
case GSOCK_OUTPUT: c = 1; break;
|
||||
case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
if (m_id[c] != -1)
|
||||
XtRemoveInput(m_id[c]);
|
||||
|
||||
if (c == 0)
|
||||
{
|
||||
m_id[0] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
|
||||
(XtPointer *)XtInputReadMask,
|
||||
(XtInputCallbackProc) _GSocket_Motif_Input,
|
||||
(XtPointer) socket);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_id[1] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
|
||||
(XtPointer *)XtInputWriteMask,
|
||||
(XtInputCallbackProc) _GSocket_Motif_Output,
|
||||
(XtPointer) socket);
|
||||
}
|
||||
}
|
||||
|
||||
void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int *m_id = (int *)(socket->m_gui_dependent);
|
||||
int c;
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_LOST: /* fall-through */
|
||||
case GSOCK_INPUT: c = 0; break;
|
||||
case GSOCK_OUTPUT: c = 1; break;
|
||||
case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
if (m_id[c] != -1)
|
||||
XtRemoveInput(m_id[c]);
|
||||
|
||||
m_id[c] = -1;
|
||||
}
|
||||
|
||||
void _GSocket_Enable_Events(GSocket *socket)
|
||||
{
|
||||
_GSocket_Install_Callback(socket, GSOCK_INPUT);
|
||||
_GSocket_Install_Callback(socket, GSOCK_OUTPUT);
|
||||
}
|
||||
|
||||
void _GSocket_Disable_Events(GSocket *socket)
|
||||
{
|
||||
_GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
|
||||
_GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
|
||||
}
|
||||
|
||||
#else /* !wxUSE_SOCKETS */
|
||||
|
||||
/* some compilers don't like having empty source files */
|
||||
static int wxDummyGsockVar = 0;
|
||||
|
||||
#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */
|
1553
src/msw/gsocket.c
1553
src/msw/gsocket.c
File diff suppressed because it is too large
Load Diff
@ -1,324 +0,0 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: GSocket (Generic Socket)
|
||||
* Name: gsockmsw.c
|
||||
* Author: Guillermo Rodriguez Garcia <guille@iies.es>
|
||||
* Purpose: GSocket GUI-specific MSW code
|
||||
* CVSID: $Id$
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO: for WinCE we need to replace WSAAsyncSelect
|
||||
* (Windows message-based notification of network events for a socket)
|
||||
* with another mechanism.
|
||||
* We may need to have a separate thread that polls for socket events
|
||||
* using select() and sends a message to the main thread.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PLEASE don't put C++ comments here - this is a C source file.
|
||||
*/
|
||||
|
||||
/* including rasasync.h (included from windows.h itself included from
|
||||
* wx/setup.h and/or winsock.h results in this warning for
|
||||
* RPCNOTIFICATION_ROUTINE
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(disable:4115) /* named type definition in parentheses */
|
||||
#endif
|
||||
|
||||
/* This needs to be before the wx/defs/h inclusion
|
||||
* for some reason
|
||||
*/
|
||||
|
||||
#ifdef __WXWINCE__
|
||||
/* windows.h results in tons of warnings at max warning level */
|
||||
# ifdef _MSC_VER
|
||||
# pragma warning(push, 1)
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
# pragma warning(disable:4514)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __GSOCKET_STANDALONE__
|
||||
# include "wx/platform.h"
|
||||
# include "wx/setup.h"
|
||||
#endif
|
||||
|
||||
#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
|
||||
|
||||
#ifndef __GSOCKET_STANDALONE__
|
||||
|
||||
#include "wx/msw/gsockmsw.h"
|
||||
#include "wx/gsocket.h"
|
||||
|
||||
HINSTANCE wxGetInstance(void);
|
||||
#define INSTANCE wxGetInstance()
|
||||
|
||||
#else
|
||||
|
||||
#include "gsockmsw.h"
|
||||
#include "gsocket.h"
|
||||
|
||||
/* If not using wxWidgets, a global var called hInst must
|
||||
* be available and it must contain the app's instance
|
||||
* handle.
|
||||
*/
|
||||
#define INSTANCE hInst
|
||||
|
||||
#endif /* __GSOCKET_STANDALONE__ */
|
||||
|
||||
#ifndef __WXWINCE__
|
||||
#include <assert.h>
|
||||
#else
|
||||
#define assert(x)
|
||||
#include <winsock.h>
|
||||
#include "wx/msw/wince/net.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <winsock.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(default:4115) /* named type definition in parentheses */
|
||||
#endif
|
||||
|
||||
#define CLASSNAME TEXT("_GSocket_Internal_Window_Class")
|
||||
|
||||
/* implemented in utils.cpp */
|
||||
extern WXDLLIMPEXP_BASE HWND
|
||||
wxCreateHiddenWindow(LPCTSTR *pclassname, LPCTSTR classname, WNDPROC wndproc);
|
||||
|
||||
/* Maximum number of different GSocket objects at a given time.
|
||||
* This value can be modified at will, but it CANNOT be greater
|
||||
* than (0x7FFF - WM_USER + 1)
|
||||
*/
|
||||
#define MAXSOCKETS 1024
|
||||
|
||||
#if (MAXSOCKETS > (0x7FFF - WM_USER + 1))
|
||||
#error "MAXSOCKETS is too big!"
|
||||
#endif
|
||||
|
||||
typedef int (PASCAL *WSAAsyncSelectFunc)(SOCKET,HWND,u_int,long);
|
||||
|
||||
/* Global variables */
|
||||
|
||||
extern HINSTANCE INSTANCE;
|
||||
static HWND hWin;
|
||||
static CRITICAL_SECTION critical;
|
||||
static GSocket* socketList[MAXSOCKETS];
|
||||
static int firstAvailable;
|
||||
static WSAAsyncSelectFunc gs_WSAAsyncSelect = NULL;
|
||||
static HMODULE gs_wsock32dll = 0;
|
||||
|
||||
/* Global initializers */
|
||||
|
||||
int _GSocket_GUI_Init(void)
|
||||
{
|
||||
static LPCTSTR pclassname = NULL;
|
||||
int i;
|
||||
|
||||
/* Create internal window for event notifications */
|
||||
hWin = wxCreateHiddenWindow(&pclassname, CLASSNAME, _GSocket_Internal_WinProc);
|
||||
if (!hWin)
|
||||
return FALSE;
|
||||
|
||||
/* Initialize socket list */
|
||||
InitializeCriticalSection(&critical);
|
||||
|
||||
for (i = 0; i < MAXSOCKETS; i++)
|
||||
{
|
||||
socketList[i] = NULL;
|
||||
}
|
||||
firstAvailable = 0;
|
||||
|
||||
/* Load WSAAsyncSelect from wsock32.dll (we don't link against it
|
||||
statically to avoid dependency on wsock32.dll for apps that don't use
|
||||
sockets): */
|
||||
gs_wsock32dll = LoadLibraryA("wsock32.dll");
|
||||
if (!gs_wsock32dll)
|
||||
return FALSE;
|
||||
gs_WSAAsyncSelect =(WSAAsyncSelectFunc)GetProcAddress(gs_wsock32dll,
|
||||
"WSAAsyncSelect");
|
||||
if (!gs_WSAAsyncSelect)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Cleanup(void)
|
||||
{
|
||||
/* Destroy internal window */
|
||||
DestroyWindow(hWin);
|
||||
UnregisterClass(CLASSNAME, INSTANCE);
|
||||
|
||||
/* Unlock wsock32.dll */
|
||||
if (gs_wsock32dll)
|
||||
{
|
||||
FreeLibrary(gs_wsock32dll);
|
||||
gs_wsock32dll = 0;
|
||||
}
|
||||
|
||||
/* Delete critical section */
|
||||
DeleteCriticalSection(&critical);
|
||||
}
|
||||
|
||||
/* Per-socket GUI initialization / cleanup */
|
||||
|
||||
int _GSocket_GUI_Init_Socket(GSocket *socket)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Allocate a new message number for this socket */
|
||||
EnterCriticalSection(&critical);
|
||||
|
||||
i = firstAvailable;
|
||||
while (socketList[i] != NULL)
|
||||
{
|
||||
i = (i + 1) % MAXSOCKETS;
|
||||
|
||||
if (i == firstAvailable) /* abort! */
|
||||
{
|
||||
LeaveCriticalSection(&critical);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
socketList[i] = socket;
|
||||
firstAvailable = (i + 1) % MAXSOCKETS;
|
||||
socket->m_msgnumber = (i + WM_USER);
|
||||
|
||||
LeaveCriticalSection(&critical);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
||||
{
|
||||
/* Remove the socket from the list */
|
||||
EnterCriticalSection(&critical);
|
||||
socketList[(socket->m_msgnumber - WM_USER)] = NULL;
|
||||
LeaveCriticalSection(&critical);
|
||||
}
|
||||
|
||||
/* Windows proc for asynchronous event handling */
|
||||
|
||||
LRESULT CALLBACK _GSocket_Internal_WinProc(HWND hWnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
GSocket *socket;
|
||||
GSocketEvent event;
|
||||
GSocketCallback cback;
|
||||
char *data;
|
||||
|
||||
if (uMsg >= WM_USER && uMsg <= (WM_USER + MAXSOCKETS - 1))
|
||||
{
|
||||
EnterCriticalSection(&critical);
|
||||
socket = socketList[(uMsg - WM_USER)];
|
||||
event = (GSocketEvent) -1;
|
||||
cback = NULL;
|
||||
data = NULL;
|
||||
|
||||
/* Check that the socket still exists (it has not been
|
||||
* destroyed) and for safety, check that the m_fd field
|
||||
* is what we expect it to be.
|
||||
*/
|
||||
if ((socket != NULL) && (socket->m_fd == wParam))
|
||||
{
|
||||
switch WSAGETSELECTEVENT(lParam)
|
||||
{
|
||||
case FD_READ: event = GSOCK_INPUT; break;
|
||||
case FD_WRITE: event = GSOCK_OUTPUT; break;
|
||||
case FD_ACCEPT: event = GSOCK_CONNECTION; break;
|
||||
case FD_CONNECT:
|
||||
{
|
||||
if (WSAGETSELECTERROR(lParam) != 0)
|
||||
event = GSOCK_LOST;
|
||||
else
|
||||
event = GSOCK_CONNECTION;
|
||||
break;
|
||||
}
|
||||
case FD_CLOSE: event = GSOCK_LOST; break;
|
||||
}
|
||||
|
||||
if (event != -1)
|
||||
{
|
||||
cback = socket->m_cbacks[event];
|
||||
data = socket->m_data[event];
|
||||
|
||||
if (event == GSOCK_LOST)
|
||||
socket->m_detected = GSOCK_LOST_FLAG;
|
||||
else
|
||||
socket->m_detected |= (1 << event);
|
||||
}
|
||||
}
|
||||
|
||||
/* OK, we can now leave the critical section because we have
|
||||
* already obtained the callback address (we make no further
|
||||
* accesses to socket->whatever). However, the app should
|
||||
* be prepared to handle events from a socket that has just
|
||||
* been closed!
|
||||
*/
|
||||
LeaveCriticalSection(&critical);
|
||||
|
||||
if (cback != NULL)
|
||||
(cback)(socket, event, data);
|
||||
|
||||
return (LRESULT) 0;
|
||||
}
|
||||
else
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
/* _GSocket_Enable_Events:
|
||||
* Enable all event notifications; we need to be notified of all
|
||||
* events for internal processing, but we will only notify users
|
||||
* when an appropiate callback function has been installed.
|
||||
*/
|
||||
void _GSocket_Enable_Events(GSocket *socket)
|
||||
{
|
||||
assert (socket != NULL);
|
||||
|
||||
if (socket->m_fd != INVALID_SOCKET)
|
||||
{
|
||||
/* We could probably just subscribe to all events regardless
|
||||
* of the socket type, but MS recommends to do it this way.
|
||||
*/
|
||||
long lEvent = socket->m_server?
|
||||
FD_ACCEPT : (FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE);
|
||||
|
||||
gs_WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, lEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/* _GSocket_Disable_Events:
|
||||
* Disable event notifications (when shutdowning the socket)
|
||||
*/
|
||||
void _GSocket_Disable_Events(GSocket *socket)
|
||||
{
|
||||
assert (socket != NULL);
|
||||
|
||||
if (socket->m_fd != INVALID_SOCKET)
|
||||
{
|
||||
gs_WSAAsyncSelect(socket->m_fd, hWin, socket->m_msgnumber, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* !wxUSE_SOCKETS */
|
||||
|
||||
/*
|
||||
* Translation unit shouldn't be empty, so include this typedef to make the
|
||||
* compiler (VC++ 6.0, for example) happy
|
||||
*/
|
||||
typedef void (*wxDummy)();
|
||||
|
||||
#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
|
1841
src/unix/gsocket.c
1841
src/unix/gsocket.c
File diff suppressed because it is too large
Load Diff
@ -1,152 +0,0 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Project: GSocket (Generic Socket) for WX
|
||||
* Name: gsockmot.c
|
||||
* Purpose: GSocket: X11 part
|
||||
* Licence: The wxWidgets licence
|
||||
* CVSID: $Id$
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
#include "wx/setup.h"
|
||||
|
||||
#if wxUSE_SOCKETS
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "wx/gsocket.h"
|
||||
#include "wx/unix/gsockunx.h"
|
||||
|
||||
/*
|
||||
* FIXME: have these in a common header instead of being repeated
|
||||
* in evtloop.cpp and gsockx11.c
|
||||
*/
|
||||
|
||||
typedef void (*wxSocketCallback) (int fd, void* data);
|
||||
|
||||
typedef enum
|
||||
{ wxSocketTableInput, wxSocketTableOutput } wxSocketTableType ;
|
||||
|
||||
void wxRegisterSocketCallback(int fd, wxSocketTableType socketType, wxSocketCallback cback, void* data);
|
||||
void wxUnregisterSocketCallback(int fd, wxSocketTableType socketType);
|
||||
|
||||
|
||||
static void _GSocket_X11_Input(int *fid, void* data)
|
||||
{
|
||||
GSocket *socket = (GSocket *)data;
|
||||
|
||||
socket->m_functions->Detected_Read(socket);
|
||||
}
|
||||
|
||||
static void _GSocket_X11_Output(int *fid, void* data)
|
||||
{
|
||||
GSocket *socket = (GSocket *)data;
|
||||
|
||||
socket->m_functions->Detected_Write(socket);
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
int _GSocket_GUI_Init_Socket(GSocket *socket)
|
||||
{
|
||||
int *m_id;
|
||||
|
||||
socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
|
||||
m_id = (int *)(socket->m_gui_dependent);
|
||||
|
||||
m_id[0] = -1;
|
||||
m_id[1] = -1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void _GSocket_GUI_Destroy_Socket(GSocket *socket)
|
||||
{
|
||||
free(socket->m_gui_dependent);
|
||||
}
|
||||
|
||||
void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int *m_id = (int *)(socket->m_gui_dependent);
|
||||
int c;
|
||||
|
||||
if (socket->m_fd == -1)
|
||||
return;
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_LOST: /* fall-through */
|
||||
case GSOCK_INPUT: c = 0; break;
|
||||
case GSOCK_OUTPUT: c = 1; break;
|
||||
case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (m_id[c] != -1)
|
||||
XtRemoveInput(m_id[c]);
|
||||
#endif /* 0 */
|
||||
|
||||
if (c == 0)
|
||||
{
|
||||
m_id[0] = socket->m_fd;
|
||||
|
||||
wxRegisterSocketCallback(socket->m_fd, wxSocketTableInput,
|
||||
(wxSocketCallback) _GSocket_X11_Input, (void*) socket);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_id[1] = socket->m_fd;
|
||||
|
||||
wxRegisterSocketCallback(socket->m_fd, wxSocketTableOutput,
|
||||
(wxSocketCallback) _GSocket_X11_Output, (void*) socket);
|
||||
}
|
||||
}
|
||||
|
||||
void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
|
||||
{
|
||||
int *m_id = (int *)(socket->m_gui_dependent);
|
||||
int c;
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case GSOCK_LOST: /* fall-through */
|
||||
case GSOCK_INPUT: c = 0; break;
|
||||
case GSOCK_OUTPUT: c = 1; break;
|
||||
case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
if (m_id[c] != -1)
|
||||
{
|
||||
if (c == 0)
|
||||
wxUnregisterSocketCallback(m_id[c], wxSocketTableInput);
|
||||
else
|
||||
wxUnregisterSocketCallback(m_id[c], wxSocketTableOutput);
|
||||
}
|
||||
|
||||
m_id[c] = -1;
|
||||
}
|
||||
|
||||
void _GSocket_Enable_Events(GSocket *socket)
|
||||
{
|
||||
_GSocket_Install_Callback(socket, GSOCK_INPUT);
|
||||
_GSocket_Install_Callback(socket, GSOCK_OUTPUT);
|
||||
}
|
||||
|
||||
void _GSocket_Disable_Events(GSocket *socket)
|
||||
{
|
||||
_GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
|
||||
_GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
|
||||
}
|
||||
|
||||
#else /* !wxUSE_SOCKETS */
|
||||
|
||||
/* some compilers don't like having empty source files */
|
||||
static int wxDummyGsockVar = 0;
|
||||
|
||||
#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */
|
Loading…
Reference in New Issue
Block a user