]>
Commit | Line | Data |
---|---|---|
dbd300df GL |
1 | /* ------------------------------------------------------------------------- |
2 | * Project: GSocket (Generic Socket) for WX | |
3 | * Name: gsockunx.h | |
4 | * Purpose: GSocket Unix header | |
5 | * CVSID: $Id$ | |
6 | * ------------------------------------------------------------------------- | |
7 | */ | |
483249fc | 8 | |
a324a7bc GL |
9 | #ifndef __GSOCK_UNX_H |
10 | #define __GSOCK_UNX_H | |
11 | ||
483249fc | 12 | #ifndef __GSOCKET_STANDALONE__ |
d422d01e | 13 | #include "wx/setup.h" |
483249fc | 14 | #endif |
d422d01e | 15 | |
483249fc | 16 | #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) |
d422d01e | 17 | |
483249fc | 18 | #ifndef __GSOCKET_STANDALONE__ |
d422d01e | 19 | #include "wx/gsocket.h" |
483249fc GRG |
20 | #else |
21 | #include "gsocket.h" | |
22 | #endif | |
23 | ||
5c9eff30 GRG |
24 | #ifndef TRUE |
25 | #define TRUE 1 | |
26 | #endif | |
27 | ||
28 | #ifndef FALSE | |
29 | #define FALSE 0 | |
30 | #endif | |
31 | ||
09e6e5ec | 32 | #ifdef wxUSE_GSOCKET_CPLUSPLUS |
ba2a81d7 | 33 | class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable |
09e6e5ec DE |
34 | { |
35 | public: | |
ba2a81d7 DE |
36 | virtual bool OnInit(); |
37 | virtual void OnExit(); | |
38 | virtual bool CanUseEventLoop(); | |
39 | virtual bool Init_Socket(GSocket *socket); | |
40 | virtual void Destroy_Socket(GSocket *socket); | |
41 | virtual void Install_Callback(GSocket *socket, GSocketEvent event); | |
42 | virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event); | |
43 | virtual void Enable_Events(GSocket *socket); | |
44 | virtual void Disable_Events(GSocket *socket); | |
45 | }; | |
46 | #endif /* def wxUSE_GSOCKET_CPLUSPLUS */ | |
47 | ||
48 | #ifdef wxUSE_GSOCKET_CPLUSPLUS | |
49 | class GSocket | |
50 | { | |
51 | public: | |
52 | GSocket(); | |
53 | virtual ~GSocket(); | |
09e6e5ec DE |
54 | bool IsOk() { return m_ok; } |
55 | void Close(); | |
56 | void Shutdown(); | |
57 | GSocketError SetLocal(GAddress *address); | |
58 | GSocketError SetPeer(GAddress *address); | |
59 | GAddress *GetLocal(); | |
60 | GAddress *GetPeer(); | |
61 | GSocketError SetServer(); | |
62 | GSocket *WaitConnection(); | |
b082b524 | 63 | int SetReusable(); |
09e6e5ec DE |
64 | GSocketError Connect(GSocketStream stream); |
65 | GSocketError SetNonOriented(); | |
66 | int Read(char *buffer, int size); | |
67 | int Write(const char *buffer, int size); | |
68 | GSocketEventFlags Select(GSocketEventFlags flags); | |
69 | void SetNonBlocking(int non_block); | |
70 | void SetTimeout(unsigned long millisec); | |
ba2a81d7 | 71 | GSocketError WXDLLIMPEXP_NET GetError(); |
09e6e5ec DE |
72 | void SetCallback(GSocketEventFlags flags, |
73 | GSocketCallback callback, char *cdata); | |
74 | void UnsetCallback(GSocketEventFlags flags); | |
b082b524 DE |
75 | GSocketError GetSockOpt(int level, int optname, void *optval, int *optlen); |
76 | GSocketError SetSockOpt(int level, int optname, | |
77 | const void *optval, int optlen); | |
09e6e5ec DE |
78 | /* API compatibility functions */ |
79 | static void _GSocket_Detected_Read(GSocket *socket); | |
80 | static void _GSocket_Detected_Write(GSocket *socket); | |
ba2a81d7 DE |
81 | virtual void Detected_Read(); |
82 | virtual void Detected_Write(); | |
09e6e5ec DE |
83 | protected: |
84 | void Enable(GSocketEvent event); | |
85 | void Disable(GSocketEvent event); | |
86 | GSocketError Input_Timeout(); | |
87 | GSocketError Output_Timeout(); | |
88 | int Recv_Stream(char *buffer, int size); | |
89 | int Recv_Dgram(char *buffer, int size); | |
90 | int Send_Stream(const char *buffer, int size); | |
91 | int Send_Dgram(const char *buffer, int size); | |
09e6e5ec DE |
92 | bool m_ok; |
93 | public: | |
b6db2e91 SN |
94 | /* DFE: We can't protect these data member until the GUI code is updated */ |
95 | /* protected: */ | |
96 | #else /* def wxUSE_GSOCKET_CPLUSPLUS */ | |
a324a7bc | 97 | |
09e6e5ec DE |
98 | #ifdef __cplusplus |
99 | extern "C" { | |
100 | #endif /* __cplusplus */ | |
a324a7bc | 101 | /* Definition of GSocket */ |
483249fc GRG |
102 | struct _GSocket |
103 | { | |
b6db2e91 | 104 | #endif /* def wxUSE_GSOCKET_CPLUSPLUS */ |
a324a7bc | 105 | int m_fd; |
483249fc GRG |
106 | GAddress *m_local; |
107 | GAddress *m_peer; | |
a324a7bc GL |
108 | GSocketError m_error; |
109 | ||
27a97d02 GRG |
110 | int m_non_blocking; |
111 | int m_server; | |
112 | int m_stream; | |
27a97d02 | 113 | int m_establishing; |
bb0926cc | 114 | int m_reusable; |
39b91eca | 115 | unsigned long m_timeout; |
a324a7bc | 116 | |
39b91eca | 117 | /* Callbacks */ |
483249fc | 118 | GSocketEventFlags m_detected; |
98781fa3 | 119 | GSocketCallback m_cbacks[GSOCK_MAX_EVENT]; |
a324a7bc GL |
120 | char *m_data[GSOCK_MAX_EVENT]; |
121 | ||
a324a7bc | 122 | char *m_gui_dependent; |
38bb138f | 123 | |
ba2a81d7 | 124 | #ifndef wxUSE_GSOCKET_CPLUSPLUS |
38bb138f VS |
125 | /* Function pointers */ |
126 | struct GSocketBaseFunctionsTable *m_functions; | |
ba2a81d7 | 127 | #endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */ |
a324a7bc | 128 | }; |
09e6e5ec DE |
129 | #ifndef wxUSE_GSOCKET_CPLUSPLUS |
130 | #ifdef __cplusplus | |
131 | } | |
132 | #endif /* __cplusplus */ | |
b6db2e91 | 133 | #endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */ |
a324a7bc | 134 | |
09e6e5ec DE |
135 | #ifdef __cplusplus |
136 | extern "C" { | |
137 | #endif /* __cplusplus */ | |
a324a7bc | 138 | /* Definition of GAddress */ |
483249fc GRG |
139 | struct _GAddress |
140 | { | |
a324a7bc GL |
141 | struct sockaddr *m_addr; |
142 | size_t m_len; | |
143 | ||
144 | GAddressType m_family; | |
145 | int m_realfamily; | |
146 | ||
147 | GSocketError m_error; | |
148 | }; | |
09e6e5ec DE |
149 | #ifdef __cplusplus |
150 | } | |
151 | #endif /* __cplusplus */ | |
152 | ||
b6db2e91 | 153 | /* Compatibility methods to support old C API (from gsocket.h) */ |
09e6e5ec DE |
154 | #ifdef wxUSE_GSOCKET_CPLUSPLUS |
155 | inline void GSocket_Shutdown(GSocket *socket) | |
156 | { socket->Shutdown(); } | |
157 | inline GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address) | |
158 | { return socket->SetLocal(address); } | |
159 | inline GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address) | |
160 | { return socket->SetPeer(address); } | |
161 | inline GAddress *GSocket_GetLocal(GSocket *socket) | |
162 | { return socket->GetLocal(); } | |
163 | inline GAddress *GSocket_GetPeer(GSocket *socket) | |
164 | { return socket->GetPeer(); } | |
165 | inline GSocketError GSocket_SetServer(GSocket *socket) | |
166 | { return socket->SetServer(); } | |
167 | inline GSocket *GSocket_WaitConnection(GSocket *socket) | |
168 | { return socket->WaitConnection(); } | |
b082b524 DE |
169 | inline int GSocket_SetReusable(GSocket *socket) |
170 | { return socket->SetReusable(); } | |
09e6e5ec DE |
171 | inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream) |
172 | { return socket->Connect(stream); } | |
173 | inline GSocketError GSocket_SetNonOriented(GSocket *socket) | |
174 | { return socket->SetNonOriented(); } | |
175 | inline int GSocket_Read(GSocket *socket, char *buffer, int size) | |
176 | { return socket->Read(buffer,size); } | |
177 | inline int GSocket_Write(GSocket *socket, const char *buffer, int size) | |
178 | { return socket->Write(buffer,size); } | |
179 | inline GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags) | |
180 | { return socket->Select(flags); } | |
181 | inline void GSocket_SetNonBlocking(GSocket *socket, int non_block) | |
182 | { socket->SetNonBlocking(non_block); } | |
183 | inline void GSocket_SetTimeout(GSocket *socket, unsigned long millisec) | |
184 | { socket->SetTimeout(millisec); } | |
ba2a81d7 DE |
185 | inline GSocketError GSocket_GetError(GSocket *socket) |
186 | { return socket->GetError(); } | |
09e6e5ec DE |
187 | inline void GSocket_SetCallback(GSocket *socket, GSocketEventFlags flags, |
188 | GSocketCallback fallback, char *cdata) | |
189 | { socket->SetCallback(flags,fallback,cdata); } | |
190 | inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags) | |
191 | { socket->UnsetCallback(flags); } | |
b082b524 DE |
192 | inline GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname, |
193 | void *optval, int *optlen) | |
194 | { return socket->GetSockOpt(level,optname,optval,optlen); } | |
195 | inline GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname, | |
196 | const void *optval, int optlen) | |
197 | { return socket->SetSockOpt(level,optname,optval,optlen); } | |
ba2a81d7 DE |
198 | inline void GSocket_destroy(GSocket *socket) |
199 | { delete socket; } | |
09e6e5ec | 200 | |
b6db2e91 | 201 | #endif /* def wxUSE_GSOCKET_CPLUSPLUS */ |
09e6e5ec DE |
202 | |
203 | #ifdef __cplusplus | |
204 | extern "C" { | |
205 | #endif /* __cplusplus */ | |
a324a7bc | 206 | |
483249fc GRG |
207 | /* Input / Output */ |
208 | ||
209 | GSocketError _GSocket_Input_Timeout(GSocket *socket); | |
210 | GSocketError _GSocket_Output_Timeout(GSocket *socket); | |
a324a7bc GL |
211 | int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size); |
212 | int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size); | |
213 | int _GSocket_Send_Stream(GSocket *socket, const char *buffer, int size); | |
214 | int _GSocket_Send_Dgram(GSocket *socket, const char *buffer, int size); | |
483249fc GRG |
215 | |
216 | /* Callbacks */ | |
217 | ||
38bb138f VS |
218 | int _GSocket_GUI_Init(void); |
219 | void _GSocket_GUI_Cleanup(void); | |
220 | ||
221 | int _GSocket_GUI_Init_Socket(GSocket *socket); | |
222 | void _GSocket_GUI_Destroy_Socket(GSocket *socket); | |
5ff86996 | 223 | |
483249fc GRG |
224 | void _GSocket_Enable_Events(GSocket *socket); |
225 | void _GSocket_Disable_Events(GSocket *socket); | |
226 | void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event); | |
227 | void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event); | |
228 | ||
5ff86996 GRG |
229 | void _GSocket_Enable(GSocket *socket, GSocketEvent event); |
230 | void _GSocket_Disable(GSocket *socket, GSocketEvent event); | |
09e6e5ec DE |
231 | |
232 | #ifndef wxUSE_GSOCKET_CPLUSPLUS | |
5ff86996 GRG |
233 | void _GSocket_Detected_Read(GSocket *socket); |
234 | void _GSocket_Detected_Write(GSocket *socket); | |
b6db2e91 | 235 | #endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */ |
5ff86996 | 236 | |
483249fc | 237 | /* GAddress */ |
e00f35bb | 238 | |
54e575f9 GL |
239 | GSocketError _GAddress_translate_from(GAddress *address, |
240 | struct sockaddr *addr, int len); | |
9bf10d6b GRG |
241 | GSocketError _GAddress_translate_to (GAddress *address, |
242 | struct sockaddr **addr, int *len); | |
54e575f9 | 243 | GSocketError _GAddress_Init_INET(GAddress *address); |
54e575f9 | 244 | GSocketError _GAddress_Init_UNIX(GAddress *address); |
a324a7bc | 245 | |
9bf10d6b | 246 | |
d422d01e RR |
247 | #ifdef __cplusplus |
248 | } | |
483249fc | 249 | #endif /* __cplusplus */ |
d422d01e | 250 | |
483249fc | 251 | #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */ |
d422d01e | 252 | |
483249fc | 253 | #endif /* __GSOCK_UNX_H */ |