1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket Unix header
6 * -------------------------------------------------------------------------
12 #ifndef __GSOCKET_STANDALONE__
16 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
18 #ifndef __GSOCKET_STANDALONE__
19 #include "wx/gsocket.h"
32 #ifdef wxUSE_GSOCKET_CPLUSPLUS
37 virtual ~GSocketBSD();
38 bool IsOk() { return m_ok
; }
41 GSocketError
SetLocal(GAddress
*address
);
42 GSocketError
SetPeer(GAddress
*address
);
45 GSocketError
SetServer();
46 GSocket
*WaitConnection();
47 GSocketError
Connect(GSocketStream stream
);
48 GSocketError
SetNonOriented();
49 int Read(char *buffer
, int size
);
50 int Write(const char *buffer
, int size
);
51 GSocketEventFlags
Select(GSocketEventFlags flags
);
52 void SetNonBlocking(int non_block
);
53 void SetTimeout(unsigned long millisec
);
54 GSocketError
GetError();
55 void SetCallback(GSocketEventFlags flags
,
56 GSocketCallback callback
, char *cdata
);
57 void UnsetCallback(GSocketEventFlags flags
);
58 /* API compatibility functions */
59 static void _GSocket_Detected_Read(GSocket
*socket
);
60 static void _GSocket_Detected_Write(GSocket
*socket
);
62 void Enable(GSocketEvent event
);
63 void Disable(GSocketEvent event
);
64 GSocketError
Input_Timeout();
65 GSocketError
Output_Timeout();
66 int Recv_Stream(char *buffer
, int size
);
67 int Recv_Dgram(char *buffer
, int size
);
68 int Send_Stream(const char *buffer
, int size
);
69 int Send_Dgram(const char *buffer
, int size
);
71 void Detected_Write();
73 virtual void EventLoop_Enable_Events() = 0;
74 virtual void EventLoop_Disable_Events() = 0;
75 virtual void EventLoop_Install_Callback(GSocketEvent event
) = 0;
76 virtual void EventLoop_Uninstall_Callback(GSocketEvent event
) = 0;
78 //DFE: We can't protect these data member until the GUI code is updated
80 #else //def wxUSE_GSOCKET_CPLUSPLUS
84 #endif /* __cplusplus */
85 /* Definition of GSocket */
88 #endif //def wxUSE_GSOCKET_CPLUSPLUS
99 unsigned long m_timeout
;
102 GSocketEventFlags m_detected
;
103 GSocketCallback m_cbacks
[GSOCK_MAX_EVENT
];
104 char *m_data
[GSOCK_MAX_EVENT
];
106 char *m_gui_dependent
;
108 /* Function pointers */
109 struct GSocketBaseFunctionsTable
*m_functions
;
111 #ifndef wxUSE_GSOCKET_CPLUSPLUS
114 #endif /* __cplusplus */
116 ///////////////////////////////////////////////////////////////////////////
118 class GSocketBSDGUIShim
:public GSocketBSD
120 friend void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable
*guifunc
);
122 static inline bool GUI_Init();
123 static inline void GUI_Cleanup();
124 static inline bool UseGUI();
126 virtual ~GSocketBSDGUIShim();
128 virtual void EventLoop_Enable_Events();
129 virtual void EventLoop_Disable_Events();
130 virtual void EventLoop_Install_Callback(GSocketEvent event
);
131 virtual void EventLoop_Uninstall_Callback(GSocketEvent event
);
133 /* Table of GUI-related functions. We must call them indirectly because
134 * of wxBase and GUI separation: */
136 static struct GSocketGUIFunctionsTable
*ms_gui_functions
;
139 #endif //ndef wxUSE_GSOCKET_CPLUSPLUS
143 #endif /* __cplusplus */
144 /* Definition of GAddress */
147 struct sockaddr
*m_addr
;
150 GAddressType m_family
;
153 GSocketError m_error
;
157 #endif /* __cplusplus */
159 // Compatibility methods to support old C API (from gsocket.h)
160 #ifdef wxUSE_GSOCKET_CPLUSPLUS
161 inline void GSocket_Shutdown(GSocket
*socket
)
162 { socket
->Shutdown(); }
163 inline GSocketError
GSocket_SetLocal(GSocket
*socket
, GAddress
*address
)
164 { return socket
->SetLocal(address
); }
165 inline GSocketError
GSocket_SetPeer(GSocket
*socket
, GAddress
*address
)
166 { return socket
->SetPeer(address
); }
167 inline GAddress
*GSocket_GetLocal(GSocket
*socket
)
168 { return socket
->GetLocal(); }
169 inline GAddress
*GSocket_GetPeer(GSocket
*socket
)
170 { return socket
->GetPeer(); }
171 inline GSocketError
GSocket_SetServer(GSocket
*socket
)
172 { return socket
->SetServer(); }
173 inline GSocket
*GSocket_WaitConnection(GSocket
*socket
)
174 { return socket
->WaitConnection(); }
175 inline GSocketError
GSocket_Connect(GSocket
*socket
, GSocketStream stream
)
176 { return socket
->Connect(stream
); }
177 inline GSocketError
GSocket_SetNonOriented(GSocket
*socket
)
178 { return socket
->SetNonOriented(); }
179 inline int GSocket_Read(GSocket
*socket
, char *buffer
, int size
)
180 { return socket
->Read(buffer
,size
); }
181 inline int GSocket_Write(GSocket
*socket
, const char *buffer
, int size
)
182 { return socket
->Write(buffer
,size
); }
183 inline GSocketEventFlags
GSocket_Select(GSocket
*socket
, GSocketEventFlags flags
)
184 { return socket
->Select(flags
); }
185 inline void GSocket_SetNonBlocking(GSocket
*socket
, int non_block
)
186 { socket
->SetNonBlocking(non_block
); }
187 inline void GSocket_SetTimeout(GSocket
*socket
, unsigned long millisec
)
188 { socket
->SetTimeout(millisec
); }
189 inline void GSocket_SetCallback(GSocket
*socket
, GSocketEventFlags flags
,
190 GSocketCallback fallback
, char *cdata
)
191 { socket
->SetCallback(flags
,fallback
,cdata
); }
192 inline void GSocket_UnsetCallback(GSocket
*socket
, GSocketEventFlags flags
)
193 { socket
->UnsetCallback(flags
); }
195 #endif //def wxUSE_GSOCKET_CPLUSPLUS
199 #endif /* __cplusplus */
203 GSocketError
_GSocket_Input_Timeout(GSocket
*socket
);
204 GSocketError
_GSocket_Output_Timeout(GSocket
*socket
);
205 int _GSocket_Recv_Stream(GSocket
*socket
, char *buffer
, int size
);
206 int _GSocket_Recv_Dgram(GSocket
*socket
, char *buffer
, int size
);
207 int _GSocket_Send_Stream(GSocket
*socket
, const char *buffer
, int size
);
208 int _GSocket_Send_Dgram(GSocket
*socket
, const char *buffer
, int size
);
212 int _GSocket_GUI_Init(void);
213 void _GSocket_GUI_Cleanup(void);
215 int _GSocket_GUI_Init_Socket(GSocket
*socket
);
216 void _GSocket_GUI_Destroy_Socket(GSocket
*socket
);
218 void _GSocket_Enable_Events(GSocket
*socket
);
219 void _GSocket_Disable_Events(GSocket
*socket
);
220 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
);
221 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
);
223 void _GSocket_Enable(GSocket
*socket
, GSocketEvent event
);
224 void _GSocket_Disable(GSocket
*socket
, GSocketEvent event
);
226 #ifndef wxUSE_GSOCKET_CPLUSPLUS
227 void _GSocket_Detected_Read(GSocket
*socket
);
228 void _GSocket_Detected_Write(GSocket
*socket
);
229 #endif //ndef wxUSE_GSOCKET_CPLUSPLUS
233 GSocketError
_GAddress_translate_from(GAddress
*address
,
234 struct sockaddr
*addr
, int len
);
235 GSocketError
_GAddress_translate_to (GAddress
*address
,
236 struct sockaddr
**addr
, int *len
);
237 GSocketError
_GAddress_Init_INET(GAddress
*address
);
238 GSocketError
_GAddress_Init_UNIX(GAddress
*address
);
243 #endif /* __cplusplus */
245 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
247 #endif /* __GSOCK_UNX_H */