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