]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/gsockunx.h
Get rid of wxUSE_GSOCKET_CPLUSPLUS
[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 class GSocketGUIFunctionsTableConcrete: public GSocketGUIFunctionsTable
33 {
34 public:
35 virtual bool OnInit();
36 virtual void OnExit();
37 virtual bool CanUseEventLoop();
38 virtual bool Init_Socket(GSocket *socket);
39 virtual void Destroy_Socket(GSocket *socket);
40 virtual void Install_Callback(GSocket *socket, GSocketEvent event);
41 virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event);
42 virtual void Enable_Events(GSocket *socket);
43 virtual void Disable_Events(GSocket *socket);
44 };
45
46 class GSocket
47 {
48 public:
49 GSocket();
50 virtual ~GSocket();
51 bool IsOk() { return m_ok; }
52 void Close();
53 void Shutdown();
54 GSocketError SetLocal(GAddress *address);
55 GSocketError SetPeer(GAddress *address);
56 GAddress *GetLocal();
57 GAddress *GetPeer();
58 GSocketError SetServer();
59 GSocket *WaitConnection();
60 int SetReusable();
61 GSocketError Connect(GSocketStream stream);
62 GSocketError SetNonOriented();
63 int Read(char *buffer, int size);
64 int Write(const char *buffer, int size);
65 GSocketEventFlags Select(GSocketEventFlags flags);
66 void SetNonBlocking(int non_block);
67 void SetTimeout(unsigned long millisec);
68 GSocketError WXDLLIMPEXP_NET GetError();
69 void SetCallback(GSocketEventFlags flags,
70 GSocketCallback callback, char *cdata);
71 void UnsetCallback(GSocketEventFlags flags);
72 GSocketError GetSockOpt(int level, int optname, void *optval, int *optlen);
73 GSocketError SetSockOpt(int level, int optname,
74 const void *optval, int optlen);
75 /* API compatibility functions */
76 static void _GSocket_Detected_Read(GSocket *socket);
77 static void _GSocket_Detected_Write(GSocket *socket);
78 virtual void Detected_Read();
79 virtual void Detected_Write();
80 protected:
81 void Enable(GSocketEvent event);
82 void Disable(GSocketEvent event);
83 GSocketError Input_Timeout();
84 GSocketError Output_Timeout();
85 int Recv_Stream(char *buffer, int size);
86 int Recv_Dgram(char *buffer, int size);
87 int Send_Stream(const char *buffer, int size);
88 int Send_Dgram(const char *buffer, int size);
89 bool m_ok;
90 public:
91 /* DFE: We can't protect these data member until the GUI code is updated */
92 /* protected: */
93 int m_fd;
94 GAddress *m_local;
95 GAddress *m_peer;
96 GSocketError m_error;
97
98 int m_non_blocking;
99 int m_server;
100 int m_stream;
101 int m_establishing;
102 int m_reusable;
103 unsigned long m_timeout;
104
105 /* Callbacks */
106 GSocketEventFlags m_detected;
107 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
108 char *m_data[GSOCK_MAX_EVENT];
109
110 char *m_gui_dependent;
111
112 };
113
114 #ifdef __cplusplus
115 extern "C" {
116 #endif /* __cplusplus */
117 /* Definition of GAddress */
118 struct _GAddress
119 {
120 struct sockaddr *m_addr;
121 size_t m_len;
122
123 GAddressType m_family;
124 int m_realfamily;
125
126 GSocketError m_error;
127 };
128 #ifdef __cplusplus
129 }
130 #endif /* __cplusplus */
131
132 /* Compatibility methods to support old C API (from gsocket.h) */
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 int GSocket_SetReusable(GSocket *socket)
148 { return socket->SetReusable(); }
149 inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream)
150 { return socket->Connect(stream); }
151 inline GSocketError GSocket_SetNonOriented(GSocket *socket)
152 { return socket->SetNonOriented(); }
153 inline int GSocket_Read(GSocket *socket, char *buffer, int size)
154 { return socket->Read(buffer,size); }
155 inline int GSocket_Write(GSocket *socket, const char *buffer, int size)
156 { return socket->Write(buffer,size); }
157 inline GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
158 { return socket->Select(flags); }
159 inline void GSocket_SetNonBlocking(GSocket *socket, int non_block)
160 { socket->SetNonBlocking(non_block); }
161 inline void GSocket_SetTimeout(GSocket *socket, unsigned long millisec)
162 { socket->SetTimeout(millisec); }
163 inline GSocketError GSocket_GetError(GSocket *socket)
164 { return socket->GetError(); }
165 inline void GSocket_SetCallback(GSocket *socket, GSocketEventFlags flags,
166 GSocketCallback fallback, char *cdata)
167 { socket->SetCallback(flags,fallback,cdata); }
168 inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags)
169 { socket->UnsetCallback(flags); }
170 inline GSocketError GSocket_GetSockOpt(GSocket *socket, int level, int optname,
171 void *optval, int *optlen)
172 { return socket->GetSockOpt(level,optname,optval,optlen); }
173 inline GSocketError GSocket_SetSockOpt(GSocket *socket, int level, int optname,
174 const void *optval, int optlen)
175 { return socket->SetSockOpt(level,optname,optval,optlen); }
176 inline void GSocket_destroy(GSocket *socket)
177 { delete socket; }
178
179
180 #ifdef __cplusplus
181 extern "C" {
182 #endif /* __cplusplus */
183
184
185 /* GAddress */
186
187 GSocketError _GAddress_translate_from(GAddress *address,
188 struct sockaddr *addr, int len);
189 GSocketError _GAddress_translate_to (GAddress *address,
190 struct sockaddr **addr, int *len);
191 GSocketError _GAddress_Init_INET(GAddress *address);
192 GSocketError _GAddress_Init_UNIX(GAddress *address);
193
194
195 #ifdef __cplusplus
196 }
197 #endif /* __cplusplus */
198
199 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
200
201 #endif /* __GSOCK_UNX_H */