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