]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gsocket.h
Added WINE and probably x-compile makefiles
[wxWidgets.git] / include / wx / gsocket.h
CommitLineData
a324a7bc
GL
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket)
3 * Name: gsocket.h
4 * Purpose: GSocket include file (system independent)
5 * CVSID: $Id$
a324a7bc
GL
6 * -------------------------------------------------------------------------
7 */
8#ifndef __GSOCKET_H
9#define __GSOCKET_H
10
d422d01e
RR
11#include "wx/setup.h"
12
13#if wxUSE_SOCKETS
14
98781fa3 15#include <stddef.h>
a324a7bc
GL
16#include <sys/types.h>
17
18#if !defined(__cplusplus)
a324a7bc 19typedef int bool;
a324a7bc
GL
20#endif
21
22#ifndef TRUE
23#define TRUE 1
24#endif
25
26#ifndef FALSE
27#define FALSE 0
28#endif
29
30typedef struct _GSocket GSocket;
31typedef struct _GAddress GAddress;
32
33typedef enum {
34 GSOCK_NOFAMILY = 0,
35 GSOCK_INET,
36 GSOCK_INET6,
37 GSOCK_UNIX
38} GAddressType;
39
40typedef enum {
41 GSOCK_STREAMED,
42 GSOCK_UNSTREAMED
43} GSocketStream;
44
45typedef enum {
46 GSOCK_NOERROR = 0,
47 GSOCK_INVOP,
48 GSOCK_IOERR,
49 GSOCK_INVADDR,
50 GSOCK_INVSOCK,
51 GSOCK_NOHOST,
f439844b 52 GSOCK_INVPORT,
98781fa3
GL
53 GSOCK_WOULDBLOCK,
54 GSOCK_TIMEOUT,
e00f35bb 55 GSOCK_MEMERR
a324a7bc
GL
56} GSocketError;
57
58typedef enum {
59 GSOCK_INPUT = 0,
60 GSOCK_OUTPUT = 1,
61 GSOCK_CONNECTION = 2,
62 GSOCK_LOST = 3,
63 GSOCK_MAX_EVENT = 4
64} GSocketEvent;
65
66enum {
67 GSOCK_INPUT_FLAG = 1 << GSOCK_INPUT,
68 GSOCK_OUTPUT_FLAG = 1 << GSOCK_OUTPUT,
69 GSOCK_CONNECTION_FLAG = 1 << GSOCK_CONNECTION,
31528cd3 70 GSOCK_LOST_FLAG = 1 << GSOCK_LOST
a324a7bc
GL
71};
72
73typedef int GSocketEventFlags;
74
39b91eca 75typedef void (*GSocketCallback)(GSocket *socket, GSocketEvent event,
31528cd3 76 char *cdata);
a324a7bc
GL
77
78#ifdef __cplusplus
79extern "C" {
80#endif
81
a58d5df4
GL
82/* Global initialisers */
83
84/* GSocket_Init() must be called at the beginning */
31989b0b 85bool GSocket_Init();
a58d5df4
GL
86/* GSocket_Cleanup() must be called at the ending */
87void GSocket_Cleanup();
88
a324a7bc
GL
89/* Constructors / Destructors */
90
91GSocket *GSocket_new();
92void GSocket_destroy(GSocket *socket);
93
94/* This will disable all IO calls to this socket but errors are still available */
95void GSocket_Shutdown(GSocket *socket);
96
97/* Address handling */
98
99GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address);
100GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address);
101GAddress *GSocket_GetLocal(GSocket *socket);
102GAddress *GSocket_GetPeer(GSocket *socket);
103
104/* Non-oriented connections handlers */
105
106GSocketError GSocket_SetNonOriented(GSocket *socket);
107
108/* Server specific parts */
109
110/*
7e1e0960 111 GSocket_SetServer() setups the socket as a server. It uses the "Local" field
a324a7bc
GL
112 of GSocket. "Local" must be set by GSocket_SetLocal() before
113 GSocket_SetServer() is called. In the other case, it returns GSOCK_INVADDR.
114*/
115GSocketError GSocket_SetServer(GSocket *socket);
116
117/*
118 GSocket_WaitConnection() waits for an incoming client connection.
119*/
120GSocket *GSocket_WaitConnection(GSocket *socket);
121
122/* Client specific parts */
123
124/*
125 GSocket_Connect() establishes a client connection to a server using the "Peer"
126 field of GSocket. "Peer" must be set by GSocket_SetPeer() before
127 GSocket_Connect() is called. In the other case, it returns GSOCK_INVADDR.
128*/
129GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream);
130
131/* Generic IO */
132
133/* Like recv(), send(), ... */
31528cd3 134/*
a324a7bc 135 NOTE: In case we read from a non-oriented connection, the incoming (outgoing)
31528cd3 136 connection address is stored in the "Local" ("Peer") field.
a324a7bc
GL
137*/
138int GSocket_Read(GSocket *socket, char *buffer, int size);
139int GSocket_Write(GSocket *socket, const char *buffer,
31528cd3 140 int size);
a324a7bc
GL
141bool GSocket_DataAvailable(GSocket *socket);
142
39b91eca
GL
143/* Flags/Parameters */
144
145/*
146 GSocket_SetTimeout() sets the timeout for reading and writing IO call. Time
147 is expressed in milliseconds.
148 */
149void GSocket_SetTimeout(GSocket *socket, unsigned long millisec);
a324a7bc
GL
150
151/*
152 GSocket_SetBlocking() puts the socket in non-blocking mode. This is useful
153 if we don't want to wait.
154*/
39b91eca 155void GSocket_SetNonBlocking(GSocket *socket, bool non_block);
a324a7bc
GL
156
157/*
158 GSocket_GetError() returns the last error occured on the socket stream.
159*/
160
161GSocketError GSocket_GetError(GSocket *socket);
162
163/* Callbacks */
164
31528cd3 165/*
a324a7bc 166 Only one fallback is possible for each event (INPUT, OUTPUT, CONNECTION, LOST)
31528cd3 167 INPUT: The function is called when there is at least a byte in the
a324a7bc
GL
168 input buffer
169 OUTPUT: The function is called when the system is sure the next write call
170 will not block
171 CONNECTION: Two cases is possible:
172 Client socket -> the connection is established
31528cd3 173 Server socket -> a client request a connection
a324a7bc
GL
174 LOST: the connection is lost
175
39b91eca 176 SetCallback accepts a combination of these flags so a same callback can
a324a7bc
GL
177 receive different events.
178
179 An event is generated only once and its state is reseted when the relative
180 IO call is requested.
181 For example: INPUT -> GSocket_Read()
182 CONNECTION -> GSocket_Accept()
183*/
39b91eca
GL
184void GSocket_SetCallback(GSocket *socket, GSocketEventFlags event,
185 GSocketCallback fallback, char *cdata);
a324a7bc
GL
186
187/*
39b91eca 188 UnsetCallback will disables all fallbacks specified by "event".
a324a7bc
GL
189 NOTE: event may be a combination of flags
190*/
39b91eca 191void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags event);
a324a7bc
GL
192
193/* GAddress */
194
195GAddress *GAddress_new();
196GAddress *GAddress_copy(GAddress *address);
197void GAddress_destroy(GAddress *address);
198
199void GAddress_SetFamily(GAddress *address, GAddressType type);
200GAddressType GAddress_GetFamily(GAddress *address);
201
31528cd3 202/*
a324a7bc
GL
203 The use of any of the next functions will set the address family to the adapted
204 one. For example if you use GAddress_INET_SetHostName, address family will be AF_INET
205 implicitely
206*/
207
208GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
209GSocketError GAddress_INET_SetHostAddress(GAddress *address,
210 unsigned long hostaddr);
5a96d2f4
GL
211GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
212 const char *protocol);
a324a7bc
GL
213GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
214
215GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
216 size_t sbuf);
217unsigned long GAddress_INET_GetHostAddress(GAddress *address);
218unsigned short GAddress_INET_GetPort(GAddress *address);
219
220/* TODO: Define specific parts (INET6, UNIX) */
221
222GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path);
223GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf);
224
225/*
226 * System specific functions
227 */
228
229/* On systems needing an event id */
230void GSocket_SetEventID(GSocket *socket, unsigned long evt_id);
231
232/* On systems which don't have background refresh */
233void GSocket_DoEvent(unsigned long evt_id);
234
235#ifdef __cplusplus
236};
d422d01e
RR
237#endif /* __cplusplus */
238
239
a324a7bc 240#endif
d422d01e 241 /* wxUSE_SOCKETS */
a324a7bc
GL
242
243#endif
d422d01e 244 /* __GSOCKET_H */