summaryrefslogtreecommitdiff
blob: 874f0eb26a7c083e7046e3b7ae634b55972da26a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
From 88cefd1ff8e70c10661c81b96baf5da1fc49feef Mon Sep 17 00:00:00 2001
From: Jonas Wielicki <j.wielicki@sotecware.net>
Date: Wed, 31 Jul 2013 14:25:23 +0200
Subject: [PATCH 1/2] Make the API more accessible by publishing constants

---
 src/buffer.h  | 15 ++++++++-------
 src/common.h  | 16 ++++++++++++++++
 src/io.h      |  7 ++++---
 src/socket.h  | 51 ++++++++++++++++++++++++++-------------------------
 src/timeout.h | 19 ++++++++++---------
 src/usocket.c |  6 ------
 src/usocket.h | 16 ++++++++++++++++
 src/wsocket.c |  4 ----
 src/wsocket.h |  5 +++++
 9 files changed, 85 insertions(+), 54 deletions(-)
 create mode 100644 src/common.h

diff --git a/src/buffer.h b/src/buffer.h
index a0901fc..66acf09 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -18,6 +18,7 @@
 #include "luasocket.h"
 #include "io.h"
 #include "timeout.h"
+#include "common.h"
 
 /* buffer size in bytes */
 #define BUF_SIZE 8192
@@ -37,13 +38,13 @@ typedef t_buffer *p_buffer;
 #pragma GCC visibility push(hidden)
 #endif
 
-int buffer_open(lua_State *L);
-void buffer_init(p_buffer buf, p_io io, p_timeout tm);
-int buffer_meth_getstats(lua_State *L, p_buffer buf);
-int buffer_meth_setstats(lua_State *L, p_buffer buf);
-int buffer_meth_send(lua_State *L, p_buffer buf);
-int buffer_meth_receive(lua_State *L, p_buffer buf);
-int buffer_isempty(p_buffer buf);
+LUASOCKET_API int buffer_open(lua_State *L);
+LUASOCKET_API void buffer_init(p_buffer buf, p_io io, p_timeout tm);
+LUASOCKET_API int buffer_meth_getstats(lua_State *L, p_buffer buf);
+LUASOCKET_API int buffer_meth_setstats(lua_State *L, p_buffer buf);
+LUASOCKET_API int buffer_meth_send(lua_State *L, p_buffer buf);
+LUASOCKET_API int buffer_meth_receive(lua_State *L, p_buffer buf);
+LUASOCKET_API int buffer_isempty(p_buffer buf);
 
 #ifndef _WIN32
 #pragma GCC visibility pop
diff --git a/src/common.h b/src/common.h
new file mode 100644
index 0000000..9bb0666
--- /dev/null
+++ b/src/common.h
@@ -0,0 +1,16 @@
+#ifndef LUASOCKET_COMMON_H
+#define LUASOCKET_COMMON_H
+
+#ifndef LUASOCKET_API
+#define LUASOCKET_API extern
+#endif
+
+#ifndef UNIX_API
+#define UNIX_API extern
+#endif
+
+#ifndef MIME_API
+#define MIME_API extern
+#endif
+
+#endif
diff --git a/src/io.h b/src/io.h
index b8a54df..6e399fb 100644
--- a/src/io.h
+++ b/src/io.h
@@ -14,13 +14,14 @@
 \*=========================================================================*/
 #include "luasocket.h"
 #include "timeout.h"
+#include "common.h"
 
 /* IO error codes */
 enum {
     IO_DONE = 0,        /* operation completed successfully */
     IO_TIMEOUT = -1,    /* operation timed out */
     IO_CLOSED = -2,     /* the connection has been closed */
-	IO_UNKNOWN = -3
+    IO_UNKNOWN = -3
 };
 
 /* interface to error message function */
@@ -60,8 +61,8 @@ typedef t_io *p_io;
 #pragma GCC visibility push(hidden)
 #endif
 
-void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx);
-const char *io_strerror(int err);
+LUASOCKET_API void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx);
+LUASOCKET_API const char *io_strerror(int err);
 
 #ifndef _WIN32
 #pragma GCC visibility pop
diff --git a/src/socket.h b/src/socket.h
index e541f27..e0b6432 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -10,6 +10,7 @@
 * creates a interface compatible with the io.h module.
 \*=========================================================================*/
 #include "io.h"
+#include "common.h"
 
 /*=========================================================================*\
 * Platform specific compatibilization
@@ -40,31 +41,31 @@ typedef struct sockaddr SA;
 #pragma GCC visibility push(hidden)
 #endif
 
-int socket_waitfd(p_socket ps, int sw, p_timeout tm);
-int socket_open(void);
-int socket_close(void);
-void socket_destroy(p_socket ps);
-int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm);
-int socket_create(p_socket ps, int domain, int type, int protocol);
-int socket_bind(p_socket ps, SA *addr, socklen_t addr_len); 
-int socket_listen(p_socket ps, int backlog);
-void socket_shutdown(p_socket ps, int how); 
-int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); 
-int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *addr_len, p_timeout tm);
-int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm);
-int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm);
-int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);
-int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm);
-int socket_write(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm);
-int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);
-void socket_setblocking(p_socket ps);
-void socket_setnonblocking(p_socket ps);
-int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp);
-int socket_gethostbyname(const char *addr, struct hostent **hp);
-const char *socket_hoststrerror(int err);
-const char *socket_strerror(int err);
-const char *socket_ioerror(p_socket ps, int err);
-const char *socket_gaistrerror(int err);
+LUASOCKET_API int socket_waitfd(p_socket ps, int sw, p_timeout tm);
+LUASOCKET_API int socket_open(void);
+LUASOCKET_API int socket_close(void);
+LUASOCKET_API void socket_destroy(p_socket ps);
+LUASOCKET_API int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm);
+LUASOCKET_API int socket_create(p_socket ps, int domain, int type, int protocol);
+LUASOCKET_API int socket_bind(p_socket ps, SA *addr, socklen_t addr_len);
+LUASOCKET_API int socket_listen(p_socket ps, int backlog);
+LUASOCKET_API void socket_shutdown(p_socket ps, int how);
+LUASOCKET_API int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm);
+LUASOCKET_API int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *addr_len, p_timeout tm);
+LUASOCKET_API int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm);
+LUASOCKET_API int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm);
+LUASOCKET_API int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);
+LUASOCKET_API int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm);
+LUASOCKET_API int socket_write(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm);
+LUASOCKET_API int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);
+LUASOCKET_API void socket_setblocking(p_socket ps);
+LUASOCKET_API void socket_setnonblocking(p_socket ps);
+LUASOCKET_API int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp);
+LUASOCKET_API int socket_gethostbyname(const char *addr, struct hostent **hp);
+LUASOCKET_API const char *socket_hoststrerror(int err);
+LUASOCKET_API const char *socket_strerror(int err);
+LUASOCKET_API const char *socket_ioerror(p_socket ps, int err);
+LUASOCKET_API const char *socket_gaistrerror(int err);
 
 #ifndef _WIN32
 #pragma GCC visibility pop
diff --git a/src/timeout.h b/src/timeout.h
index 9e5250d..b36bd58 100644
--- a/src/timeout.h
+++ b/src/timeout.h
@@ -5,6 +5,7 @@
 * LuaSocket toolkit
 \*=========================================================================*/
 #include "luasocket.h"
+#include "common.h"
 
 /* timeout control structure */
 typedef struct t_timeout_ {
@@ -18,18 +19,18 @@ typedef t_timeout *p_timeout;
 #pragma GCC visibility push(hidden)
 #endif
 
-void timeout_init(p_timeout tm, double block, double total);
-double timeout_get(p_timeout tm);
-double timeout_getstart(p_timeout tm);
-double timeout_getretry(p_timeout tm);
-p_timeout timeout_markstart(p_timeout tm);
+LUASOCKET_API void timeout_init(p_timeout tm, double block, double total);
+LUASOCKET_API double timeout_get(p_timeout tm);
+LUASOCKET_API double timeout_getstart(p_timeout tm);
+LUASOCKET_API double timeout_getretry(p_timeout tm);
+LUASOCKET_API p_timeout timeout_markstart(p_timeout tm);
 
-double timeout_gettime(void);
+LUASOCKET_API double timeout_gettime(void);
 
-int timeout_open(lua_State *L);
+LUASOCKET_API int timeout_open(lua_State *L);
 
-int timeout_meth_settimeout(lua_State *L, p_timeout tm);
-int timeout_meth_gettimeout(lua_State *L, p_timeout tm);
+LUASOCKET_API int timeout_meth_settimeout(lua_State *L, p_timeout tm);
+LUASOCKET_API int timeout_meth_gettimeout(lua_State *L, p_timeout tm);
 
 #ifndef _WIN32
 #pragma GCC visibility pop
diff --git a/src/usocket.c b/src/usocket.c
index acfe186..7490df5 100644
--- a/src/usocket.c
+++ b/src/usocket.c
@@ -20,9 +20,6 @@
 #ifndef SOCKET_SELECT
 #include <sys/poll.h>
 
-#define WAITFD_R        POLLIN
-#define WAITFD_W        POLLOUT
-#define WAITFD_C        (POLLIN|POLLOUT)
 int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
     int ret;
     struct pollfd pfd;
@@ -41,9 +38,6 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
 }
 #else
 
-#define WAITFD_R        1
-#define WAITFD_W        2
-#define WAITFD_C        (WAITFD_R|WAITFD_W)
 
 int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
     int ret;
diff --git a/src/usocket.h b/src/usocket.h
index 45f2f99..ca67c95 100644
--- a/src/usocket.h
+++ b/src/usocket.h
@@ -56,4 +56,20 @@ typedef struct sockaddr_storage t_sockaddr_storage;
 
 #define SOCKET_INVALID (-1)
 
+#ifndef SOCKET_SELECT
+#include <sys/poll.h>
+
+#define WAITFD_R        POLLIN
+#define WAITFD_W        POLLOUT
+#define WAITFD_C        (POLLIN|POLLOUT)
+
+#else
+
+#define WAITFD_R        1
+#define WAITFD_W        2
+#define WAITFD_C        (WAITFD_R|WAITFD_W)
+
+#endif
+
+
 #endif /* USOCKET_H */
diff --git a/src/wsocket.c b/src/wsocket.c
index 20da330..6101dd6 100755
--- a/src/wsocket.c
+++ b/src/wsocket.c
@@ -42,10 +42,6 @@ int socket_close(void) {
 /*-------------------------------------------------------------------------*\
 * Wait for readable/writable/connected socket with timeout
 \*-------------------------------------------------------------------------*/
-#define WAITFD_R        1
-#define WAITFD_W        2
-#define WAITFD_E        4
-#define WAITFD_C        (WAITFD_E|WAITFD_W)
 
 int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
     int ret;
diff --git a/src/wsocket.h b/src/wsocket.h
index 3986640..55ab0a9 100644
--- a/src/wsocket.h
+++ b/src/wsocket.h
@@ -30,4 +30,9 @@ typedef t_socket *p_socket;
 #define AI_NUMERICSERV (0)
 #endif
 
+#define WAITFD_R        1
+#define WAITFD_W        2
+#define WAITFD_E        4
+#define WAITFD_C        (WAITFD_E|WAITFD_W)
+
 #endif /* WSOCKET_H */
-- 
2.32.0