]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/gsockpm.c
c210cb0b2893b62e9e6585a06b05e15beb10e14d
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket: PM part
5 * Licence: The wxWindows licence
7 * ------------------------------------------------------------------------- */
14 #include "wx/unix/gsockunx.h"
15 #include "wx/gsocket.h"
17 extern int wxAppAddSocketHandler(int handle
, int mask
,
18 void (*callback
)(void*), void * gsock
);
20 extern void wxAppRemoveSocketHandler(int handle
);
22 #define wxSockReadMask 0x01
23 #define wxSockWriteMask 0x02
25 static void _GSocket_PM_Input(void *data
)
27 GSocket
*socket
= (GSocket
*) data
;
28 socket
->m_functions
->Detected_Read(socket
);
31 static void _GSocket_PM_Output(void *data
)
33 GSocket
*socket
= (GSocket
*) data
;
34 socket
->m_functions
->Detected_Write(socket
);
37 int _GSocket_GUI_Init(void)
42 void _GSocket_GUI_Cleanup(void)
46 int _GSocket_GUI_Init_Socket(GSocket
*socket
)
49 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
50 m_id
= (int *)(socket
->m_gui_dependent
);
57 void _GSocket_GUI_Destroy_Socket(GSocket
*socket
)
59 free(socket
->m_gui_dependent
);
62 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
)
64 int *m_id
= (int *)(socket
->m_gui_dependent
);
67 if (socket
->m_fd
== -1)
72 case GSOCK_LOST
: /* fall-through */
73 case GSOCK_INPUT
: c
= 0; break;
74 case GSOCK_OUTPUT
: c
= 1; break;
75 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
80 wxAppRemoveSocketHandler(m_id
[c
]);
84 m_id
[0] = wxAppAddSocketHandler(socket
->m_fd
, wxSockReadMask
,
85 _GSocket_PM_Input
, (void *)socket
);
89 m_id
[1] = wxAppAddSocketHandler(socket
->m_fd
, wxSockWriteMask
,
90 _GSocket_PM_Output
, (void *)socket
);
94 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
96 int *m_id
= (int *)(socket
->m_gui_dependent
);
100 case GSOCK_LOST
: /* fall-through */
101 case GSOCK_INPUT
: c
= 0; break;
102 case GSOCK_OUTPUT
: c
= 1; break;
103 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
107 wxAppRemoveSocketHandler(m_id
[c
]);
112 void _GSocket_Enable_Events(GSocket
*socket
)
114 _GSocket_Install_Callback(socket
, GSOCK_INPUT
);
115 _GSocket_Install_Callback(socket
, GSOCK_OUTPUT
);
118 void _GSocket_Disable_Events(GSocket
*socket
)
120 _GSocket_Uninstall_Callback(socket
, GSOCK_INPUT
);
121 _GSocket_Uninstall_Callback(socket
, GSOCK_OUTPUT
);
124 #else /* !wxUSE_SOCKETS */
126 /* some compilers don't like having empty source files */
127 static int wxDummyGsockVar
= 0;
129 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */