]>
Commit | Line | Data |
---|---|---|
1 | /* ------------------------------------------------------------------------- | |
2 | * Project: GSocket (Generic Socket) for WX | |
3 | * Name: gsockunx.h | |
4 | * Purpose: GSocket Unix header | |
5 | * CVSID: $Id$ | |
6 | * ------------------------------------------------------------------------- | |
7 | */ | |
8 | ||
9 | #ifndef __GSOCK_UNX_H | |
10 | #define __GSOCK_UNX_H | |
11 | ||
12 | #ifndef __GSOCKET_STANDALONE__ | |
13 | #include "wx/setup.h" | |
14 | #endif | |
15 | ||
16 | #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) | |
17 | ||
18 | #ifndef __GSOCKET_STANDALONE__ | |
19 | #include "wx/gsocket.h" | |
20 | #else | |
21 | #include "gsocket.h" | |
22 | #endif | |
23 | ||
24 | #ifndef TRUE | |
25 | #define TRUE 1 | |
26 | #endif | |
27 | ||
28 | #ifndef FALSE | |
29 | #define FALSE 0 | |
30 | #endif | |
31 | ||
32 | #ifdef wxUSE_GSOCKET_CPLUSPLUS | |
33 | class GSocketBSD | |
34 | { | |
35 | public: | |
36 | GSocketBSD(); | |
37 | virtual ~GSocketBSD(); | |
38 | bool IsOk() { return m_ok; } | |
39 | void Close(); | |
40 | void Shutdown(); | |
41 | GSocketError SetLocal(GAddress *address); | |
42 | GSocketError SetPeer(GAddress *address); | |
43 | GAddress *GetLocal(); | |
44 | GAddress *GetPeer(); | |
45 | GSocketError SetServer(); | |
46 | GSocket *WaitConnection(); | |
47 | int SetReusable(); | |
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); | |
65 | protected: | |
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); | |
74 | void Detected_Read(); | |
75 | void Detected_Write(); | |
76 | bool m_ok; | |
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; | |
81 | public: | |
82 | /* DFE: We can't protect these data member until the GUI code is updated */ | |
83 | /* protected: */ | |
84 | #else /* def wxUSE_GSOCKET_CPLUSPLUS */ | |
85 | ||
86 | #ifdef __cplusplus | |
87 | extern "C" { | |
88 | #endif /* __cplusplus */ | |
89 | /* Definition of GSocket */ | |
90 | struct _GSocket | |
91 | { | |
92 | #endif /* def wxUSE_GSOCKET_CPLUSPLUS */ | |
93 | int m_fd; | |
94 | GAddress *m_local; | |
95 | GAddress *m_peer; | |
96 | GSocketError m_error; | |
97 | ||
98 | int m_non_blocking; | |
99 | int m_server; | |
100 | int m_stream; | |
101 | int m_establishing; | |
102 | int m_reusable; | |
103 | unsigned long m_timeout; | |
104 | ||
105 | /* Callbacks */ | |
106 | GSocketEventFlags m_detected; | |
107 | GSocketCallback m_cbacks[GSOCK_MAX_EVENT]; | |
108 | char *m_data[GSOCK_MAX_EVENT]; | |
109 | ||
110 | char *m_gui_dependent; | |
111 | ||
112 | /* Function pointers */ | |
113 | struct GSocketBaseFunctionsTable *m_functions; | |
114 | }; | |
115 | #ifndef wxUSE_GSOCKET_CPLUSPLUS | |
116 | #ifdef __cplusplus | |
117 | } | |
118 | #endif /* __cplusplus */ | |
119 | #else | |
120 | /**************************************************************************/ | |
121 | /* GSocketBSDGUIShim */ | |
122 | class GSocketBSDGUIShim:public GSocketBSD | |
123 | { | |
124 | friend void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable *guifunc); | |
125 | public: | |
126 | static inline bool GUI_Init(); | |
127 | static inline void GUI_Cleanup(); | |
128 | static inline bool UseGUI(); | |
129 | GSocketBSDGUIShim(); | |
130 | virtual ~GSocketBSDGUIShim(); | |
131 | protected: | |
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); | |
136 | private: | |
137 | /* Table of GUI-related functions. We must call them indirectly because | |
138 | * of wxBase and GUI separation: */ | |
139 | ||
140 | static struct GSocketGUIFunctionsTable *ms_gui_functions; | |
141 | }; | |
142 | ||
143 | #endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */ | |
144 | ||
145 | #ifdef __cplusplus | |
146 | extern "C" { | |
147 | #endif /* __cplusplus */ | |
148 | /* Definition of GAddress */ | |
149 | struct _GAddress | |
150 | { | |
151 | struct sockaddr *m_addr; | |
152 | size_t m_len; | |
153 | ||
154 | GAddressType m_family; | |
155 | int m_realfamily; | |
156 | ||
157 | GSocketError m_error; | |
158 | }; | |
159 | #ifdef __cplusplus | |
160 | } | |
161 | #endif /* __cplusplus */ | |
162 | ||
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); } | |
206 | ||
207 | #endif /* def wxUSE_GSOCKET_CPLUSPLUS */ | |
208 | ||
209 | #ifdef __cplusplus | |
210 | extern "C" { | |
211 | #endif /* __cplusplus */ | |
212 | ||
213 | /* Input / Output */ | |
214 | ||
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); | |
221 | ||
222 | /* Callbacks */ | |
223 | ||
224 | int _GSocket_GUI_Init(void); | |
225 | void _GSocket_GUI_Cleanup(void); | |
226 | ||
227 | int _GSocket_GUI_Init_Socket(GSocket *socket); | |
228 | void _GSocket_GUI_Destroy_Socket(GSocket *socket); | |
229 | ||
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); | |
234 | ||
235 | void _GSocket_Enable(GSocket *socket, GSocketEvent event); | |
236 | void _GSocket_Disable(GSocket *socket, GSocketEvent event); | |
237 | ||
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 */ | |
242 | ||
243 | /* GAddress */ | |
244 | ||
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); | |
251 | ||
252 | ||
253 | #ifdef __cplusplus | |
254 | } | |
255 | #endif /* __cplusplus */ | |
256 | ||
257 | #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */ | |
258 | ||
259 | #endif /* __GSOCK_UNX_H */ |