]>
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 virtual bool OnInit() = 0;
104 virtual void OnExit() = 0;
105 virtual bool CanUseEventLoop() = 0;
106 virtual bool Init_Socket(GSocket
*socket
) = 0;
107 virtual void Destroy_Socket(GSocket
*socket
) = 0;
109 virtual void Install_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
110 virtual void Uninstall_Callback(GSocket
*socket
, GSocketEvent event
) = 0;
112 virtual void Enable_Events(GSocket
*socket
) = 0;
113 virtual void Disable_Events(GSocket
*socket
) = 0;
117 /* Global initializers */
119 /* Sets GUI functions callbacks. Must be called *before* GSocket_Init
120 if the app uses async sockets. */
121 void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable
*guifunc
);
123 /* GSocket_Init() must be called at the beginning */
124 int GSocket_Init(void);
126 /* GSocket_Cleanup() must be called at the end */
127 void GSocket_Cleanup(void);
130 /* Constructors / Destructors */
132 GSocket
*GSocket_new(void);
137 GAddress
*GAddress_new(void);
138 GAddress
*GAddress_copy(GAddress
*address
);
139 void GAddress_destroy(GAddress
*address
);
141 void GAddress_SetFamily(GAddress
*address
, GAddressType type
);
142 GAddressType
GAddress_GetFamily(GAddress
*address
);
144 /* The use of any of the next functions will set the address family to
145 * the specific one. For example if you use GAddress_INET_SetHostName,
146 * address family will be implicitly set to AF_INET.
149 GSocketError
GAddress_INET_SetHostName(GAddress
*address
, const char *hostname
);
150 GSocketError
GAddress_INET_SetAnyAddress(GAddress
*address
);
151 GSocketError
GAddress_INET_SetHostAddress(GAddress
*address
,
152 unsigned long hostaddr
);
153 GSocketError
GAddress_INET_SetPortName(GAddress
*address
, const char *port
,
154 const char *protocol
);
155 GSocketError
GAddress_INET_SetPort(GAddress
*address
, unsigned short port
);
157 GSocketError
GAddress_INET_GetHostName(GAddress
*address
, char *hostname
,
159 unsigned long GAddress_INET_GetHostAddress(GAddress
*address
);
160 unsigned short GAddress_INET_GetPort(GAddress
*address
);
162 /* TODO: Define specific parts (INET6, UNIX) */
164 GSocketError
GAddress_UNIX_SetPath(GAddress
*address
, const char *path
);
165 GSocketError
GAddress_UNIX_GetPath(GAddress
*address
, char *path
, size_t sbuf
);
169 #endif /* __cplusplus */
171 # if defined(__WINDOWS__)
172 # include "wx/msw/gsockmsw.h"
173 # elif defined(__WXMAC__) && !defined(__DARWIN__)
174 # include "wx/mac/gsockmac.h"
176 # include "wx/unix/gsockunx.h"
179 #endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
181 #endif /* __GSOCKET_H */