]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gsocket.h
Fixes
[wxWidgets.git] / include / wx / gsocket.h
CommitLineData
a324a7bc
GL
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket)
3 * Name: gsocket.h
33ac7e6f 4 * Author: Guilhem Lavaux
9bf10d6b 5 * Guillermo Rodriguez Garcia <guille@iies.es> (maintainer)
a324a7bc
GL
6 * Purpose: GSocket include file (system independent)
7 * CVSID: $Id$
a324a7bc
GL
8 * -------------------------------------------------------------------------
9 */
9bf10d6b 10
a324a7bc
GL
11#ifndef __GSOCKET_H
12#define __GSOCKET_H
13
0ce742cf 14#ifndef __GSOCKET_STANDALONE__
d422d01e 15#include "wx/setup.h"
3a858e75 16#include "wx/platform.h"
ab8af15f 17
b6db2e91 18#include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
ab8af15f 19
0ce742cf 20#endif
d422d01e 21
0ce742cf 22#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
d422d01e 23
98781fa3 24#include <stddef.h>
58071ea0
VZ
25
26/*
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.
30 */
882dfc67 31#if !defined(__WXMAC__) && !defined(__CYGWIN__) && !defined(__WXWINCE__)
a324a7bc 32#include <sys/types.h>
a02bb143 33#endif
a324a7bc 34
882dfc67
JS
35#ifdef __WXWINCE__
36#include <stdlib.h>
37#endif
38
4b4d23c7 39class GSocket;
09e6e5ec 40
e9e3e3ab
GRG
41#ifdef __cplusplus
42extern "C" {
43#endif
44
a324a7bc
GL
45typedef struct _GAddress GAddress;
46
47typedef enum {
48 GSOCK_NOFAMILY = 0,
49 GSOCK_INET,
50 GSOCK_INET6,
51 GSOCK_UNIX
52} GAddressType;
53
54typedef enum {
55 GSOCK_STREAMED,
56 GSOCK_UNSTREAMED
57} GSocketStream;
58
59typedef enum {
60 GSOCK_NOERROR = 0,
61 GSOCK_INVOP,
62 GSOCK_IOERR,
63 GSOCK_INVADDR,
64 GSOCK_INVSOCK,
65 GSOCK_NOHOST,
f439844b 66 GSOCK_INVPORT,
98781fa3 67 GSOCK_WOULDBLOCK,
aa6d9706 68 GSOCK_TIMEDOUT,
bfa7bf7d 69 GSOCK_MEMERR,
98bdbbe3 70 GSOCK_OPTERR
a324a7bc
GL
71} GSocketError;
72
9bf10d6b
GRG
73/* See below for an explanation on how events work.
74 */
a324a7bc
GL
75typedef enum {
76 GSOCK_INPUT = 0,
77 GSOCK_OUTPUT = 1,
78 GSOCK_CONNECTION = 2,
79 GSOCK_LOST = 3,
80 GSOCK_MAX_EVENT = 4
81} GSocketEvent;
82
83enum {
84 GSOCK_INPUT_FLAG = 1 << GSOCK_INPUT,
85 GSOCK_OUTPUT_FLAG = 1 << GSOCK_OUTPUT,
86 GSOCK_CONNECTION_FLAG = 1 << GSOCK_CONNECTION,
31528cd3 87 GSOCK_LOST_FLAG = 1 << GSOCK_LOST
a324a7bc
GL
88};
89
90typedef int GSocketEventFlags;
91
39b91eca 92typedef void (*GSocketCallback)(GSocket *socket, GSocketEvent event,
31528cd3 93 char *cdata);
a324a7bc 94
a324a7bc 95
38bb138f
VS
96/* Functions tables for internal use by GSocket code: */
97
4b4d23c7
DE
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 */
100class GSocketGUIFunctionsTable
101{
102public:
ed62f740
VZ
103 // needed since this class declares virtual members
104 virtual ~GSocketGUIFunctionsTable() { }
4b4d23c7
DE
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;
110#ifndef __WINDOWS__
111 virtual void Install_Callback(GSocket *socket, GSocketEvent event) = 0;
112 virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event) = 0;
113#endif
114 virtual void Enable_Events(GSocket *socket) = 0;
115 virtual void Disable_Events(GSocket *socket) = 0;
116};
117
38bb138f 118
e9e3e3ab 119/* Global initializers */
a58d5df4 120
38bb138f
VS
121/* Sets GUI functions callbacks. Must be called *before* GSocket_Init
122 if the app uses async sockets. */
3e1400ac 123void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable *guifunc);
38bb138f 124
a58d5df4 125/* GSocket_Init() must be called at the beginning */
5c9eff30 126int GSocket_Init(void);
9bf10d6b
GRG
127
128/* GSocket_Cleanup() must be called at the end */
da051b23 129void GSocket_Cleanup(void);
a58d5df4 130
9bf10d6b 131
a324a7bc
GL
132/* Constructors / Destructors */
133
da051b23 134GSocket *GSocket_new(void);
09e6e5ec 135
9bf10d6b 136
a324a7bc
GL
137/* GAddress */
138
da051b23 139GAddress *GAddress_new(void);
a324a7bc
GL
140GAddress *GAddress_copy(GAddress *address);
141void GAddress_destroy(GAddress *address);
142
143void GAddress_SetFamily(GAddress *address, GAddressType type);
144GAddressType GAddress_GetFamily(GAddress *address);
145
e9e3e3ab
GRG
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.
149 */
a324a7bc
GL
150
151GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
9bf10d6b 152GSocketError GAddress_INET_SetAnyAddress(GAddress *address);
a324a7bc
GL
153GSocketError GAddress_INET_SetHostAddress(GAddress *address,
154 unsigned long hostaddr);
5a96d2f4
GL
155GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
156 const char *protocol);
a324a7bc
GL
157GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
158
159GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
160 size_t sbuf);
161unsigned long GAddress_INET_GetHostAddress(GAddress *address);
162unsigned short GAddress_INET_GetPort(GAddress *address);
163
164/* TODO: Define specific parts (INET6, UNIX) */
165
166GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path);
167GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf);
168
a324a7bc 169#ifdef __cplusplus
ba14d986 170}
d422d01e
RR
171#endif /* __cplusplus */
172
795eb932 173# if defined(__WINDOWS__)
4b4d23c7 174# include "wx/msw/gsockmsw.h"
795eb932
DE
175# elif defined(__WXMAC__) && !defined(__DARWIN__)
176# include "wx/mac/gsockmac.h"
4b4d23c7
DE
177# else
178# include "wx/unix/gsockunx.h"
179# endif
d422d01e 180
0ce742cf 181#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
a324a7bc 182
e9e3e3ab 183#endif /* __GSOCKET_H */