]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/gsockunx.h
fixed typo
[wxWidgets.git] / include / wx / unix / gsockunx.h
CommitLineData
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 33class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable
09e6e5ec
DE
34{
35public:
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
49class GSocket
50{
51public:
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
83protected:
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;
93public:
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
99extern "C" {
100#endif /* __cplusplus */
a324a7bc 101/* Definition of GSocket */
483249fc
GRG
102struct _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
136extern "C" {
137#endif /* __cplusplus */
a324a7bc 138/* Definition of GAddress */
483249fc
GRG
139struct _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
155inline void GSocket_Shutdown(GSocket *socket)
156{ socket->Shutdown(); }
157inline GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address)
158{ return socket->SetLocal(address); }
159inline GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address)
160{ return socket->SetPeer(address); }
161inline GAddress *GSocket_GetLocal(GSocket *socket)
162{ return socket->GetLocal(); }
163inline GAddress *GSocket_GetPeer(GSocket *socket)
164{ return socket->GetPeer(); }
165inline GSocketError GSocket_SetServer(GSocket *socket)
166{ return socket->SetServer(); }
167inline GSocket *GSocket_WaitConnection(GSocket *socket)
168{ return socket->WaitConnection(); }
b082b524
DE
169inline int GSocket_SetReusable(GSocket *socket)
170{ return socket->SetReusable(); }
09e6e5ec
DE
171inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream)
172{ return socket->Connect(stream); }
173inline GSocketError GSocket_SetNonOriented(GSocket *socket)
174{ return socket->SetNonOriented(); }
175inline int GSocket_Read(GSocket *socket, char *buffer, int size)
176{ return socket->Read(buffer,size); }
177inline int GSocket_Write(GSocket *socket, const char *buffer, int size)
178{ return socket->Write(buffer,size); }
179inline GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
180{ return socket->Select(flags); }
181inline void GSocket_SetNonBlocking(GSocket *socket, int non_block)
182{ socket->SetNonBlocking(non_block); }
183inline void GSocket_SetTimeout(GSocket *socket, unsigned long millisec)
184{ socket->SetTimeout(millisec); }
ba2a81d7
DE
185inline GSocketError GSocket_GetError(GSocket *socket)
186{ return socket->GetError(); }
09e6e5ec
DE
187inline void GSocket_SetCallback(GSocket *socket, GSocketEventFlags flags,
188 GSocketCallback fallback, char *cdata)
189{ socket->SetCallback(flags,fallback,cdata); }
190inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags)
191{ socket->UnsetCallback(flags); }
b082b524
DE
192inline GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname,
193 void *optval, int *optlen)
194{ return socket->GetSockOpt(level,optname,optval,optlen); }
195inline 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
198inline void GSocket_destroy(GSocket *socket)
199{ delete socket; }
09e6e5ec 200
b6db2e91 201#endif /* def wxUSE_GSOCKET_CPLUSPLUS */
09e6e5ec
DE
202
203#ifdef __cplusplus
204extern "C" {
205#endif /* __cplusplus */
a324a7bc 206
483249fc
GRG
207/* Input / Output */
208
209GSocketError _GSocket_Input_Timeout(GSocket *socket);
210GSocketError _GSocket_Output_Timeout(GSocket *socket);
a324a7bc
GL
211int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size);
212int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size);
213int _GSocket_Send_Stream(GSocket *socket, const char *buffer, int size);
214int _GSocket_Send_Dgram(GSocket *socket, const char *buffer, int size);
483249fc
GRG
215
216/* Callbacks */
217
38bb138f
VS
218int _GSocket_GUI_Init(void);
219void _GSocket_GUI_Cleanup(void);
220
221int _GSocket_GUI_Init_Socket(GSocket *socket);
222void _GSocket_GUI_Destroy_Socket(GSocket *socket);
5ff86996 223
483249fc
GRG
224void _GSocket_Enable_Events(GSocket *socket);
225void _GSocket_Disable_Events(GSocket *socket);
226void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event);
227void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event);
228
5ff86996
GRG
229void _GSocket_Enable(GSocket *socket, GSocketEvent event);
230void _GSocket_Disable(GSocket *socket, GSocketEvent event);
09e6e5ec
DE
231
232#ifndef wxUSE_GSOCKET_CPLUSPLUS
5ff86996
GRG
233void _GSocket_Detected_Read(GSocket *socket);
234void _GSocket_Detected_Write(GSocket *socket);
b6db2e91 235#endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
5ff86996 236
483249fc 237/* GAddress */
e00f35bb 238
54e575f9
GL
239GSocketError _GAddress_translate_from(GAddress *address,
240 struct sockaddr *addr, int len);
9bf10d6b
GRG
241GSocketError _GAddress_translate_to (GAddress *address,
242 struct sockaddr **addr, int *len);
54e575f9 243GSocketError _GAddress_Init_INET(GAddress *address);
54e575f9 244GSocketError _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 */