]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gsocket.h
don't define comparison operators taking wxStrings when wxUSE_STL == 1
[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:
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;
108#ifndef __WINDOWS__
109 virtual void Install_Callback(GSocket *socket, GSocketEvent event) = 0;
110 virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event) = 0;
111#endif
112 virtual void Enable_Events(GSocket *socket) = 0;
113 virtual void Disable_Events(GSocket *socket) = 0;
114};
115
38bb138f 116
e9e3e3ab 117/* Global initializers */
a58d5df4 118
38bb138f
VS
119/* Sets GUI functions callbacks. Must be called *before* GSocket_Init
120 if the app uses async sockets. */
3e1400ac 121void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable *guifunc);
38bb138f 122
a58d5df4 123/* GSocket_Init() must be called at the beginning */
5c9eff30 124int GSocket_Init(void);
9bf10d6b
GRG
125
126/* GSocket_Cleanup() must be called at the end */
da051b23 127void GSocket_Cleanup(void);
a58d5df4 128
9bf10d6b 129
a324a7bc
GL
130/* Constructors / Destructors */
131
da051b23 132GSocket *GSocket_new(void);
09e6e5ec 133
9bf10d6b 134
a324a7bc
GL
135/* GAddress */
136
da051b23 137GAddress *GAddress_new(void);
a324a7bc
GL
138GAddress *GAddress_copy(GAddress *address);
139void GAddress_destroy(GAddress *address);
140
141void GAddress_SetFamily(GAddress *address, GAddressType type);
142GAddressType GAddress_GetFamily(GAddress *address);
143
e9e3e3ab
GRG
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.
147 */
a324a7bc
GL
148
149GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
9bf10d6b 150GSocketError GAddress_INET_SetAnyAddress(GAddress *address);
a324a7bc
GL
151GSocketError GAddress_INET_SetHostAddress(GAddress *address,
152 unsigned long hostaddr);
5a96d2f4
GL
153GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
154 const char *protocol);
a324a7bc
GL
155GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
156
157GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
158 size_t sbuf);
159unsigned long GAddress_INET_GetHostAddress(GAddress *address);
160unsigned short GAddress_INET_GetPort(GAddress *address);
161
162/* TODO: Define specific parts (INET6, UNIX) */
163
164GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path);
165GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf);
166
a324a7bc 167#ifdef __cplusplus
ba14d986 168}
d422d01e
RR
169#endif /* __cplusplus */
170
795eb932 171# if defined(__WINDOWS__)
4b4d23c7 172# include "wx/msw/gsockmsw.h"
795eb932
DE
173# elif defined(__WXMAC__) && !defined(__DARWIN__)
174# include "wx/mac/gsockmac.h"
4b4d23c7
DE
175# else
176# include "wx/unix/gsockunx.h"
177# endif
d422d01e 178
0ce742cf 179#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
a324a7bc 180
e9e3e3ab 181#endif /* __GSOCKET_H */