]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/gsockunx.h
e5eefa2c4e11f6ce059910c59ebcba6c97eac210
[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 GSocketBSD
34 {
35 public:
36 GSocketBSD();
37 ~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 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);
61 protected:
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);
70 void Detected_Read();
71 void Detected_Write();
72 bool m_ok;
73 public:
74 //DFE: We can't protect these data member until the GUI code is updated
75 //protected:
76 #else //def wxUSE_GSOCKET_CPLUSPLUS
77
78 #ifdef __cplusplus
79 extern "C" {
80 #endif /* __cplusplus */
81 /* Definition of GSocket */
82 struct _GSocket
83 {
84 #endif //def wxUSE_GSOCKET_CPLUSPLUS
85 int m_fd;
86 GAddress *m_local;
87 GAddress *m_peer;
88 GSocketError m_error;
89
90 int m_non_blocking;
91 int m_server;
92 int m_stream;
93 int m_oriented;
94 int m_establishing;
95 unsigned long m_timeout;
96
97 /* Callbacks */
98 GSocketEventFlags m_detected;
99 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
100 char *m_data[GSOCK_MAX_EVENT];
101
102 char *m_gui_dependent;
103
104 /* Function pointers */
105 struct GSocketBaseFunctionsTable *m_functions;
106 };
107 #ifndef wxUSE_GSOCKET_CPLUSPLUS
108 #ifdef __cplusplus
109 }
110 #endif /* __cplusplus */
111 #endif //ndef wxUSE_GSOCKET_CPLUSPLUS
112
113 #ifdef __cplusplus
114 extern "C" {
115 #endif /* __cplusplus */
116 /* Definition of GAddress */
117 struct _GAddress
118 {
119 struct sockaddr *m_addr;
120 size_t m_len;
121
122 GAddressType m_family;
123 int m_realfamily;
124
125 GSocketError m_error;
126 };
127 #ifdef __cplusplus
128 }
129 #endif /* __cplusplus */
130
131 // Compatibility methods to support old C API (from gsocket.h)
132 #ifdef wxUSE_GSOCKET_CPLUSPLUS
133 inline void GSocket_Shutdown(GSocket *socket)
134 { socket->Shutdown(); }
135 inline GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address)
136 { return socket->SetLocal(address); }
137 inline GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address)
138 { return socket->SetPeer(address); }
139 inline GAddress *GSocket_GetLocal(GSocket *socket)
140 { return socket->GetLocal(); }
141 inline GAddress *GSocket_GetPeer(GSocket *socket)
142 { return socket->GetPeer(); }
143 inline GSocketError GSocket_SetServer(GSocket *socket)
144 { return socket->SetServer(); }
145 inline GSocket *GSocket_WaitConnection(GSocket *socket)
146 { return socket->WaitConnection(); }
147 inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream)
148 { return socket->Connect(stream); }
149 inline GSocketError GSocket_SetNonOriented(GSocket *socket)
150 { return socket->SetNonOriented(); }
151 inline int GSocket_Read(GSocket *socket, char *buffer, int size)
152 { return socket->Read(buffer,size); }
153 inline int GSocket_Write(GSocket *socket, const char *buffer, int size)
154 { return socket->Write(buffer,size); }
155 inline GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
156 { return socket->Select(flags); }
157 inline void GSocket_SetNonBlocking(GSocket *socket, int non_block)
158 { socket->SetNonBlocking(non_block); }
159 inline void GSocket_SetTimeout(GSocket *socket, unsigned long millisec)
160 { socket->SetTimeout(millisec); }
161 inline void GSocket_SetCallback(GSocket *socket, GSocketEventFlags flags,
162 GSocketCallback fallback, char *cdata)
163 { socket->SetCallback(flags,fallback,cdata); }
164 inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags)
165 { socket->UnsetCallback(flags); }
166
167 #endif //def wxUSE_GSOCKET_CPLUSPLUS
168
169 #ifdef __cplusplus
170 extern "C" {
171 #endif /* __cplusplus */
172
173 /* Input / Output */
174
175 GSocketError _GSocket_Input_Timeout(GSocket *socket);
176 GSocketError _GSocket_Output_Timeout(GSocket *socket);
177 int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size);
178 int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size);
179 int _GSocket_Send_Stream(GSocket *socket, const char *buffer, int size);
180 int _GSocket_Send_Dgram(GSocket *socket, const char *buffer, int size);
181
182 /* Callbacks */
183
184 int _GSocket_GUI_Init(void);
185 void _GSocket_GUI_Cleanup(void);
186
187 int _GSocket_GUI_Init_Socket(GSocket *socket);
188 void _GSocket_GUI_Destroy_Socket(GSocket *socket);
189
190 void _GSocket_Enable_Events(GSocket *socket);
191 void _GSocket_Disable_Events(GSocket *socket);
192 void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event);
193 void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event);
194
195 void _GSocket_Enable(GSocket *socket, GSocketEvent event);
196 void _GSocket_Disable(GSocket *socket, GSocketEvent event);
197
198 #ifndef wxUSE_GSOCKET_CPLUSPLUS
199 void _GSocket_Detected_Read(GSocket *socket);
200 void _GSocket_Detected_Write(GSocket *socket);
201 #endif //ndef wxUSE_GSOCKET_CPLUSPLUS
202
203 /* GAddress */
204
205 GSocketError _GAddress_translate_from(GAddress *address,
206 struct sockaddr *addr, int len);
207 GSocketError _GAddress_translate_to (GAddress *address,
208 struct sockaddr **addr, int *len);
209 GSocketError _GAddress_Init_INET(GAddress *address);
210 GSocketError _GAddress_Init_UNIX(GAddress *address);
211
212
213 #ifdef __cplusplus
214 }
215 #endif /* __cplusplus */
216
217 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
218
219 #endif /* __GSOCK_UNX_H */