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