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();
48 GSocketError
Connect(GSocketStream stream
);
49 GSocketError
SetNonOriented();
50 int Read(char *buffer
, int size
);
51 int Write(const char *buffer
, int size
);
52 GSocketEventFlags
Select(GSocketEventFlags flags
);
53 void SetNonBlocking(int non_block
);
54 void SetTimeout(unsigned long millisec
);
55 GSocketError
GetError();
56 void SetCallback(GSocketEventFlags flags
,
57 GSocketCallback callback
, char *cdata
);
58 void UnsetCallback(GSocketEventFlags flags
);
59 GSocketError
GetSockOpt(int level
, int optname
, void *optval
, int *optlen
);
60 GSocketError
SetSockOpt(int level
, int optname
,
61 const void *optval
, int optlen
);
62 /* API compatibility functions */
63 static void _GSocket_Detected_Read(GSocket
*socket
);
64 static void _GSocket_Detected_Write(GSocket
*socket
);
66 void Enable(GSocketEvent event
);
67 void Disable(GSocketEvent event
);
68 GSocketError
Input_Timeout();
69 GSocketError
Output_Timeout();
70 int Recv_Stream(char *buffer
, int size
);
71 int Recv_Dgram(char *buffer
, int size
);
72 int Send_Stream(const char *buffer
, int size
);
73 int Send_Dgram(const char *buffer
, int size
);
75 void Detected_Write();
77 virtual void EventLoop_Enable_Events() = 0;
78 virtual void EventLoop_Disable_Events() = 0;
79 virtual void EventLoop_Install_Callback(GSocketEvent event
) = 0;
80 virtual void EventLoop_Uninstall_Callback(GSocketEvent event
) = 0;
82 /* DFE: We can't protect these data member until the GUI code is updated */
84 #else /* def wxUSE_GSOCKET_CPLUSPLUS */
88 #endif /* __cplusplus */
89 /* Definition of GSocket */
92 #endif /* def wxUSE_GSOCKET_CPLUSPLUS */
103 unsigned long m_timeout
;
106 GSocketEventFlags m_detected
;
107 GSocketCallback m_cbacks
[GSOCK_MAX_EVENT
];
108 char *m_data
[GSOCK_MAX_EVENT
];
110 char *m_gui_dependent
;
112 /* Function pointers */
113 struct GSocketBaseFunctionsTable
*m_functions
;
115 #ifndef wxUSE_GSOCKET_CPLUSPLUS
118 #endif /* __cplusplus */
120 /**************************************************************************/
121 /* GSocketBSDGUIShim */
122 class GSocketBSDGUIShim
:public GSocketBSD
124 friend void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable
*guifunc
);
126 static inline bool GUI_Init();
127 static inline void GUI_Cleanup();
128 static inline bool UseGUI();
130 virtual ~GSocketBSDGUIShim();
132 virtual void EventLoop_Enable_Events();
133 virtual void EventLoop_Disable_Events();
134 virtual void EventLoop_Install_Callback(GSocketEvent event
);
135 virtual void EventLoop_Uninstall_Callback(GSocketEvent event
);
137 /* Table of GUI-related functions. We must call them indirectly because
138 * of wxBase and GUI separation: */
140 static struct GSocketGUIFunctionsTable
*ms_gui_functions
;
143 #endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
147 #endif /* __cplusplus */
148 /* Definition of GAddress */
151 struct sockaddr
*m_addr
;
154 GAddressType m_family
;
157 GSocketError m_error
;
161 #endif /* __cplusplus */
163 /* Compatibility methods to support old C API (from gsocket.h) */
164 #ifdef wxUSE_GSOCKET_CPLUSPLUS
165 inline void GSocket_Shutdown(GSocket
*socket
)
166 { socket
->Shutdown(); }
167 inline GSocketError
GSocket_SetLocal(GSocket
*socket
, GAddress
*address
)
168 { return socket
->SetLocal(address
); }
169 inline GSocketError
GSocket_SetPeer(GSocket
*socket
, GAddress
*address
)
170 { return socket
->SetPeer(address
); }
171 inline GAddress
*GSocket_GetLocal(GSocket
*socket
)
172 { return socket
->GetLocal(); }
173 inline GAddress
*GSocket_GetPeer(GSocket
*socket
)
174 { return socket
->GetPeer(); }
175 inline GSocketError
GSocket_SetServer(GSocket
*socket
)
176 { return socket
->SetServer(); }
177 inline GSocket
*GSocket_WaitConnection(GSocket
*socket
)
178 { return socket
->WaitConnection(); }
179 inline int GSocket_SetReusable(GSocket
*socket
)
180 { return socket
->SetReusable(); }
181 inline GSocketError
GSocket_Connect(GSocket
*socket
, GSocketStream stream
)
182 { return socket
->Connect(stream
); }
183 inline GSocketError
GSocket_SetNonOriented(GSocket
*socket
)
184 { return socket
->SetNonOriented(); }
185 inline int GSocket_Read(GSocket
*socket
, char *buffer
, int size
)
186 { return socket
->Read(buffer
,size
); }
187 inline int GSocket_Write(GSocket
*socket
, const char *buffer
, int size
)
188 { return socket
->Write(buffer
,size
); }
189 inline GSocketEventFlags
GSocket_Select(GSocket
*socket
, GSocketEventFlags flags
)
190 { return socket
->Select(flags
); }
191 inline void GSocket_SetNonBlocking(GSocket
*socket
, int non_block
)
192 { socket
->SetNonBlocking(non_block
); }
193 inline void GSocket_SetTimeout(GSocket
*socket
, unsigned long millisec
)
194 { socket
->SetTimeout(millisec
); }
195 inline void GSocket_SetCallback(GSocket
*socket
, GSocketEventFlags flags
,
196 GSocketCallback fallback
, char *cdata
)
197 { socket
->SetCallback(flags
,fallback
,cdata
); }
198 inline void GSocket_UnsetCallback(GSocket
*socket
, GSocketEventFlags flags
)
199 { socket
->UnsetCallback(flags
); }
200 inline GSocketError
GSocket_GetSockOpt(GSocket
*socket
, int level
, int optname
,
201 void *optval
, int *optlen
)
202 { return socket
->GetSockOpt(level
,optname
,optval
,optlen
); }
203 inline GSocketError
GSocket_SetSockOpt(GSocket
*socket
, int level
, int optname
,
204 const void *optval
, int optlen
)
205 { return socket
->SetSockOpt(level
,optname
,optval
,optlen
); }
207 #endif /* def wxUSE_GSOCKET_CPLUSPLUS */
211 #endif /* __cplusplus */
215 GSocketError
_GSocket_Input_Timeout(GSocket
*socket
);
216 GSocketError
_GSocket_Output_Timeout(GSocket
*socket
);
217 int _GSocket_Recv_Stream(GSocket
*socket
, char *buffer
, int size
);
218 int _GSocket_Recv_Dgram(GSocket
*socket
, char *buffer
, int size
);
219 int _GSocket_Send_Stream(GSocket
*socket
, const char *buffer
, int size
);
220 int _GSocket_Send_Dgram(GSocket
*socket
, const char *buffer
, int size
);
224 int _GSocket_GUI_Init(void);
225 void _GSocket_GUI_Cleanup(void);
227 int _GSocket_GUI_Init_Socket(GSocket
*socket
);
228 void _GSocket_GUI_Destroy_Socket(GSocket
*socket
);
230 void _GSocket_Enable_Events(GSocket
*socket
);
231 void _GSocket_Disable_Events(GSocket
*socket
);
232 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
);
233 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
);
235 void _GSocket_Enable(GSocket
*socket
, GSocketEvent event
);
236 void _GSocket_Disable(GSocket
*socket
, GSocketEvent event
);
238 #ifndef wxUSE_GSOCKET_CPLUSPLUS
239 void _GSocket_Detected_Read(GSocket
*socket
);
240 void _GSocket_Detected_Write(GSocket
*socket
);
241 #endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
245 GSocketError
_GAddress_translate_from(GAddress
*address
,
246 struct sockaddr
*addr
, int len
);
247 GSocketError
_GAddress_translate_to (GAddress
*address
,
248 struct sockaddr
**addr
, int *len
);
249 GSocketError
_GAddress_Init_INET(GAddress
*address
);
250 GSocketError
_GAddress_Init_UNIX(GAddress
*address
);
255 #endif /* __cplusplus */
257 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
259 #endif /* __GSOCK_UNX_H */