]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gsocket.h
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket)
4 * Author: Guilhem Lavaux
5 * Guillermo Rodriguez Garcia <guille@iies.es> (maintainer)
6 * Copyright: (c) Guilhem Lavaux
7 * Licence: wxWindows Licence
8 * Purpose: GSocket include file (system independent)
10 * -------------------------------------------------------------------------
16 #ifndef __GSOCKET_STANDALONE__
19 #include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
23 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
28 Including sys/types.h under cygwin results in the warnings about "fd_set
29 having been defined in sys/types.h" when winsock.h is included later and
30 doesn't seem to be necessary anyhow. It's not needed under Mac neither.
32 #if !defined(__WXMAC__) && !defined(__CYGWIN__) && !defined(__WXWINCE__)
33 #include <sys/types.h>
46 typedef struct _GAddress GAddress
;
74 /* See below for an explanation on how events work.
85 GSOCK_INPUT_FLAG
= 1 << GSOCK_INPUT
,
86 GSOCK_OUTPUT_FLAG
= 1 << GSOCK_OUTPUT
,
87 GSOCK_CONNECTION_FLAG
= 1 << GSOCK_CONNECTION
,
88 GSOCK_LOST_FLAG
= 1 << GSOCK_LOST
91 typedef int GSocketEventFlags
;
93 typedef void (*GSocketCallback
)(GSocket
*socket
, GSocketEvent event
,
97 /* Functions tables for internal use by GSocket code: */
99 /* Actually this is a misnomer now, but reusing this name means I don't
100 have to ifdef app traits or common socket code */
101 class GSocketGUIFunctionsTable
104 // needed since this class declares virtual members
105 virtual ~GSocketGUIFunctionsTable() { }
106 virtual bool OnInit() = 0;
107 virtual void OnExit() = 0;
108 virtual bool CanUseEventLoop() = 0;
109 virtual bool Init_Socket(GSocket
*socket
) = 0;
110 virtual void Destroy_Socket(GSocket
*socket
) = 0;
112 virtual void Install_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
113 virtual void Uninstall_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
115 virtual void Enable_Events(GSocket
*socket
) = 0;
116 virtual void Disable_Events(GSocket
*socket
) = 0;
120 /* Global initializers */
122 /* Sets GUI functions callbacks. Must be called *before* GSocket_Init
123 if the app uses async sockets. */
124 void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable
*guifunc
);
126 /* GSocket_Init() must be called at the beginning */
127 int GSocket_Init(void);
129 /* GSocket_Cleanup() must be called at the end */
130 void GSocket_Cleanup(void);
133 /* Constructors / Destructors */
135 GSocket
*GSocket_new(void);
140 GAddress
*GAddress_new(void);
141 GAddress
*GAddress_copy(GAddress
*address
);
142 void GAddress_destroy(GAddress
*address
);
144 void GAddress_SetFamily(GAddress
*address
, GAddressType type
);
145 GAddressType
GAddress_GetFamily(GAddress
*address
);
147 /* The use of any of the next functions will set the address family to
148 * the specific one. For example if you use GAddress_INET_SetHostName,
149 * address family will be implicitly set to AF_INET.
152 GSocketError
GAddress_INET_SetHostName(GAddress
*address
, const char *hostname
);
153 GSocketError
GAddress_INET_SetBroadcastAddress(GAddress
*address
);
154 GSocketError
GAddress_INET_SetAnyAddress(GAddress
*address
);
155 GSocketError
GAddress_INET_SetHostAddress(GAddress
*address
,
156 unsigned long hostaddr
);
157 GSocketError
GAddress_INET_SetPortName(GAddress
*address
, const char *port
,
158 const char *protocol
);
159 GSocketError
GAddress_INET_SetPort(GAddress
*address
, unsigned short port
);
161 GSocketError
GAddress_INET_GetHostName(GAddress
*address
, char *hostname
,
163 unsigned long GAddress_INET_GetHostAddress(GAddress
*address
);
164 unsigned short GAddress_INET_GetPort(GAddress
*address
);
168 GSocketError
GAddress_INET6_SetHostName(GAddress
*address
, const char *hostname
);
169 GSocketError
GAddress_INET6_SetAnyAddress(GAddress
*address
);
170 GSocketError
GAddress_INET6_SetHostAddress(GAddress
*address
,
171 struct in6_addr hostaddr
);
172 GSocketError
GAddress_INET6_SetPortName(GAddress
*address
, const char *port
,
173 const char *protocol
);
174 GSocketError
GAddress_INET6_SetPort(GAddress
*address
, unsigned short port
);
176 GSocketError
GAddress_INET6_GetHostName(GAddress
*address
, char *hostname
,
178 GSocketError
GAddress_INET6_GetHostAddress(GAddress
*address
,struct in6_addr
*hostaddr
);
179 unsigned short GAddress_INET6_GetPort(GAddress
*address
);
183 /* TODO: Define specific parts (UNIX) */
185 GSocketError
GAddress_UNIX_SetPath(GAddress
*address
, const char *path
);
186 GSocketError
GAddress_UNIX_GetPath(GAddress
*address
, char *path
, size_t sbuf
);
190 #endif /* __cplusplus */
192 # if defined(__WINDOWS__)
193 # include "wx/msw/gsockmsw.h"
195 # include "wx/unix/gsockunx.h"
198 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
200 #endif /* __GSOCKET_H */