]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/gsockunx.h
c73a168d5b330b1b643833c1ca72340769445bc7
[wxWidgets.git] / include / wx / unix / gsockunx.h
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 GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable
34 {
35 public:
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();
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();
63 int SetReusable();
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);
71 GSocketError WXDLLIMPEXP_NET GetError();
72 void SetCallback(GSocketEventFlags flags,
73 GSocketCallback callback, char *cdata);
74 void UnsetCallback(GSocketEventFlags flags);
75 GSocketError GetSockOpt(int level, int optname, void *optval, int *optlen);
76 GSocketError SetSockOpt(int level, int optname,
77 const void *optval, int optlen);
78 /* API compatibility functions */
79 static void _GSocket_Detected_Read(GSocket *socket);
80 static void _GSocket_Detected_Write(GSocket *socket);
81 virtual void Detected_Read();
82 virtual void Detected_Write();
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);
92 bool m_ok;
93 public:
94 /* DFE: We can't protect these data member until the GUI code is updated */
95 /* protected: */
96 #else /* def wxUSE_GSOCKET_CPLUSPLUS */
97
98 #ifdef __cplusplus
99 extern "C" {
100 #endif /* __cplusplus */
101 /* Definition of GSocket */
102 struct _GSocket
103 {
104 #endif /* def wxUSE_GSOCKET_CPLUSPLUS */
105 int m_fd;
106 GAddress *m_local;
107 GAddress *m_peer;
108 GSocketError m_error;
109
110 int m_non_blocking;
111 int m_server;
112 int m_stream;
113 int m_establishing;
114 int m_reusable;
115 unsigned long m_timeout;
116
117 /* Callbacks */
118 GSocketEventFlags m_detected;
119 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
120 char *m_data[GSOCK_MAX_EVENT];
121
122 char *m_gui_dependent;
123
124 #ifndef wxUSE_GSOCKET_CPLUSPLUS
125 /* Function pointers */
126 struct GSocketBaseFunctionsTable *m_functions;
127 #endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
128 };
129 #ifndef wxUSE_GSOCKET_CPLUSPLUS
130 #ifdef __cplusplus
131 }
132 #endif /* __cplusplus */
133 #endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
134
135 #ifdef __cplusplus
136 extern "C" {
137 #endif /* __cplusplus */
138 /* Definition of GAddress */
139 struct _GAddress
140 {
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 };
149 #ifdef __cplusplus
150 }
151 #endif /* __cplusplus */
152
153 /* Compatibility methods to support old C API (from gsocket.h) */
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(); }
169 inline int GSocket_SetReusable(GSocket *socket)
170 { return socket->SetReusable(); }
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); }
185 inline GSocketError GSocket_GetError(GSocket *socket)
186 { return socket->GetError(); }
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); }
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); }
198 inline void GSocket_destroy(GSocket *socket)
199 { delete socket; }
200
201 #endif /* def wxUSE_GSOCKET_CPLUSPLUS */
202
203 #ifdef __cplusplus
204 extern "C" {
205 #endif /* __cplusplus */
206
207 /* Input / Output */
208
209 GSocketError _GSocket_Input_Timeout(GSocket *socket);
210 GSocketError _GSocket_Output_Timeout(GSocket *socket);
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);
215
216 /* Callbacks */
217
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);
223
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
229 void _GSocket_Enable(GSocket *socket, GSocketEvent event);
230 void _GSocket_Disable(GSocket *socket, GSocketEvent event);
231
232 #ifndef wxUSE_GSOCKET_CPLUSPLUS
233 void _GSocket_Detected_Read(GSocket *socket);
234 void _GSocket_Detected_Write(GSocket *socket);
235 #endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
236
237 /* GAddress */
238
239 GSocketError _GAddress_translate_from(GAddress *address,
240 struct sockaddr *addr, int len);
241 GSocketError _GAddress_translate_to (GAddress *address,
242 struct sockaddr **addr, int *len);
243 GSocketError _GAddress_Init_INET(GAddress *address);
244 GSocketError _GAddress_Init_UNIX(GAddress *address);
245
246
247 #ifdef __cplusplus
248 }
249 #endif /* __cplusplus */
250
251 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
252
253 #endif /* __GSOCK_UNX_H */