]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/gsockunx.h
region from polygon added
[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
DE
32#ifdef wxUSE_GSOCKET_CPLUSPLUS
33class GSocketBSD
34{
35public:
36 GSocketBSD();
444cb1fd 37 virtual ~GSocketBSD();
09e6e5ec
DE
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();
b082b524 47 int SetReusable();
09e6e5ec
DE
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);
b082b524
DE
59 GSocketError GetSockOpt(int level, int optname, void *optval, int *optlen);
60 GSocketError SetSockOpt(int level, int optname,
61 const void *optval, int optlen);
09e6e5ec
DE
62 /* API compatibility functions */
63 static void _GSocket_Detected_Read(GSocket *socket);
64 static void _GSocket_Detected_Write(GSocket *socket);
65protected:
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;
444cb1fd
DE
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;
09e6e5ec 81public:
b6db2e91
SN
82 /* DFE: We can't protect these data member until the GUI code is updated */
83 /* protected: */
84#else /* def wxUSE_GSOCKET_CPLUSPLUS */
a324a7bc 85
09e6e5ec
DE
86#ifdef __cplusplus
87extern "C" {
88#endif /* __cplusplus */
a324a7bc 89/* Definition of GSocket */
483249fc
GRG
90struct _GSocket
91{
b6db2e91 92#endif /* def wxUSE_GSOCKET_CPLUSPLUS */
a324a7bc 93 int m_fd;
483249fc
GRG
94 GAddress *m_local;
95 GAddress *m_peer;
a324a7bc
GL
96 GSocketError m_error;
97
27a97d02
GRG
98 int m_non_blocking;
99 int m_server;
100 int m_stream;
27a97d02 101 int m_establishing;
bb0926cc 102 int m_reusable;
39b91eca 103 unsigned long m_timeout;
a324a7bc 104
39b91eca 105 /* Callbacks */
483249fc 106 GSocketEventFlags m_detected;
98781fa3 107 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
a324a7bc
GL
108 char *m_data[GSOCK_MAX_EVENT];
109
a324a7bc 110 char *m_gui_dependent;
38bb138f
VS
111
112 /* Function pointers */
113 struct GSocketBaseFunctionsTable *m_functions;
a324a7bc 114};
09e6e5ec
DE
115#ifndef wxUSE_GSOCKET_CPLUSPLUS
116#ifdef __cplusplus
117}
118#endif /* __cplusplus */
1119a830 119#else
b6db2e91
SN
120/**************************************************************************/
121/* GSocketBSDGUIShim */
1119a830
DE
122class GSocketBSDGUIShim:public GSocketBSD
123{
124 friend void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable *guifunc);
125public:
126 static inline bool GUI_Init();
127 static inline void GUI_Cleanup();
128 static inline bool UseGUI();
129 GSocketBSDGUIShim();
130 virtual ~GSocketBSDGUIShim();
131protected:
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);
136private:
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
b6db2e91 143#endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
a324a7bc 144
09e6e5ec
DE
145#ifdef __cplusplus
146extern "C" {
147#endif /* __cplusplus */
a324a7bc 148/* Definition of GAddress */
483249fc
GRG
149struct _GAddress
150{
a324a7bc
GL
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};
09e6e5ec
DE
159#ifdef __cplusplus
160}
161#endif /* __cplusplus */
162
b6db2e91 163/* Compatibility methods to support old C API (from gsocket.h) */
09e6e5ec
DE
164#ifdef wxUSE_GSOCKET_CPLUSPLUS
165inline void GSocket_Shutdown(GSocket *socket)
166{ socket->Shutdown(); }
167inline GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address)
168{ return socket->SetLocal(address); }
169inline GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address)
170{ return socket->SetPeer(address); }
171inline GAddress *GSocket_GetLocal(GSocket *socket)
172{ return socket->GetLocal(); }
173inline GAddress *GSocket_GetPeer(GSocket *socket)
174{ return socket->GetPeer(); }
175inline GSocketError GSocket_SetServer(GSocket *socket)
176{ return socket->SetServer(); }
177inline GSocket *GSocket_WaitConnection(GSocket *socket)
178{ return socket->WaitConnection(); }
b082b524
DE
179inline int GSocket_SetReusable(GSocket *socket)
180{ return socket->SetReusable(); }
09e6e5ec
DE
181inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream)
182{ return socket->Connect(stream); }
183inline GSocketError GSocket_SetNonOriented(GSocket *socket)
184{ return socket->SetNonOriented(); }
185inline int GSocket_Read(GSocket *socket, char *buffer, int size)
186{ return socket->Read(buffer,size); }
187inline int GSocket_Write(GSocket *socket, const char *buffer, int size)
188{ return socket->Write(buffer,size); }
189inline GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
190{ return socket->Select(flags); }
191inline void GSocket_SetNonBlocking(GSocket *socket, int non_block)
192{ socket->SetNonBlocking(non_block); }
193inline void GSocket_SetTimeout(GSocket *socket, unsigned long millisec)
194{ socket->SetTimeout(millisec); }
195inline void GSocket_SetCallback(GSocket *socket, GSocketEventFlags flags,
196 GSocketCallback fallback, char *cdata)
197{ socket->SetCallback(flags,fallback,cdata); }
198inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags)
199{ socket->UnsetCallback(flags); }
b082b524
DE
200inline GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname,
201 void *optval, int *optlen)
202{ return socket->GetSockOpt(level,optname,optval,optlen); }
203inline GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname,
204 const void *optval, int optlen)
205{ return socket->SetSockOpt(level,optname,optval,optlen); }
09e6e5ec 206
b6db2e91 207#endif /* def wxUSE_GSOCKET_CPLUSPLUS */
09e6e5ec
DE
208
209#ifdef __cplusplus
210extern "C" {
211#endif /* __cplusplus */
a324a7bc 212
483249fc
GRG
213/* Input / Output */
214
215GSocketError _GSocket_Input_Timeout(GSocket *socket);
216GSocketError _GSocket_Output_Timeout(GSocket *socket);
a324a7bc
GL
217int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size);
218int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size);
219int _GSocket_Send_Stream(GSocket *socket, const char *buffer, int size);
220int _GSocket_Send_Dgram(GSocket *socket, const char *buffer, int size);
483249fc
GRG
221
222/* Callbacks */
223
38bb138f
VS
224int _GSocket_GUI_Init(void);
225void _GSocket_GUI_Cleanup(void);
226
227int _GSocket_GUI_Init_Socket(GSocket *socket);
228void _GSocket_GUI_Destroy_Socket(GSocket *socket);
5ff86996 229
483249fc
GRG
230void _GSocket_Enable_Events(GSocket *socket);
231void _GSocket_Disable_Events(GSocket *socket);
232void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event);
233void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event);
234
5ff86996
GRG
235void _GSocket_Enable(GSocket *socket, GSocketEvent event);
236void _GSocket_Disable(GSocket *socket, GSocketEvent event);
09e6e5ec
DE
237
238#ifndef wxUSE_GSOCKET_CPLUSPLUS
5ff86996
GRG
239void _GSocket_Detected_Read(GSocket *socket);
240void _GSocket_Detected_Write(GSocket *socket);
b6db2e91 241#endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
5ff86996 242
483249fc 243/* GAddress */
e00f35bb 244
54e575f9
GL
245GSocketError _GAddress_translate_from(GAddress *address,
246 struct sockaddr *addr, int len);
9bf10d6b
GRG
247GSocketError _GAddress_translate_to (GAddress *address,
248 struct sockaddr **addr, int *len);
54e575f9 249GSocketError _GAddress_Init_INET(GAddress *address);
54e575f9 250GSocketError _GAddress_Init_UNIX(GAddress *address);
a324a7bc 251
9bf10d6b 252
d422d01e
RR
253#ifdef __cplusplus
254}
483249fc 255#endif /* __cplusplus */
d422d01e 256
483249fc 257#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
d422d01e 258
483249fc 259#endif /* __GSOCK_UNX_H */