]>
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__
16 #include "wx/platform.h"
18 #include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
22 #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
27 Including sys/types.h under cygwin results in the warnings about "fd_set
28 having been defined in sys/types.h" when winsock.h is included later and
29 doesn't seem to be necessary anyhow. It's not needed under Mac neither.
31 #if !defined(__WXMAC__) && !defined(__CYGWIN__) && !defined(__WXWINCE__)
32 #include <sys/types.h>
45 typedef struct _GAddress GAddress
;
73 /* See below for an explanation on how events work.
84 GSOCK_INPUT_FLAG
= 1 << GSOCK_INPUT
,
85 GSOCK_OUTPUT_FLAG
= 1 << GSOCK_OUTPUT
,
86 GSOCK_CONNECTION_FLAG
= 1 << GSOCK_CONNECTION
,
87 GSOCK_LOST_FLAG
= 1 << GSOCK_LOST
90 typedef int GSocketEventFlags
;
92 typedef void (*GSocketCallback
)(GSocket
*socket
, GSocketEvent event
,
96 /* Functions tables for internal use by GSocket code: */
98 /* Actually this is a misnomer now, but reusing this name means I don't
99 have to ifdef app traits or common socket code */
100 class GSocketGUIFunctionsTable
103 // needed since this class declares virtual members
104 virtual ~GSocketGUIFunctionsTable() { }
105 virtual bool OnInit() = 0;
106 virtual void OnExit() = 0;
107 virtual bool CanUseEventLoop() = 0;
108 virtual bool Init_Socket(GSocket
*socket
) = 0;
109 virtual void Destroy_Socket(GSocket
*socket
) = 0;
111 virtual void Install_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
112 virtual void Uninstall_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
114 virtual void Enable_Events(GSocket
*socket
) = 0;
115 virtual void Disable_Events(GSocket
*socket
) = 0;
119 /* Global initializers */
121 /* Sets GUI functions callbacks. Must be called *before* GSocket_Init
122 if the app uses async sockets. */
123 void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable
*guifunc
);
125 /* GSocket_Init() must be called at the beginning */
126 int GSocket_Init(void);
128 /* GSocket_Cleanup() must be called at the end */
129 void GSocket_Cleanup(void);
132 /* Constructors / Destructors */
134 GSocket
*GSocket_new(void);
139 GAddress
*GAddress_new(void);
140 GAddress
*GAddress_copy(GAddress
*address
);
141 void GAddress_destroy(GAddress
*address
);
143 void GAddress_SetFamily(GAddress
*address
, GAddressType type
);
144 GAddressType
GAddress_GetFamily(GAddress
*address
);
146 /* The use of any of the next functions will set the address family to
147 * the specific one. For example if you use GAddress_INET_SetHostName,
148 * address family will be implicitly set to AF_INET.
151 GSocketError
GAddress_INET_SetHostName(GAddress
*address
, const char *hostname
);
152 GSocketError
GAddress_INET_SetAnyAddress(GAddress
*address
);
153 GSocketError
GAddress_INET_SetHostAddress(GAddress
*address
,
154 unsigned long hostaddr
);
155 GSocketError
GAddress_INET_SetPortName(GAddress
*address
, const char *port
,
156 const char *protocol
);
157 GSocketError
GAddress_INET_SetPort(GAddress
*address
, unsigned short port
);
159 GSocketError
GAddress_INET_GetHostName(GAddress
*address
, char *hostname
,
161 unsigned long GAddress_INET_GetHostAddress(GAddress
*address
);
162 unsigned short GAddress_INET_GetPort(GAddress
*address
);
164 /* TODO: Define specific parts (INET6, UNIX) */
166 GSocketError
GAddress_UNIX_SetPath(GAddress
*address
, const char *path
);
167 GSocketError
GAddress_UNIX_GetPath(GAddress
*address
, char *path
, size_t sbuf
);
171 #endif /* __cplusplus */
173 # if defined(__WINDOWS__)
174 # include "wx/msw/gsockmsw.h"
175 # elif defined(__WXMAC__) && !defined(__DARWIN__)
176 # include "wx/mac/gsockmac.h"
178 # include "wx/unix/gsockunx.h"
181 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
183 #endif /* __GSOCKET_H */