]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gsocket.h
change superflous elif to else
[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 // needed since this class declares virtual members
104 virtual ~GSocketGUIFunctionsTable() { }
105 virtual bool OnInit() = 0;
106 virtual void OnExit() = 0;
107 virtual bool CanUseEventLoop() = 0;
108 virtual bool Init_Socket(GSocket *socket) = 0;
109 virtual void Destroy_Socket(GSocket *socket) = 0;
110 #ifndef __WINDOWS__
111 virtual void Install_Callback(GSocket *socket, GSocketEvent event) = 0;
112 virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event) = 0;
113 #endif
114 virtual void Enable_Events(GSocket *socket) = 0;
115 virtual void Disable_Events(GSocket *socket) = 0;
116 };
117
118
119 /* Global initializers */
120
121 /* Sets GUI functions callbacks. Must be called *before* GSocket_Init
122 if the app uses async sockets. */
123 void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable *guifunc);
124
125 /* GSocket_Init() must be called at the beginning */
126 int GSocket_Init(void);
127
128 /* GSocket_Cleanup() must be called at the end */
129 void GSocket_Cleanup(void);
130
131
132 /* Constructors / Destructors */
133
134 GSocket *GSocket_new(void);
135
136
137 /* GAddress */
138
139 GAddress *GAddress_new(void);
140 GAddress *GAddress_copy(GAddress *address);
141 void GAddress_destroy(GAddress *address);
142
143 void GAddress_SetFamily(GAddress *address, GAddressType type);
144 GAddressType GAddress_GetFamily(GAddress *address);
145
146 /* The use of any of the next functions will set the address family to
147 * the specific one. For example if you use GAddress_INET_SetHostName,
148 * address family will be implicitly set to AF_INET.
149 */
150
151 GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
152 GSocketError GAddress_INET_SetAnyAddress(GAddress *address);
153 GSocketError GAddress_INET_SetHostAddress(GAddress *address,
154 unsigned long hostaddr);
155 GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
156 const char *protocol);
157 GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
158
159 GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
160 size_t sbuf);
161 unsigned long GAddress_INET_GetHostAddress(GAddress *address);
162 unsigned short GAddress_INET_GetPort(GAddress *address);
163
164 /* TODO: Define specific parts (INET6, UNIX) */
165
166 GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path);
167 GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf);
168
169 #ifdef __cplusplus
170 }
171 #endif /* __cplusplus */
172
173 # if defined(__WINDOWS__)
174 # include "wx/msw/gsockmsw.h"
175 # elif defined(__WXMAC__) && !defined(__DARWIN__)
176 # include "wx/mac/gsockmac.h"
177 # else
178 # include "wx/unix/gsockunx.h"
179 # endif
180
181 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
182
183 #endif /* __GSOCKET_H */