]>
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 * Purpose: GSocket include file (system independent)
8 * -------------------------------------------------------------------------
14 #ifndef __GSOCKET_STANDALONE__
17 #include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
21 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
26 Including sys/types.h under cygwin results in the warnings about "fd_set
27 having been defined in sys/types.h" when winsock.h is included later and
28 doesn't seem to be necessary anyhow. It's not needed under Mac neither.
30 #if !defined(__WXMAC__) && !defined(__CYGWIN__) && !defined(__WXWINCE__)
31 #include <sys/types.h>
44 typedef struct _GAddress GAddress
;
72 /* See below for an explanation on how events work.
83 GSOCK_INPUT_FLAG
= 1 << GSOCK_INPUT
,
84 GSOCK_OUTPUT_FLAG
= 1 << GSOCK_OUTPUT
,
85 GSOCK_CONNECTION_FLAG
= 1 << GSOCK_CONNECTION
,
86 GSOCK_LOST_FLAG
= 1 << GSOCK_LOST
89 typedef int GSocketEventFlags
;
91 typedef void (*GSocketCallback
)(GSocket
*socket
, GSocketEvent event
,
95 /* Functions tables for internal use by GSocket code: */
97 /* Actually this is a misnomer now, but reusing this name means I don't
98 have to ifdef app traits or common socket code */
99 class GSocketGUIFunctionsTable
102 // needed since this class declares virtual members
103 virtual ~GSocketGUIFunctionsTable() { }
104 virtual bool OnInit() = 0;
105 virtual void OnExit() = 0;
106 virtual bool CanUseEventLoop() = 0;
107 virtual bool Init_Socket(GSocket
*socket
) = 0;
108 virtual void Destroy_Socket(GSocket
*socket
) = 0;
110 virtual void Install_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
111 virtual void Uninstall_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
113 virtual void Enable_Events(GSocket
*socket
) = 0;
114 virtual void Disable_Events(GSocket
*socket
) = 0;
118 /* Global initializers */
120 /* Sets GUI functions callbacks. Must be called *before* GSocket_Init
121 if the app uses async sockets. */
122 void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable
*guifunc
);
124 /* GSocket_Init() must be called at the beginning */
125 int GSocket_Init(void);
127 /* GSocket_Cleanup() must be called at the end */
128 void GSocket_Cleanup(void);
131 /* Constructors / Destructors */
133 GSocket
*GSocket_new(void);
138 GAddress
*GAddress_new(void);
139 GAddress
*GAddress_copy(GAddress
*address
);
140 void GAddress_destroy(GAddress
*address
);
142 void GAddress_SetFamily(GAddress
*address
, GAddressType type
);
143 GAddressType
GAddress_GetFamily(GAddress
*address
);
145 /* The use of any of the next functions will set the address family to
146 * the specific one. For example if you use GAddress_INET_SetHostName,
147 * address family will be implicitly set to AF_INET.
150 GSocketError
GAddress_INET_SetHostName(GAddress
*address
, const char *hostname
);
151 GSocketError
GAddress_INET_SetAnyAddress(GAddress
*address
);
152 GSocketError
GAddress_INET_SetHostAddress(GAddress
*address
,
153 unsigned long hostaddr
);
154 GSocketError
GAddress_INET_SetPortName(GAddress
*address
, const char *port
,
155 const char *protocol
);
156 GSocketError
GAddress_INET_SetPort(GAddress
*address
, unsigned short port
);
158 GSocketError
GAddress_INET_GetHostName(GAddress
*address
, char *hostname
,
160 unsigned long GAddress_INET_GetHostAddress(GAddress
*address
);
161 unsigned short GAddress_INET_GetPort(GAddress
*address
);
163 /* TODO: Define specific parts (INET6, UNIX) */
165 GSocketError
GAddress_UNIX_SetPath(GAddress
*address
, const char *path
);
166 GSocketError
GAddress_UNIX_GetPath(GAddress
*address
, char *path
, size_t sbuf
);
170 #endif /* __cplusplus */
172 # if defined(__WINDOWS__)
173 # include "wx/msw/gsockmsw.h"
174 # elif defined(__WXMAC__) && !defined(__DARWIN__)
175 # include "wx/mac/gsockmac.h"
177 # include "wx/unix/gsockunx.h"
180 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
182 #endif /* __GSOCKET_H */