diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-26 04:03:55 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-07-26 04:03:55 +0000 |
commit | cd994f306a67ea7b9ee0ba810d985114e097dd77 (patch) | |
tree | 54a44706f2523c4b53aebc8d4c5024113ab7cfe0 | |
parent | c8b402e00442cd249397d4d33d2723a1f08a8108 (diff) | |
download | luasocket-cd994f306a67ea7b9ee0ba810d985114e097dd77.tar.gz luasocket-cd994f306a67ea7b9ee0ba810d985114e097dd77.tar.bz2 luasocket-cd994f306a67ea7b9ee0ba810d985114e097dd77.zip |
Gonna try my luck on windows...
-rw-r--r-- | src/buffer.c | 17 | ||||
-rw-r--r-- | src/buffer.h | 1 | ||||
-rw-r--r-- | src/io.h | 3 | ||||
-rw-r--r-- | src/luasocket.h | 2 | ||||
-rw-r--r-- | src/socket.lua | 3 | ||||
-rw-r--r-- | src/tcp.c | 7 | ||||
-rw-r--r-- | src/unix.c | 122 | ||||
-rw-r--r-- | src/usocket.c | 16 | ||||
-rw-r--r-- | src/wsocket.c | 7 | ||||
-rw-r--r-- | test/httptest.lua | 7 | ||||
-rw-r--r-- | test/mimetest.lua | 2 |
11 files changed, 106 insertions, 81 deletions
diff --git a/src/buffer.c b/src/buffer.c index 30be156..a696158 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
@@ -60,6 +60,17 @@ int buf_meth_getstats(lua_State *L, p_buf buf) { | |||
60 | } | 60 | } |
61 | 61 | ||
62 | /*-------------------------------------------------------------------------*\ | 62 | /*-------------------------------------------------------------------------*\ |
63 | * object:setstats() interface | ||
64 | \*-------------------------------------------------------------------------*/ | ||
65 | int buf_meth_setstats(lua_State *L, p_buf buf) { | ||
66 | buf->received = (long) luaL_optnumber(L, 2, buf->received); | ||
67 | buf->sent = (long) luaL_optnumber(L, 3, buf->sent); | ||
68 | if (lua_isnumber(L, 4)) buf->birthday = tm_gettime() - lua_tonumber(L, 4); | ||
69 | lua_pushnumber(L, 1); | ||
70 | return 1; | ||
71 | } | ||
72 | |||
73 | /*-------------------------------------------------------------------------*\ | ||
63 | * object:send() interface | 74 | * object:send() interface |
64 | \*-------------------------------------------------------------------------*/ | 75 | \*-------------------------------------------------------------------------*/ |
65 | int buf_meth_send(lua_State *L, p_buf buf) { | 76 | int buf_meth_send(lua_State *L, p_buf buf) { |
@@ -68,12 +79,12 @@ int buf_meth_send(lua_State *L, p_buf buf) { | |||
68 | int err = IO_DONE; | 79 | int err = IO_DONE; |
69 | size_t size, sent; | 80 | size_t size, sent; |
70 | const char *data = luaL_checklstring(L, 2, &size); | 81 | const char *data = luaL_checklstring(L, 2, &size); |
71 | ssize_t start = (ssize_t) luaL_optnumber(L, 3, 1); | 82 | long start = (long) luaL_optnumber(L, 3, 1); |
72 | ssize_t end = (ssize_t) luaL_optnumber(L, 4, -1); | 83 | long end = (long) luaL_optnumber(L, 4, -1); |
73 | if (start < 0) start = size+start+1; | 84 | if (start < 0) start = size+start+1; |
74 | if (end < 0) end = size+end+1; | 85 | if (end < 0) end = size+end+1; |
75 | if (start < 1) start = 1; | 86 | if (start < 1) start = 1; |
76 | if (end > size) end = size; | 87 | if (end > (long) size) end = size; |
77 | if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); | 88 | if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); |
78 | /* check if there was an error */ | 89 | /* check if there was an error */ |
79 | if (err != IO_DONE) { | 90 | if (err != IO_DONE) { |
diff --git a/src/buffer.h b/src/buffer.h index 3cc885f..8e5fb6c 100644 --- a/src/buffer.h +++ b/src/buffer.h | |||
@@ -41,6 +41,7 @@ void buf_init(p_buf buf, p_io io, p_tm tm); | |||
41 | int buf_meth_send(lua_State *L, p_buf buf); | 41 | int buf_meth_send(lua_State *L, p_buf buf); |
42 | int buf_meth_receive(lua_State *L, p_buf buf); | 42 | int buf_meth_receive(lua_State *L, p_buf buf); |
43 | int buf_meth_getstats(lua_State *L, p_buf buf); | 43 | int buf_meth_getstats(lua_State *L, p_buf buf); |
44 | int buf_meth_setstats(lua_State *L, p_buf buf); | ||
44 | int buf_isempty(p_buf buf); | 45 | int buf_isempty(p_buf buf); |
45 | 46 | ||
46 | #endif /* BUF_H */ | 47 | #endif /* BUF_H */ |
@@ -64,4 +64,5 @@ typedef t_io *p_io; | |||
64 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); | 64 | void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); |
65 | const char *io_strerror(int err); | 65 | const char *io_strerror(int err); |
66 | 66 | ||
67 | #endif /* IO_H */ \ No newline at end of file | 67 | #endif /* IO_H */ |
68 | |||
diff --git a/src/luasocket.h b/src/luasocket.h index 716b7ff..14daef5 100644 --- a/src/luasocket.h +++ b/src/luasocket.h | |||
@@ -13,7 +13,7 @@ | |||
13 | /*-------------------------------------------------------------------------*\ | 13 | /*-------------------------------------------------------------------------*\ |
14 | * Current luasocket version | 14 | * Current luasocket version |
15 | \*-------------------------------------------------------------------------*/ | 15 | \*-------------------------------------------------------------------------*/ |
16 | #define LUASOCKET_VERSION "LuaSocket 2.0 (beta)" | 16 | #define LUASOCKET_VERSION "LuaSocket 2.0 (beta2)" |
17 | 17 | ||
18 | /*-------------------------------------------------------------------------*\ | 18 | /*-------------------------------------------------------------------------*\ |
19 | * This macro prefixes all exported API functions | 19 | * This macro prefixes all exported API functions |
diff --git a/src/socket.lua b/src/socket.lua index ad96ddb..be16efe 100644 --- a/src/socket.lua +++ b/src/socket.lua | |||
@@ -90,7 +90,8 @@ socket.sinkt["keep-open"] = function(sock) | |||
90 | dirty = function() return sock:dirty() end | 90 | dirty = function() return sock:dirty() end |
91 | }, { | 91 | }, { |
92 | __call = function(self, chunk, err) | 92 | __call = function(self, chunk, err) |
93 | return sock:send(chunk) | 93 | if chunk then return sock:send(chunk) |
94 | else return 1 end | ||
94 | end | 95 | end |
95 | }) | 96 | }) |
96 | end | 97 | end |
@@ -24,6 +24,7 @@ static int meth_listen(lua_State *L); | |||
24 | static int meth_bind(lua_State *L); | 24 | static int meth_bind(lua_State *L); |
25 | static int meth_send(lua_State *L); | 25 | static int meth_send(lua_State *L); |
26 | static int meth_getstats(lua_State *L); | 26 | static int meth_getstats(lua_State *L); |
27 | static int meth_setstats(lua_State *L); | ||
27 | static int meth_getsockname(lua_State *L); | 28 | static int meth_getsockname(lua_State *L); |
28 | static int meth_getpeername(lua_State *L); | 29 | static int meth_getpeername(lua_State *L); |
29 | static int meth_shutdown(lua_State *L); | 30 | static int meth_shutdown(lua_State *L); |
@@ -49,6 +50,7 @@ static luaL_reg tcp[] = { | |||
49 | {"getpeername", meth_getpeername}, | 50 | {"getpeername", meth_getpeername}, |
50 | {"getsockname", meth_getsockname}, | 51 | {"getsockname", meth_getsockname}, |
51 | {"getstats", meth_getstats}, | 52 | {"getstats", meth_getstats}, |
53 | {"setstats", meth_setstats}, | ||
52 | {"listen", meth_listen}, | 54 | {"listen", meth_listen}, |
53 | {"receive", meth_receive}, | 55 | {"receive", meth_receive}, |
54 | {"send", meth_send}, | 56 | {"send", meth_send}, |
@@ -117,6 +119,11 @@ static int meth_getstats(lua_State *L) { | |||
117 | return buf_meth_getstats(L, &tcp->buf); | 119 | return buf_meth_getstats(L, &tcp->buf); |
118 | } | 120 | } |
119 | 121 | ||
122 | static int meth_setstats(lua_State *L) { | ||
123 | p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1); | ||
124 | return buf_meth_setstats(L, &tcp->buf); | ||
125 | } | ||
126 | |||
120 | /*-------------------------------------------------------------------------*\ | 127 | /*-------------------------------------------------------------------------*\ |
121 | * Just call option handler | 128 | * Just call option handler |
122 | \*-------------------------------------------------------------------------*/ | 129 | \*-------------------------------------------------------------------------*/ |
@@ -33,11 +33,11 @@ static int meth_getfd(lua_State *L); | |||
33 | static int meth_setfd(lua_State *L); | 33 | static int meth_setfd(lua_State *L); |
34 | static int meth_dirty(lua_State *L); | 34 | static int meth_dirty(lua_State *L); |
35 | 35 | ||
36 | static const char *unix_tryconnect(p_unix unix, const char *path); | 36 | static const char *unix_tryconnect(p_unix un, const char *path); |
37 | static const char *unix_trybind(p_unix unix, const char *path); | 37 | static const char *unix_trybind(p_unix un, const char *path); |
38 | 38 | ||
39 | /* unix object methods */ | 39 | /* unix object methods */ |
40 | static luaL_reg unix[] = { | 40 | static luaL_reg un[] = { |
41 | {"__gc", meth_close}, | 41 | {"__gc", meth_close}, |
42 | {"__tostring", aux_tostring}, | 42 | {"__tostring", aux_tostring}, |
43 | {"accept", meth_accept}, | 43 | {"accept", meth_accept}, |
@@ -77,9 +77,9 @@ static luaL_reg func[] = { | |||
77 | \*-------------------------------------------------------------------------*/ | 77 | \*-------------------------------------------------------------------------*/ |
78 | int unix_open(lua_State *L) { | 78 | int unix_open(lua_State *L) { |
79 | /* create classes */ | 79 | /* create classes */ |
80 | aux_newclass(L, "unix{master}", unix); | 80 | aux_newclass(L, "unix{master}", un); |
81 | aux_newclass(L, "unix{client}", unix); | 81 | aux_newclass(L, "unix{client}", un); |
82 | aux_newclass(L, "unix{server}", unix); | 82 | aux_newclass(L, "unix{server}", un); |
83 | /* create class groups */ | 83 | /* create class groups */ |
84 | aux_add2group(L, "unix{master}", "unix{any}"); | 84 | aux_add2group(L, "unix{master}", "unix{any}"); |
85 | aux_add2group(L, "unix{client}", "unix{any}"); | 85 | aux_add2group(L, "unix{client}", "unix{any}"); |
@@ -98,42 +98,42 @@ int unix_open(lua_State *L) { | |||
98 | * Just call buffered IO methods | 98 | * Just call buffered IO methods |
99 | \*-------------------------------------------------------------------------*/ | 99 | \*-------------------------------------------------------------------------*/ |
100 | static int meth_send(lua_State *L) { | 100 | static int meth_send(lua_State *L) { |
101 | p_unix unix = (p_unix) aux_checkclass(L, "unix{client}", 1); | 101 | p_unix un = (p_unix) aux_checkclass(L, "unix{client}", 1); |
102 | return buf_meth_send(L, &unix->buf); | 102 | return buf_meth_send(L, &un->buf); |
103 | } | 103 | } |
104 | 104 | ||
105 | static int meth_receive(lua_State *L) { | 105 | static int meth_receive(lua_State *L) { |
106 | p_unix unix = (p_unix) aux_checkclass(L, "unix{client}", 1); | 106 | p_unix un = (p_unix) aux_checkclass(L, "unix{client}", 1); |
107 | return buf_meth_receive(L, &unix->buf); | 107 | return buf_meth_receive(L, &un->buf); |
108 | } | 108 | } |
109 | 109 | ||
110 | /*-------------------------------------------------------------------------*\ | 110 | /*-------------------------------------------------------------------------*\ |
111 | * Just call option handler | 111 | * Just call option handler |
112 | \*-------------------------------------------------------------------------*/ | 112 | \*-------------------------------------------------------------------------*/ |
113 | static int meth_setoption(lua_State *L) { | 113 | static int meth_setoption(lua_State *L) { |
114 | p_unix unix = (p_unix) aux_checkgroup(L, "unix{any}", 1); | 114 | p_unix un = (p_unix) aux_checkgroup(L, "unix{any}", 1); |
115 | return opt_meth_setoption(L, opt, &unix->sock); | 115 | return opt_meth_setoption(L, opt, &un->sock); |
116 | } | 116 | } |
117 | 117 | ||
118 | /*-------------------------------------------------------------------------*\ | 118 | /*-------------------------------------------------------------------------*\ |
119 | * Select support methods | 119 | * Select support methods |
120 | \*-------------------------------------------------------------------------*/ | 120 | \*-------------------------------------------------------------------------*/ |
121 | static int meth_getfd(lua_State *L) { | 121 | static int meth_getfd(lua_State *L) { |
122 | p_unix unix = (p_unix) aux_checkgroup(L, "unix{any}", 1); | 122 | p_unix un = (p_unix) aux_checkgroup(L, "unix{any}", 1); |
123 | lua_pushnumber(L, (int) unix->sock); | 123 | lua_pushnumber(L, (int) un->sock); |
124 | return 1; | 124 | return 1; |
125 | } | 125 | } |
126 | 126 | ||
127 | /* this is very dangerous, but can be handy for those that are brave enough */ | 127 | /* this is very dangerous, but can be handy for those that are brave enough */ |
128 | static int meth_setfd(lua_State *L) { | 128 | static int meth_setfd(lua_State *L) { |
129 | p_unix unix = (p_unix) aux_checkgroup(L, "unix{any}", 1); | 129 | p_unix un = (p_unix) aux_checkgroup(L, "unix{any}", 1); |
130 | unix->sock = (t_sock) luaL_checknumber(L, 2); | 130 | un->sock = (t_sock) luaL_checknumber(L, 2); |
131 | return 0; | 131 | return 0; |
132 | } | 132 | } |
133 | 133 | ||
134 | static int meth_dirty(lua_State *L) { | 134 | static int meth_dirty(lua_State *L) { |
135 | p_unix unix = (p_unix) aux_checkgroup(L, "unix{any}", 1); | 135 | p_unix un = (p_unix) aux_checkgroup(L, "unix{any}", 1); |
136 | lua_pushboolean(L, !buf_isempty(&unix->buf)); | 136 | lua_pushboolean(L, !buf_isempty(&un->buf)); |
137 | return 1; | 137 | return 1; |
138 | } | 138 | } |
139 | 139 | ||
@@ -145,22 +145,22 @@ static int meth_accept(lua_State *L) { | |||
145 | p_unix server = (p_unix) aux_checkclass(L, "unix{server}", 1); | 145 | p_unix server = (p_unix) aux_checkclass(L, "unix{server}", 1); |
146 | p_tm tm = tm_markstart(&server->tm); | 146 | p_tm tm = tm_markstart(&server->tm); |
147 | t_sock sock; | 147 | t_sock sock; |
148 | const char *err = sock_accept(&server->sock, &sock, NULL, NULL, tm); | 148 | int err = sock_accept(&server->sock, &sock, NULL, NULL, tm); |
149 | /* if successful, push client socket */ | 149 | /* if successful, push client socket */ |
150 | if (!err) { | 150 | if (err == IO_DONE) { |
151 | p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); | 151 | p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); |
152 | aux_setclass(L, "unix{client}", -1); | 152 | aux_setclass(L, "unix{client}", -1); |
153 | /* initialize structure fields */ | 153 | /* initialize structure fields */ |
154 | sock_setnonblocking(&sock); | 154 | sock_setnonblocking(&sock); |
155 | clnt->sock = sock; | 155 | clnt->sock = sock; |
156 | io_init(&clnt->io, (p_send)sock_send, (p_recv)sock_recv, | 156 | io_init(&clnt->io, (p_send)sock_send, (p_recv)sock_recv, |
157 | (p_geterr) sock_geterr, &clnt->sock); | 157 | (p_error) sock_ioerror, &clnt->sock); |
158 | tm_init(&clnt->tm, -1, -1); | 158 | tm_init(&clnt->tm, -1, -1); |
159 | buf_init(&clnt->buf, &clnt->io, &clnt->tm); | 159 | buf_init(&clnt->buf, &clnt->io, &clnt->tm); |
160 | return 1; | 160 | return 1; |
161 | } else { | 161 | } else { |
162 | lua_pushnil(L); | 162 | lua_pushnil(L); |
163 | lua_pushstring(L, err); | 163 | lua_pushstring(L, sock_strerror(err)); |
164 | return 2; | 164 | return 2; |
165 | } | 165 | } |
166 | } | 166 | } |
@@ -168,10 +168,10 @@ static int meth_accept(lua_State *L) { | |||
168 | /*-------------------------------------------------------------------------*\ | 168 | /*-------------------------------------------------------------------------*\ |
169 | * Binds an object to an address | 169 | * Binds an object to an address |
170 | \*-------------------------------------------------------------------------*/ | 170 | \*-------------------------------------------------------------------------*/ |
171 | static const char *unix_trybind(p_unix unix, const char *path) { | 171 | static const char *unix_trybind(p_unix un, const char *path) { |
172 | struct sockaddr_un local; | 172 | struct sockaddr_un local; |
173 | size_t len = strlen(path); | 173 | size_t len = strlen(path); |
174 | const char *err; | 174 | int err; |
175 | if (len >= sizeof(local.sun_path)) return "path too long"; | 175 | if (len >= sizeof(local.sun_path)) return "path too long"; |
176 | memset(&local, 0, sizeof(local)); | 176 | memset(&local, 0, sizeof(local)); |
177 | strcpy(local.sun_path, path); | 177 | strcpy(local.sun_path, path); |
@@ -179,20 +179,20 @@ static const char *unix_trybind(p_unix unix, const char *path) { | |||
179 | #ifdef UNIX_HAS_SUN_LEN | 179 | #ifdef UNIX_HAS_SUN_LEN |
180 | local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) | 180 | local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) |
181 | + len + 1; | 181 | + len + 1; |
182 | err = sock_bind(&unix->sock, (SA *) &local, local.sun_len); | 182 | err = sock_bind(&un->sock, (SA *) &local, local.sun_len); |
183 | 183 | ||
184 | #else | 184 | #else |
185 | err = sock_bind(&unix->sock, (SA *) &local, | 185 | err = sock_bind(&un->sock, (SA *) &local, |
186 | sizeof(local.sun_family) + len); | 186 | sizeof(local.sun_family) + len); |
187 | #endif | 187 | #endif |
188 | if (err) sock_destroy(&unix->sock); | 188 | if (err != IO_DONE) sock_destroy(&un->sock); |
189 | return err; | 189 | return sock_strerror(err); |
190 | } | 190 | } |
191 | 191 | ||
192 | static int meth_bind(lua_State *L) { | 192 | static int meth_bind(lua_State *L) { |
193 | p_unix unix = (p_unix) aux_checkclass(L, "unix{master}", 1); | 193 | p_unix un = (p_unix) aux_checkclass(L, "unix{master}", 1); |
194 | const char *path = luaL_checkstring(L, 2); | 194 | const char *path = luaL_checkstring(L, 2); |
195 | const char *err = unix_trybind(unix, path); | 195 | const char *err = unix_trybind(un, path); |
196 | if (err) { | 196 | if (err) { |
197 | lua_pushnil(L); | 197 | lua_pushnil(L); |
198 | lua_pushstring(L, err); | 198 | lua_pushstring(L, err); |
@@ -205,33 +205,33 @@ static int meth_bind(lua_State *L) { | |||
205 | /*-------------------------------------------------------------------------*\ | 205 | /*-------------------------------------------------------------------------*\ |
206 | * Turns a master unix object into a client object. | 206 | * Turns a master unix object into a client object. |
207 | \*-------------------------------------------------------------------------*/ | 207 | \*-------------------------------------------------------------------------*/ |
208 | static const char *unix_tryconnect(p_unix unix, const char *path) | 208 | static const char *unix_tryconnect(p_unix un, const char *path) |
209 | { | 209 | { |
210 | struct sockaddr_un remote; | 210 | struct sockaddr_un remote; |
211 | const char *err; | 211 | int err; |
212 | size_t len = strlen(path); | 212 | size_t len = strlen(path); |
213 | if (len >= sizeof(remote.sun_path)) return "path too long"; | 213 | if (len >= sizeof(remote.sun_path)) return "path too long"; |
214 | memset(&remote, 0, sizeof(remote)); | 214 | memset(&remote, 0, sizeof(remote)); |
215 | strcpy(remote.sun_path, path); | 215 | strcpy(remote.sun_path, path); |
216 | remote.sun_family = AF_UNIX; | 216 | remote.sun_family = AF_UNIX; |
217 | tm_markstart(&unix->tm); | 217 | tm_markstart(&un->tm); |
218 | #ifdef UNIX_HAS_SUN_LEN | 218 | #ifdef UNIX_HAS_SUN_LEN |
219 | remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) | 219 | remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) |
220 | + len + 1; | 220 | + len + 1; |
221 | err = sock_connect(&unix->sock, (SA *) &remote, remote.sun_len, &unix->tm); | 221 | err = sock_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); |
222 | #else | 222 | #else |
223 | err = sock_connect(&unix->sock, (SA *) &remote, | 223 | err = sock_connect(&un->sock, (SA *) &remote, |
224 | sizeof(remote.sun_family) + len, &unix->tm); | 224 | sizeof(remote.sun_family) + len, &un->tm); |
225 | #endif | 225 | #endif |
226 | if (err) sock_destroy(&unix->sock); | 226 | if (err != IO_DONE) sock_destroy(&un->sock); |
227 | return err; | 227 | return sock_strerror(err); |
228 | } | 228 | } |
229 | 229 | ||
230 | static int meth_connect(lua_State *L) | 230 | static int meth_connect(lua_State *L) |
231 | { | 231 | { |
232 | p_unix unix = (p_unix) aux_checkclass(L, "unix{master}", 1); | 232 | p_unix un = (p_unix) aux_checkclass(L, "unix{master}", 1); |
233 | const char *path = luaL_checkstring(L, 2); | 233 | const char *path = luaL_checkstring(L, 2); |
234 | const char *err = unix_tryconnect(unix, path); | 234 | const char *err = unix_tryconnect(un, path); |
235 | if (err) { | 235 | if (err) { |
236 | lua_pushnil(L); | 236 | lua_pushnil(L); |
237 | lua_pushstring(L, err); | 237 | lua_pushstring(L, err); |
@@ -248,8 +248,8 @@ static int meth_connect(lua_State *L) | |||
248 | \*-------------------------------------------------------------------------*/ | 248 | \*-------------------------------------------------------------------------*/ |
249 | static int meth_close(lua_State *L) | 249 | static int meth_close(lua_State *L) |
250 | { | 250 | { |
251 | p_unix unix = (p_unix) aux_checkgroup(L, "unix{any}", 1); | 251 | p_unix un = (p_unix) aux_checkgroup(L, "unix{any}", 1); |
252 | sock_destroy(&unix->sock); | 252 | sock_destroy(&un->sock); |
253 | return 0; | 253 | return 0; |
254 | } | 254 | } |
255 | 255 | ||
@@ -258,12 +258,12 @@ static int meth_close(lua_State *L) | |||
258 | \*-------------------------------------------------------------------------*/ | 258 | \*-------------------------------------------------------------------------*/ |
259 | static int meth_listen(lua_State *L) | 259 | static int meth_listen(lua_State *L) |
260 | { | 260 | { |
261 | p_unix unix = (p_unix) aux_checkclass(L, "unix{master}", 1); | 261 | p_unix un = (p_unix) aux_checkclass(L, "unix{master}", 1); |
262 | int backlog = (int) luaL_optnumber(L, 2, 32); | 262 | int backlog = (int) luaL_optnumber(L, 2, 32); |
263 | const char *err = sock_listen(&unix->sock, backlog); | 263 | int err = sock_listen(&un->sock, backlog); |
264 | if (err) { | 264 | if (err != IO_DONE) { |
265 | lua_pushnil(L); | 265 | lua_pushnil(L); |
266 | lua_pushstring(L, err); | 266 | lua_pushstring(L, sock_strerror(err)); |
267 | return 2; | 267 | return 2; |
268 | } | 268 | } |
269 | /* turn master object into a server object */ | 269 | /* turn master object into a server object */ |
@@ -277,20 +277,20 @@ static int meth_listen(lua_State *L) | |||
277 | \*-------------------------------------------------------------------------*/ | 277 | \*-------------------------------------------------------------------------*/ |
278 | static int meth_shutdown(lua_State *L) | 278 | static int meth_shutdown(lua_State *L) |
279 | { | 279 | { |
280 | p_unix unix = (p_unix) aux_checkgroup(L, "unix{client}", 1); | 280 | p_unix un = (p_unix) aux_checkgroup(L, "unix{client}", 1); |
281 | const char *how = luaL_optstring(L, 2, "both"); | 281 | const char *how = luaL_optstring(L, 2, "both"); |
282 | switch (how[0]) { | 282 | switch (how[0]) { |
283 | case 'b': | 283 | case 'b': |
284 | if (strcmp(how, "both")) goto error; | 284 | if (strcmp(how, "both")) goto error; |
285 | sock_shutdown(&unix->sock, 2); | 285 | sock_shutdown(&un->sock, 2); |
286 | break; | 286 | break; |
287 | case 's': | 287 | case 's': |
288 | if (strcmp(how, "send")) goto error; | 288 | if (strcmp(how, "send")) goto error; |
289 | sock_shutdown(&unix->sock, 1); | 289 | sock_shutdown(&un->sock, 1); |
290 | break; | 290 | break; |
291 | case 'r': | 291 | case 'r': |
292 | if (strcmp(how, "receive")) goto error; | 292 | if (strcmp(how, "receive")) goto error; |
293 | sock_shutdown(&unix->sock, 0); | 293 | sock_shutdown(&un->sock, 0); |
294 | break; | 294 | break; |
295 | } | 295 | } |
296 | lua_pushnumber(L, 1); | 296 | lua_pushnumber(L, 1); |
@@ -304,8 +304,8 @@ error: | |||
304 | * Just call tm methods | 304 | * Just call tm methods |
305 | \*-------------------------------------------------------------------------*/ | 305 | \*-------------------------------------------------------------------------*/ |
306 | static int meth_settimeout(lua_State *L) { | 306 | static int meth_settimeout(lua_State *L) { |
307 | p_unix unix = (p_unix) aux_checkgroup(L, "unix{any}", 1); | 307 | p_unix un = (p_unix) aux_checkgroup(L, "unix{any}", 1); |
308 | return tm_meth_settimeout(L, &unix->tm); | 308 | return tm_meth_settimeout(L, &un->tm); |
309 | } | 309 | } |
310 | 310 | ||
311 | /*=========================================================================*\ | 311 | /*=========================================================================*\ |
@@ -316,24 +316,24 @@ static int meth_settimeout(lua_State *L) { | |||
316 | \*-------------------------------------------------------------------------*/ | 316 | \*-------------------------------------------------------------------------*/ |
317 | static int global_create(lua_State *L) { | 317 | static int global_create(lua_State *L) { |
318 | t_sock sock; | 318 | t_sock sock; |
319 | const char *err = sock_create(&sock, AF_UNIX, SOCK_STREAM, 0); | 319 | int err = sock_create(&sock, AF_UNIX, SOCK_STREAM, 0); |
320 | /* try to allocate a system socket */ | 320 | /* try to allocate a system socket */ |
321 | if (!err) { | 321 | if (err == IO_DONE) { |
322 | /* allocate unix object */ | 322 | /* allocate unix object */ |
323 | p_unix unix = (p_unix) lua_newuserdata(L, sizeof(t_unix)); | 323 | p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); |
324 | /* set its type as master object */ | 324 | /* set its type as master object */ |
325 | aux_setclass(L, "unix{master}", -1); | 325 | aux_setclass(L, "unix{master}", -1); |
326 | /* initialize remaining structure fields */ | 326 | /* initialize remaining structure fields */ |
327 | sock_setnonblocking(&sock); | 327 | sock_setnonblocking(&sock); |
328 | unix->sock = sock; | 328 | un->sock = sock; |
329 | io_init(&unix->io, (p_send) sock_send, (p_recv) sock_recv, | 329 | io_init(&un->io, (p_send) sock_send, (p_recv) sock_recv, |
330 | (p_geterr) sock_geterr, &unix->sock); | 330 | (p_error) sock_ioerror, &un->sock); |
331 | tm_init(&unix->tm, -1, -1); | 331 | tm_init(&un->tm, -1, -1); |
332 | buf_init(&unix->buf, &unix->io, &unix->tm); | 332 | buf_init(&un->buf, &un->io, &un->tm); |
333 | return 1; | 333 | return 1; |
334 | } else { | 334 | } else { |
335 | lua_pushnil(L); | 335 | lua_pushnil(L); |
336 | lua_pushstring(L, err); | 336 | lua_pushstring(L, sock_strerror(err)); |
337 | return 2; | 337 | return 2; |
338 | } | 338 | } |
339 | } | 339 | } |
diff --git a/src/usocket.c b/src/usocket.c index 0cff17b..62a2557 100644 --- a/src/usocket.c +++ b/src/usocket.c | |||
@@ -205,7 +205,7 @@ int sock_send(p_sock ps, const char *data, size_t count, size_t *sent, p_tm tm) | |||
205 | /* loop until we send something or we give up on error */ | 205 | /* loop until we send something or we give up on error */ |
206 | *sent = 0; | 206 | *sent = 0; |
207 | for ( ;; ) { | 207 | for ( ;; ) { |
208 | ssize_t put = send(*ps, data, count, 0); | 208 | long put = (long) send(*ps, data, count, 0); |
209 | /* if we sent anything, we are done */ | 209 | /* if we sent anything, we are done */ |
210 | if (put > 0) { | 210 | if (put > 0) { |
211 | *sent = put; | 211 | *sent = put; |
@@ -236,7 +236,7 @@ int sock_sendto(p_sock ps, const char *data, size_t count, size_t *sent, | |||
236 | if (*ps == SOCK_INVALID) return IO_CLOSED; | 236 | if (*ps == SOCK_INVALID) return IO_CLOSED; |
237 | *sent = 0; | 237 | *sent = 0; |
238 | for ( ;; ) { | 238 | for ( ;; ) { |
239 | ssize_t put = sendto(*ps, data, count, 0, addr, len); | 239 | long put = (long) sendto(*ps, data, count, 0, addr, len); |
240 | if (put > 0) { | 240 | if (put > 0) { |
241 | *sent = put; | 241 | *sent = put; |
242 | return IO_DONE; | 242 | return IO_DONE; |
@@ -257,7 +257,7 @@ int sock_recv(p_sock ps, char *data, size_t count, size_t *got, p_tm tm) { | |||
257 | int err; | 257 | int err; |
258 | if (*ps == SOCK_INVALID) return IO_CLOSED; | 258 | if (*ps == SOCK_INVALID) return IO_CLOSED; |
259 | for ( ;; ) { | 259 | for ( ;; ) { |
260 | ssize_t taken = recv(*ps, data, count, 0); | 260 | long taken = (long) recv(*ps, data, count, 0); |
261 | if (taken > 0) { | 261 | if (taken > 0) { |
262 | *got = taken; | 262 | *got = taken; |
263 | return IO_DONE; | 263 | return IO_DONE; |
@@ -280,7 +280,7 @@ int sock_recvfrom(p_sock ps, char *data, size_t count, size_t *got, | |||
280 | int err; | 280 | int err; |
281 | if (*ps == SOCK_INVALID) return IO_CLOSED; | 281 | if (*ps == SOCK_INVALID) return IO_CLOSED; |
282 | for ( ;; ) { | 282 | for ( ;; ) { |
283 | ssize_t taken = recvfrom(*ps, data, count, 0, addr, len); | 283 | long taken = (long) recvfrom(*ps, data, count, 0, addr, len); |
284 | if (taken > 0) { | 284 | if (taken > 0) { |
285 | *got = taken; | 285 | *got = taken; |
286 | return IO_DONE; | 286 | return IO_DONE; |
@@ -335,7 +335,7 @@ int sock_gethostbyname(const char *addr, struct hostent **hp) { | |||
335 | const char *sock_hoststrerror(int err) { | 335 | const char *sock_hoststrerror(int err) { |
336 | if (err <= 0) return io_strerror(err); | 336 | if (err <= 0) return io_strerror(err); |
337 | switch (err) { | 337 | switch (err) { |
338 | case HOST_NOT_FOUND: return "host_not_found"; | 338 | case HOST_NOT_FOUND: return "host not found"; |
339 | default: return hstrerror(err); | 339 | default: return hstrerror(err); |
340 | } | 340 | } |
341 | } | 341 | } |
@@ -343,9 +343,9 @@ const char *sock_hoststrerror(int err) { | |||
343 | const char *sock_strerror(int err) { | 343 | const char *sock_strerror(int err) { |
344 | if (err <= 0) return io_strerror(err); | 344 | if (err <= 0) return io_strerror(err); |
345 | switch (err) { | 345 | switch (err) { |
346 | case EADDRINUSE: return "eaddrinuse"; | 346 | case EADDRINUSE: return "address already in use"; |
347 | case EACCES: return "eaccess"; | 347 | case EACCES: return "permission denied"; |
348 | case ECONNREFUSED: return "econnrefused"; | 348 | case ECONNREFUSED: return "connection refused"; |
349 | case ECONNABORTED: return "closed"; | 349 | case ECONNABORTED: return "closed"; |
350 | case ECONNRESET: return "closed"; | 350 | case ECONNRESET: return "closed"; |
351 | case ETIMEDOUT: return "timedout"; | 351 | case ETIMEDOUT: return "timedout"; |
diff --git a/src/wsocket.c b/src/wsocket.c index 511dbdc..1f1e99d 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
@@ -309,7 +309,7 @@ int sock_gethostbyname(const char *addr, struct hostent **hp) { | |||
309 | const char *sock_hoststrerror(int err) { | 309 | const char *sock_hoststrerror(int err) { |
310 | if (err <= 0) return io_strerror(err); | 310 | if (err <= 0) return io_strerror(err); |
311 | switch (err) { | 311 | switch (err) { |
312 | case WSAHOST_NOT_FOUND: return "host_not_found"; | 312 | case WSAHOST_NOT_FOUND: return "host not found"; |
313 | default: return wstrerror(err); | 313 | default: return wstrerror(err); |
314 | } | 314 | } |
315 | } | 315 | } |
@@ -317,8 +317,9 @@ const char *sock_hoststrerror(int err) { | |||
317 | const char *sock_strerror(int err) { | 317 | const char *sock_strerror(int err) { |
318 | if (err <= 0) return io_strerror(err); | 318 | if (err <= 0) return io_strerror(err); |
319 | switch (err) { | 319 | switch (err) { |
320 | case WSAEADDRINUSE: return "eaddrinuse"; | 320 | case WSAEADDRINUSE: return "address already in use"; |
321 | case WSAECONNREFUSED: return "econnrefused"; | 321 | case WSAECONNREFUSED: return "connection refused"; |
322 | case WSAEACCES: return "permission denied"; | ||
322 | case WSAECONNABORTED: return "closed"; | 323 | case WSAECONNABORTED: return "closed"; |
323 | case WSAECONNRESET: return "closed"; | 324 | case WSAECONNRESET: return "closed"; |
324 | case WSAETIMEDOUT: return "timeout"; | 325 | case WSAETIMEDOUT: return "timeout"; |
diff --git a/test/httptest.lua b/test/httptest.lua index 1f4158a..31e8212 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -3,8 +3,11 @@ | |||
3 | -- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi | 3 | -- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi |
4 | -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" | 4 | -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" |
5 | -- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth | 5 | -- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth |
6 | |||
7 | local socket = require("socket") | 6 | local socket = require("socket") |
7 | |||
8 | -- override protection to make sure we see all errors | ||
9 | -- socket.protect = function(s) return s end | ||
10 | |||
8 | local http = require("http") | 11 | local http = require("http") |
9 | local mime = require("mime") | 12 | local mime = require("mime") |
10 | local url = require("url") | 13 | local url = require("url") |
@@ -19,7 +22,7 @@ http.TIMEOUT = 10 | |||
19 | 22 | ||
20 | local t = socket.gettime() | 23 | local t = socket.gettime() |
21 | 24 | ||
22 | host = host or "diego.princeton.edu" | 25 | host = host or "diego.student.princeton.edu" |
23 | proxy = proxy or "http://localhost:3128" | 26 | proxy = proxy or "http://localhost:3128" |
24 | prefix = prefix or "/luasocket-test" | 27 | prefix = prefix or "/luasocket-test" |
25 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | 28 | cgiprefix = cgiprefix or "/luasocket-test-cgi" |
diff --git a/test/mimetest.lua b/test/mimetest.lua index 413a83b..d549ba6 100644 --- a/test/mimetest.lua +++ b/test/mimetest.lua | |||
@@ -8,7 +8,7 @@ local qptest = "qptest.bin" | |||
8 | local eqptest = "qptest.bin2" | 8 | local eqptest = "qptest.bin2" |
9 | local dqptest = "qptest.bin3" | 9 | local dqptest = "qptest.bin3" |
10 | 10 | ||
11 | local b64test = "luasocket.dll" | 11 | local b64test = "luasocket.so" |
12 | local eb64test = "b64test.bin" | 12 | local eb64test = "b64test.bin" |
13 | local db64test = "b64test.bin2" | 13 | local db64test = "b64test.bin2" |
14 | 14 | ||