]>
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 /* Constructors / Destructors */
78 GSocket
*GSocket_new();
79 void GSocket_destroy(GSocket
*socket
);
81 /* This will disable all IO calls to this socket but errors are still available */
82 void GSocket_Shutdown(GSocket
*socket
);
84 /* Address handling */
86 GSocketError
GSocket_SetLocal(GSocket
*socket
, GAddress
*address
);
87 GSocketError
GSocket_SetPeer(GSocket
*socket
, GAddress
*address
);
88 GAddress
*GSocket_GetLocal(GSocket
*socket
);
89 GAddress
*GSocket_GetPeer(GSocket
*socket
);
91 /* Non-oriented connections handlers */
93 GSocketError
GSocket_SetNonOriented(GSocket
*socket
);
95 /* Server specific parts */
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.
102 GSocketError
GSocket_SetServer(GSocket
*socket
);
105 GSocket_WaitConnection() waits for an incoming client connection.
107 GSocket
*GSocket_WaitConnection(GSocket
*socket
);
109 /* Client specific parts */
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.
116 GSocketError
GSocket_Connect(GSocket
*socket
, GSocketStream stream
);
120 /* Like recv(), send(), ... */
122 NOTE: In case we read from a non-oriented connection, the incoming (outgoing)
123 connection address is stored in the "Local" ("Peer") field.
125 int GSocket_Read(GSocket
*socket
, char *buffer
, int size
);
126 int GSocket_Write(GSocket
*socket
, const char *buffer
,
128 bool GSocket_DataAvailable(GSocket
*socket
);
133 GSocket_SetBlocking() puts the socket in non-blocking mode. This is useful
134 if we don't want to wait.
136 void GSocket_SetBlocking(GSocket
*socket
, bool block
);
139 GSocket_GetError() returns the last error occured on the socket stream.
142 GSocketError
GSocket_GetError(GSocket
*socket
);
147 Only one fallback is possible for each event (INPUT, OUTPUT, CONNECTION, LOST)
148 INPUT: The function is called when there is at least a byte in the
150 OUTPUT: The function is called when the system is sure the next write call
152 CONNECTION: Two cases is possible:
153 Client socket -> the connection is established
154 Server socket -> a client request a connection
155 LOST: the connection is lost
157 SetFallback accepts a combination of these flags so a same callback can
158 receive different events.
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()
165 void GSocket_SetFallback(GSocket
*socket
, GSocketEventFlags event
,
166 GSocketFallback fallback
, char *cdata
);
169 UnsetFallback will disables all fallbacks specified by "event".
170 NOTE: event may be a combination of flags
172 void GSocket_UnsetFallback(GSocket
*socket
, GSocketEventFlags event
);
176 GAddress
*GAddress_new();
177 GAddress
*GAddress_copy(GAddress
*address
);
178 void GAddress_destroy(GAddress
*address
);
180 void GAddress_SetFamily(GAddress
*address
, GAddressType type
);
181 GAddressType
GAddress_GetFamily(GAddress
*address
);
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
189 GSocketError
GAddress_INET_SetHostName(GAddress
*address
, const char *hostname
);
190 GSocketError
GAddress_INET_SetHostAddress(GAddress
*address
,
191 unsigned long hostaddr
);
192 GSocketError
GAddress_INET_SetPortName(GAddress
*address
, const char *port
);
193 GSocketError
GAddress_INET_SetPort(GAddress
*address
, unsigned short port
);
195 GSocketError
GAddress_INET_GetHostName(GAddress
*address
, char *hostname
,
197 unsigned long GAddress_INET_GetHostAddress(GAddress
*address
);
198 unsigned short GAddress_INET_GetPort(GAddress
*address
);
200 /* TODO: Define specific parts (INET6, UNIX) */
202 GSocketError
GAddress_UNIX_SetPath(GAddress
*address
, const char *path
);
203 GSocketError
GAddress_UNIX_GetPath(GAddress
*address
, char *path
, size_t sbuf
);
206 * System specific functions
209 /* On systems needing an event id */
210 void GSocket_SetEventID(GSocket
*socket
, unsigned long evt_id
);
212 /* On systems which don't have background refresh */
213 void GSocket_DoEvent(unsigned long evt_id
);