]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/gsockpm.c
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 _GSocket_Detected_Read(socket
);
31 static void _GSocket_PM_Output(void *data
)
33 GSocket
*socket
= (GSocket
*) data
;
34 _GSocket_Detected_Write(socket
);
37 int _GSocket_GUI_Init(GSocket
*socket
)
40 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
41 m_id
= (int *)(socket
->m_gui_dependent
);
48 void _GSocket_GUI_Destroy(GSocket
*socket
)
50 free(socket
->m_gui_dependent
);
53 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
)
55 int *m_id
= (int *)(socket
->m_gui_dependent
);
58 if (socket
->m_fd
== -1)
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;
71 wxAppRemoveSocketHandler(m_id
[c
]);
75 m_id
[0] = wxAppAddSocketHandler(socket
->m_fd
, wxSockReadMask
,
76 _GSocket_PM_Input
, (void *)socket
);
80 m_id
[1] = wxAppAddSocketHandler(socket
->m_fd
, wxSockWriteMask
,
81 _GSocket_PM_Output
, (void *)socket
);
85 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
87 int *m_id
= (int *)(socket
->m_gui_dependent
);
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;
98 wxAppRemoveSocketHandler(m_id
[c
]);
103 void _GSocket_Enable_Events(GSocket
*socket
)
105 _GSocket_Install_Callback(socket
, GSOCK_INPUT
);
106 _GSocket_Install_Callback(socket
, GSOCK_OUTPUT
);
109 void _GSocket_Disable_Events(GSocket
*socket
)
111 _GSocket_Uninstall_Callback(socket
, GSOCK_INPUT
);
112 _GSocket_Uninstall_Callback(socket
, GSOCK_OUTPUT
);
115 #else /* !wxUSE_SOCKETS */
117 /* some compilers don't like having empty source files */
118 static int wxDummyGsockVar
= 0;
120 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */