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