]> git.saurik.com Git - wxWidgets.git/blob - src/os2/gsockpm.cpp
Blind fix for bug #1209944, wxFileConfig constructor corrupts the stack
[wxWidgets.git] / src / os2 / gsockpm.cpp
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockpm.c
4 * Purpose: GSocket: PM part
5 * Licence: The wxWindows licence
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 #include "wx/app.h"
17
18 #define wxSockReadMask 0x01
19 #define wxSockWriteMask 0x02
20
21 static void _GSocket_PM_Input(void *data)
22 {
23 GSocket *socket = (GSocket *) data;
24 socket->Detected_Read();
25 }
26
27 static void _GSocket_PM_Output(void *data)
28 {
29 GSocket *socket = (GSocket *) data;
30 socket->Detected_Write();
31 }
32
33 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
34 { return true; }
35
36 bool GSocketGUIFunctionsTableConcrete::OnInit(void)
37 {
38 return 1;
39 }
40
41 void GSocketGUIFunctionsTableConcrete::OnExit(void)
42 {
43 }
44
45 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
46 {
47 int *m_id;
48 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
49 m_id = (int *)(socket->m_gui_dependent);
50
51 m_id[0] = -1;
52 m_id[1] = -1;
53 return true;
54 }
55
56 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
57 {
58 free(socket->m_gui_dependent);
59 }
60
61 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
62 {
63 int *m_id = (int *)(socket->m_gui_dependent);
64 int c;
65
66 if (socket->m_fd == -1)
67 return;
68
69 switch (event)
70 {
71 case GSOCK_LOST: /* fall-through */
72 case GSOCK_INPUT: c = 0; break;
73 case GSOCK_OUTPUT: c = 1; break;
74 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
75 default: return;
76 }
77
78 if (m_id[c] != -1)
79 wxTheApp->RemoveSocketHandler(m_id[c]);
80
81 if (c == 0)
82 {
83 m_id[0] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockReadMask,
84 _GSocket_PM_Input, (void *)socket);
85 }
86 else
87 {
88 m_id[1] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockWriteMask,
89 _GSocket_PM_Output, (void *)socket);
90 }
91 }
92
93 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
94 {
95 int *m_id = (int *)(socket->m_gui_dependent);
96 int c;
97 switch (event)
98 {
99 case GSOCK_LOST: /* fall-through */
100 case GSOCK_INPUT: c = 0; break;
101 case GSOCK_OUTPUT: c = 1; break;
102 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
103 default: return;
104 }
105 if (m_id[c] != -1)
106 wxTheApp->RemoveSocketHandler(m_id[c]);
107
108 m_id[c] = -1;
109 }
110
111 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
112 {
113 Install_Callback(socket, GSOCK_INPUT);
114 Install_Callback(socket, GSOCK_OUTPUT);
115 }
116
117 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
118 {
119 Uninstall_Callback(socket, GSOCK_INPUT);
120 Uninstall_Callback(socket, GSOCK_OUTPUT);
121 }
122
123 #else /* !wxUSE_SOCKETS */
124
125 /* some compilers don't like having empty source files */
126 static int wxDummyGsockVar = 0;
127
128 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */