]> git.saurik.com Git - wxWidgets.git/blame - src/os2/gsockpm.c
Applied patch [ 649157 ] wxDisplay for Unix
[wxWidgets.git] / src / os2 / gsockpm.c
CommitLineData
3958ae62
SN
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockpm.c
4 * Purpose: GSocket: PM part
84969af7 5 * Licence: The wxWindows licence
3958ae62
SN
6 * CVSID: $Id$
7 * ------------------------------------------------------------------------- */
8
9#include "wx/setup.h"
10
11#if wxUSE_SOCKETS
12
13#include <stdlib.h>
14#include "wx/unix/gsockunx.h"
15#include "wx/gsocket.h"
16
17extern int wxAppAddSocketHandler(int handle, int mask,
18 void (*callback)(void*), void * gsock);
19
20extern void wxAppRemoveSocketHandler(int handle);
21
22#define wxSockReadMask 0x01
23#define wxSockWriteMask 0x02
24
25static void _GSocket_PM_Input(void *data)
26{
27 GSocket *socket = (GSocket *) data;
28 _GSocket_Detected_Read(socket);
29}
30
31static void _GSocket_PM_Output(void *data)
32{
33 GSocket *socket = (GSocket *) data;
34 _GSocket_Detected_Write(socket);
35}
36
37int _GSocket_GUI_Init(GSocket *socket)
38{
39 int *m_id;
40 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
41 m_id = (int *)(socket->m_gui_dependent);
42
43 m_id[0] = -1;
44 m_id[1] = -1;
45 return TRUE;
46}
47
48void _GSocket_GUI_Destroy(GSocket *socket)
49{
50 free(socket->m_gui_dependent);
51}
52
53void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
54{
55 int *m_id = (int *)(socket->m_gui_dependent);
56 int c;
57
58 if (socket->m_fd == -1)
59 return;
60
61 switch (event)
62 {
63 case GSOCK_LOST: /* fall-through */
64 case GSOCK_INPUT: c = 0; break;
65 case GSOCK_OUTPUT: c = 1; break;
66 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
67 default: return;
68 }
69
70 if (m_id[c] != -1)
71 wxAppRemoveSocketHandler(m_id[c]);
72
73 if (c == 0)
74 {
75 m_id[0] = wxAppAddSocketHandler(socket->m_fd, wxSockReadMask,
76 _GSocket_PM_Input, (void *)socket);
77 }
78 else
79 {
80 m_id[1] = wxAppAddSocketHandler(socket->m_fd, wxSockWriteMask,
81 _GSocket_PM_Output, (void *)socket);
82 }
83}
84
85void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
86{
87 int *m_id = (int *)(socket->m_gui_dependent);
88 int c;
89 switch (event)
90 {
91 case GSOCK_LOST: /* fall-through */
92 case GSOCK_INPUT: c = 0; break;
93 case GSOCK_OUTPUT: c = 1; break;
94 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
95 default: return;
96 }
97 if (m_id[c] != -1)
98 wxAppRemoveSocketHandler(m_id[c]);
99
100 m_id[c] = -1;
101}
102
103void _GSocket_Enable_Events(GSocket *socket)
104{
105 _GSocket_Install_Callback(socket, GSOCK_INPUT);
106 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
107}
108
109void _GSocket_Disable_Events(GSocket *socket)
110{
111 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
112 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
113}
114
115#else /* !wxUSE_SOCKETS */
116
117/* some compilers don't like having empty source files */
118static int wxDummyGsockVar = 0;
119
120#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */