]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gsocket.h
wxURL - doc cleanups, depreciated more methods, more source comments. wxURI - enclos...
[wxWidgets.git] / include / wx / gsocket.h
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket)
3 * Name: gsocket.h
4 * Author: Guilhem Lavaux
5 * Guillermo Rodriguez Garcia <guille@iies.es> (maintainer)
6 * Purpose: GSocket include file (system independent)
7 * CVSID: $Id$
8 * -------------------------------------------------------------------------
9 */
10
11 #ifndef __GSOCKET_H
12 #define __GSOCKET_H
13
14 #ifndef __GSOCKET_STANDALONE__
15 #include "wx/setup.h"
16 #include "wx/platform.h"
17
18 #include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
19
20 #endif
21
22 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
23
24 #include <stddef.h>
25
26 /*
27 Including sys/types.h under cygwin results in the warnings about "fd_set
28 having been defined in sys/types.h" when winsock.h is included later and
29 doesn't seem to be necessary anyhow. It's not needed under Mac neither.
30 */
31 #if !defined(__WXMAC__) && !defined(__CYGWIN__) && !defined(__WXWINCE__)
32 #include <sys/types.h>
33 #endif
34
35 #ifdef __WXWINCE__
36 #include <stdlib.h>
37 #endif
38
39 class GSocket;
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 typedef struct _GAddress GAddress;
46
47 typedef enum {
48 GSOCK_NOFAMILY = 0,
49 GSOCK_INET,
50 GSOCK_INET6,
51 GSOCK_UNIX
52 } GAddressType;
53
54 typedef enum {
55 GSOCK_STREAMED,
56 GSOCK_UNSTREAMED
57 } GSocketStream;
58
59 typedef enum {
60 GSOCK_NOERROR = 0,
61 GSOCK_INVOP,
62 GSOCK_IOERR,
63 GSOCK_INVADDR,
64 GSOCK_INVSOCK,
65 GSOCK_NOHOST,
66 GSOCK_INVPORT,
67 GSOCK_WOULDBLOCK,
68 GSOCK_TIMEDOUT,
69 GSOCK_MEMERR,
70 GSOCK_OPTERR
71 } GSocketError;
72
73 /* See below for an explanation on how events work.
74 */
75 typedef enum {
76 GSOCK_INPUT = 0,
77 GSOCK_OUTPUT = 1,
78 GSOCK_CONNECTION = 2,
79 GSOCK_LOST = 3,
80 GSOCK_MAX_EVENT = 4
81 } GSocketEvent;
82
83 enum {
84 GSOCK_INPUT_FLAG = 1 << GSOCK_INPUT,
85 GSOCK_OUTPUT_FLAG = 1 << GSOCK_OUTPUT,
86 GSOCK_CONNECTION_FLAG = 1 << GSOCK_CONNECTION,
87 GSOCK_LOST_FLAG = 1 << GSOCK_LOST
88 };
89
90 typedef int GSocketEventFlags;
91
92 typedef void (*GSocketCallback)(GSocket *socket, GSocketEvent event,
93 char *cdata);
94
95
96 /* Functions tables for internal use by GSocket code: */
97
98 /* Actually this is a misnomer now, but reusing this name means I don't
99 have to ifdef app traits or common socket code */
100 class GSocketGUIFunctionsTable
101 {
102 public:
103 virtual bool OnInit() = 0;
104 virtual void OnExit() = 0;
105 virtual bool CanUseEventLoop() = 0;
106 virtual bool Init_Socket(GSocket *socket) = 0;
107 virtual void Destroy_Socket(GSocket *socket) = 0;
108 #ifndef __WINDOWS__
109 virtual void Install_Callback(GSocket *socket, GSocketEvent event) = 0;
110 virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event) = 0;
111 #endif
112 virtual void Enable_Events(GSocket *socket) = 0;
113 virtual void Disable_Events(GSocket *socket) = 0;
114 };
115
116
117 /* Global initializers */
118
119 /* Sets GUI functions callbacks. Must be called *before* GSocket_Init
120 if the app uses async sockets. */
121 void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable *guifunc);
122
123 /* GSocket_Init() must be called at the beginning */
124 int GSocket_Init(void);
125
126 /* GSocket_Cleanup() must be called at the end */
127 void GSocket_Cleanup(void);
128
129
130 /* Constructors / Destructors */
131
132 GSocket *GSocket_new(void);
133
134
135 /* GAddress */
136
137 GAddress *GAddress_new(void);
138 GAddress *GAddress_copy(GAddress *address);
139 void GAddress_destroy(GAddress *address);
140
141 void GAddress_SetFamily(GAddress *address, GAddressType type);
142 GAddressType GAddress_GetFamily(GAddress *address);
143
144 /* The use of any of the next functions will set the address family to
145 * the specific one. For example if you use GAddress_INET_SetHostName,
146 * address family will be implicitly set to AF_INET.
147 */
148
149 GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
150 GSocketError GAddress_INET_SetAnyAddress(GAddress *address);
151 GSocketError GAddress_INET_SetHostAddress(GAddress *address,
152 unsigned long hostaddr);
153 GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
154 const char *protocol);
155 GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
156
157 GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
158 size_t sbuf);
159 unsigned long GAddress_INET_GetHostAddress(GAddress *address);
160 unsigned short GAddress_INET_GetPort(GAddress *address);
161
162 /* TODO: Define specific parts (INET6, UNIX) */
163
164 GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path);
165 GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf);
166
167 #ifdef __cplusplus
168 }
169 #endif /* __cplusplus */
170
171 # if defined(__WINDOWS__)
172 # include "wx/msw/gsockmsw.h"
173 # elif defined(__WXMAC__) && !defined(__DARWIN__)
174 # include "wx/mac/gsockmac.h"
175 # else
176 # include "wx/unix/gsockunx.h"
177 # endif
178
179 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
180
181 #endif /* __GSOCKET_H */