]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gsocket.h
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket)
4 * Purpose: GSocket include file (system independent)
6 * -------------------------------------------------------------------------
11 #include <sys/types.h>
13 #if !defined(__cplusplus)
27 typedef struct _GSocket GSocket
;
28 typedef struct _GAddress GAddress
;
61 GSOCK_INPUT_FLAG
= 1 << GSOCK_INPUT
,
62 GSOCK_OUTPUT_FLAG
= 1 << GSOCK_OUTPUT
,
63 GSOCK_CONNECTION_FLAG
= 1 << GSOCK_CONNECTION
,
64 GSOCK_LOST_FLAG
= 1 << GSOCK_LOST
67 typedef int GSocketEventFlags
;
69 typedef void (*GSocketFallback
)(GSocket
*socket
, GSocketEvent event
,
76 /* Global initialisers */
78 /* GSocket_Init() must be called at the beginning */
80 /* GSocket_Cleanup() must be called at the ending */
81 void GSocket_Cleanup();
83 /* Constructors / Destructors */
85 GSocket
*GSocket_new();
86 void GSocket_destroy(GSocket
*socket
);
88 /* This will disable all IO calls to this socket but errors are still available */
89 void GSocket_Shutdown(GSocket
*socket
);
91 /* Address handling */
93 GSocketError
GSocket_SetLocal(GSocket
*socket
, GAddress
*address
);
94 GSocketError
GSocket_SetPeer(GSocket
*socket
, GAddress
*address
);
95 GAddress
*GSocket_GetLocal(GSocket
*socket
);
96 GAddress
*GSocket_GetPeer(GSocket
*socket
);
98 /* Non-oriented connections handlers */
100 GSocketError
GSocket_SetNonOriented(GSocket
*socket
);
102 /* Server specific parts */
105 GSocket_SetServer() setup the socket as a server. It uses the "Local" field
106 of GSocket. "Local" must be set by GSocket_SetLocal() before
107 GSocket_SetServer() is called. In the other case, it returns GSOCK_INVADDR.
109 GSocketError
GSocket_SetServer(GSocket
*socket
);
112 GSocket_WaitConnection() waits for an incoming client connection.
114 GSocket
*GSocket_WaitConnection(GSocket
*socket
);
116 /* Client specific parts */
119 GSocket_Connect() establishes a client connection to a server using the "Peer"
120 field of GSocket. "Peer" must be set by GSocket_SetPeer() before
121 GSocket_Connect() is called. In the other case, it returns GSOCK_INVADDR.
123 GSocketError
GSocket_Connect(GSocket
*socket
, GSocketStream stream
);
127 /* Like recv(), send(), ... */
129 NOTE: In case we read from a non-oriented connection, the incoming (outgoing)
130 connection address is stored in the "Local" ("Peer") field.
132 int GSocket_Read(GSocket
*socket
, char *buffer
, int size
);
133 int GSocket_Write(GSocket
*socket
, const char *buffer
,
135 bool GSocket_DataAvailable(GSocket
*socket
);
140 GSocket_SetBlocking() puts the socket in non-blocking mode. This is useful
141 if we don't want to wait.
143 void GSocket_SetBlocking(GSocket
*socket
, bool block
);
146 GSocket_GetError() returns the last error occured on the socket stream.
149 GSocketError
GSocket_GetError(GSocket
*socket
);
154 Only one fallback is possible for each event (INPUT, OUTPUT, CONNECTION, LOST)
155 INPUT: The function is called when there is at least a byte in the
157 OUTPUT: The function is called when the system is sure the next write call
159 CONNECTION: Two cases is possible:
160 Client socket -> the connection is established
161 Server socket -> a client request a connection
162 LOST: the connection is lost
164 SetFallback accepts a combination of these flags so a same callback can
165 receive different events.
167 An event is generated only once and its state is reseted when the relative
168 IO call is requested.
169 For example: INPUT -> GSocket_Read()
170 CONNECTION -> GSocket_Accept()
172 void GSocket_SetFallback(GSocket
*socket
, GSocketEventFlags event
,
173 GSocketFallback fallback
, char *cdata
);
176 UnsetFallback will disables all fallbacks specified by "event".
177 NOTE: event may be a combination of flags
179 void GSocket_UnsetFallback(GSocket
*socket
, GSocketEventFlags event
);
183 GAddress
*GAddress_new();
184 GAddress
*GAddress_copy(GAddress
*address
);
185 void GAddress_destroy(GAddress
*address
);
187 void GAddress_SetFamily(GAddress
*address
, GAddressType type
);
188 GAddressType
GAddress_GetFamily(GAddress
*address
);
191 The use of any of the next functions will set the address family to the adapted
192 one. For example if you use GAddress_INET_SetHostName, address family will be AF_INET
196 GSocketError
GAddress_INET_SetHostName(GAddress
*address
, const char *hostname
);
197 GSocketError
GAddress_INET_SetHostAddress(GAddress
*address
,
198 unsigned long hostaddr
);
199 GSocketError
GAddress_INET_SetPortName(GAddress
*address
, const char *port
,
200 const char *protocol
);
201 GSocketError
GAddress_INET_SetPort(GAddress
*address
, unsigned short port
);
203 GSocketError
GAddress_INET_GetHostName(GAddress
*address
, char *hostname
,
205 unsigned long GAddress_INET_GetHostAddress(GAddress
*address
);
206 unsigned short GAddress_INET_GetPort(GAddress
*address
);
208 /* TODO: Define specific parts (INET6, UNIX) */
210 GSocketError
GAddress_UNIX_SetPath(GAddress
*address
, const char *path
);
211 GSocketError
GAddress_UNIX_GetPath(GAddress
*address
, char *path
, size_t sbuf
);
214 * System specific functions
217 /* On systems needing an event id */
218 void GSocket_SetEventID(GSocket
*socket
, unsigned long evt_id
);
220 /* On systems which don't have background refresh */
221 void GSocket_DoEvent(unsigned long evt_id
);