]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/gsockpm.c
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket: PM part
6 * ------------------------------------------------------------------------- */
13 #include "wx/unix/gsockunx.h"
14 #include "wx/gsocket.h"
16 extern int wxAppAddSocketHandler(int handle
, int mask
,
17 void (*callback
)(void*), void * gsock
);
19 extern void wxAppRemoveSocketHandler(int handle
);
21 #define wxSockReadMask 0x01
22 #define wxSockWriteMask 0x02
24 static void _GSocket_PM_Input(void *data
)
26 GSocket
*socket
= (GSocket
*) data
;
27 _GSocket_Detected_Read(socket
);
30 static void _GSocket_PM_Output(void *data
)
32 GSocket
*socket
= (GSocket
*) data
;
33 _GSocket_Detected_Write(socket
);
36 int _GSocket_GUI_Init(GSocket
*socket
)
39 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
40 m_id
= (int *)(socket
->m_gui_dependent
);
47 void _GSocket_GUI_Destroy(GSocket
*socket
)
49 free(socket
->m_gui_dependent
);
52 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
)
54 int *m_id
= (int *)(socket
->m_gui_dependent
);
57 if (socket
->m_fd
== -1)
62 case GSOCK_LOST
: /* fall-through */
63 case GSOCK_INPUT
: c
= 0; break;
64 case GSOCK_OUTPUT
: c
= 1; break;
65 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
70 wxAppRemoveSocketHandler(m_id
[c
]);
74 m_id
[0] = wxAppAddSocketHandler(socket
->m_fd
, wxSockReadMask
,
75 _GSocket_PM_Input
, (void *)socket
);
79 m_id
[1] = wxAppAddSocketHandler(socket
->m_fd
, wxSockWriteMask
,
80 _GSocket_PM_Output
, (void *)socket
);
84 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
86 int *m_id
= (int *)(socket
->m_gui_dependent
);
90 case GSOCK_LOST
: /* fall-through */
91 case GSOCK_INPUT
: c
= 0; break;
92 case GSOCK_OUTPUT
: c
= 1; break;
93 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
97 wxAppRemoveSocketHandler(m_id
[c
]);
102 void _GSocket_Enable_Events(GSocket
*socket
)
104 _GSocket_Install_Callback(socket
, GSOCK_INPUT
);
105 _GSocket_Install_Callback(socket
, GSOCK_OUTPUT
);
108 void _GSocket_Disable_Events(GSocket
*socket
)
110 _GSocket_Uninstall_Callback(socket
, GSOCK_INPUT
);
111 _GSocket_Uninstall_Callback(socket
, GSOCK_OUTPUT
);
114 #else /* !wxUSE_SOCKETS */
116 /* some compilers don't like having empty source files */
117 static int wxDummyGsockVar
= 0;
119 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */