]>
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>
6 * Copyright: (c) Guilhem Lavaux
7 * (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
8 * Licence: wxWindows Licence
9 * Purpose: GSocket include file (system independent)
11 * -------------------------------------------------------------------------
14 #ifndef _WX_GSOCKET_H_
15 #define _WX_GSOCKET_H_
21 #include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
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>
38 typedef struct _GAddress GAddress
;
69 /* See below for an explanation on how events work.
82 GSOCK_INPUT_FLAG
= 1 << GSOCK_INPUT
,
83 GSOCK_OUTPUT_FLAG
= 1 << GSOCK_OUTPUT
,
84 GSOCK_CONNECTION_FLAG
= 1 << GSOCK_CONNECTION
,
85 GSOCK_LOST_FLAG
= 1 << GSOCK_LOST
88 typedef int GSocketEventFlags
;
92 typedef void (*GSocketCallback
)(GSocket
*socket
, GSocketEvent event
,
96 Class providing hooks abstracting the differences between console and GUI
97 applications for socket code.
99 We also have different implementations of this class for different platforms
100 allowing us to keep more things in the common code but the main reason for
101 its existence is that we want the same socket code work differently
102 depending on whether it's used from a console or a GUI program. This is
103 achieved by implementing the virtual methods of this class differently in
104 the objects returned by wxConsoleAppTraits::GetSocketFunctionsTable() and
105 the same method in wxGUIAppTraits.
110 // set the manager to use, we don't take ownership of it
112 // this should be called before GSocket_Init(), i.e. before the first
113 // wxSocket object is created, otherwise the manager returned by
114 // wxAppTraits::GetSocketManager() will be used
115 static void Set(GSocketManager
*manager
);
117 // return the manager to use
119 // this initializes the manager at first use
120 static GSocketManager
*Get()
128 // called before the first wxSocket is created and should do the
129 // initializations needed in order to use the network
131 // return true if initialized successfully
132 virtual bool OnInit() = 0;
134 // undo the initializations of OnInit()
135 virtual void OnExit() = 0;
138 // do manager-specific socket initializations (and undo it): this is called
139 // in the beginning/end of the socket initialization/destruction
140 virtual bool Init_Socket(GSocket
*socket
) = 0;
141 virtual void Destroy_Socket(GSocket
*socket
) = 0;
143 virtual void Install_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
144 virtual void Uninstall_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
146 virtual void Enable_Events(GSocket
*socket
) = 0;
147 virtual void Disable_Events(GSocket
*socket
) = 0;
149 virtual ~GSocketManager() { }
152 // get the manager to use if we don't have it yet
155 static GSocketManager
*ms_manager
;
158 #if defined(__WINDOWS__)
159 #include "wx/msw/gsockmsw.h"
161 #include "wx/unix/gsockunx.h"
165 /* Global initializers */
167 /* GSocket_Init() must be called at the beginning (but after calling
168 * GSocketManager::Set() if a custom manager should be used) */
171 /* GSocket_Cleanup() must be called at the end */
172 void GSocket_Cleanup();
175 /* Constructors / Destructors */
177 GSocket
*GSocket_new();
182 GAddress
*GAddress_new();
183 GAddress
*GAddress_copy(GAddress
*address
);
184 void GAddress_destroy(GAddress
*address
);
186 void GAddress_SetFamily(GAddress
*address
, GAddressType type
);
187 GAddressType
GAddress_GetFamily(GAddress
*address
);
189 /* The use of any of the next functions will set the address family to
190 * the specific one. For example if you use GAddress_INET_SetHostName,
191 * address family will be implicitly set to AF_INET.
194 GSocketError
GAddress_INET_SetHostName(GAddress
*address
, const char *hostname
);
195 GSocketError
GAddress_INET_SetBroadcastAddress(GAddress
*address
);
196 GSocketError
GAddress_INET_SetAnyAddress(GAddress
*address
);
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
);
210 GSocketError
GAddress_INET6_SetHostName(GAddress
*address
, const char *hostname
);
211 GSocketError
GAddress_INET6_SetAnyAddress(GAddress
*address
);
212 GSocketError
GAddress_INET6_SetHostAddress(GAddress
*address
,
213 struct in6_addr hostaddr
);
214 GSocketError
GAddress_INET6_SetPortName(GAddress
*address
, const char *port
,
215 const char *protocol
);
216 GSocketError
GAddress_INET6_SetPort(GAddress
*address
, unsigned short port
);
218 GSocketError
GAddress_INET6_GetHostName(GAddress
*address
, char *hostname
,
220 GSocketError
GAddress_INET6_GetHostAddress(GAddress
*address
,struct in6_addr
*hostaddr
);
221 unsigned short GAddress_INET6_GetPort(GAddress
*address
);
225 /* TODO: Define specific parts (UNIX) */
227 GSocketError
GAddress_UNIX_SetPath(GAddress
*address
, const char *path
);
228 GSocketError
GAddress_UNIX_GetPath(GAddress
*address
, char *path
, size_t sbuf
);
230 #endif /* wxUSE_SOCKETS */
232 #endif /* _WX_GSOCKET_H_ */