diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2012-04-26 16:50:27 -0700 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2012-04-26 16:50:27 -0700 |
commit | e86eac96fa69eb59f878abf005ac7cedbfaf5736 (patch) | |
tree | 79ee2705ffd5cbacebbd2b40639043f7146a1b4c | |
parent | 30d1aae140db85501672983481a987418eeba2ed (diff) | |
download | luasocket-e86eac96fa69eb59f878abf005ac7cedbfaf5736.tar.gz luasocket-e86eac96fa69eb59f878abf005ac7cedbfaf5736.tar.bz2 luasocket-e86eac96fa69eb59f878abf005ac7cedbfaf5736.zip |
:shutdown() errors on all invalid argument strings
It used to error only on invalid argument strings that started with 's',
'r', or 'b'.
-rw-r--r-- | src/tcp.c | 22 | ||||
-rw-r--r-- | src/unix.c | 24 |
2 files changed, 9 insertions, 37 deletions
@@ -308,27 +308,13 @@ static int meth_listen(lua_State *L) | |||
308 | \*-------------------------------------------------------------------------*/ | 308 | \*-------------------------------------------------------------------------*/ |
309 | static int meth_shutdown(lua_State *L) | 309 | static int meth_shutdown(lua_State *L) |
310 | { | 310 | { |
311 | /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ | ||
312 | static const char* methods[] = { "receive", "send", "both", NULL }; | ||
311 | p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{client}", 1); | 313 | p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{client}", 1); |
312 | const char *how = luaL_optstring(L, 2, "both"); | 314 | int how = luaL_checkoption(L, 2, "both", methods); |
313 | switch (how[0]) { | 315 | socket_shutdown(&tcp->sock, how); |
314 | case 'b': | ||
315 | if (strcmp(how, "both")) goto error; | ||
316 | socket_shutdown(&tcp->sock, 2); | ||
317 | break; | ||
318 | case 's': | ||
319 | if (strcmp(how, "send")) goto error; | ||
320 | socket_shutdown(&tcp->sock, 1); | ||
321 | break; | ||
322 | case 'r': | ||
323 | if (strcmp(how, "receive")) goto error; | ||
324 | socket_shutdown(&tcp->sock, 0); | ||
325 | break; | ||
326 | } | ||
327 | lua_pushnumber(L, 1); | 316 | lua_pushnumber(L, 1); |
328 | return 1; | 317 | return 1; |
329 | error: | ||
330 | luaL_argerror(L, 2, "invalid shutdown method"); | ||
331 | return 0; | ||
332 | } | 318 | } |
333 | 319 | ||
334 | /*-------------------------------------------------------------------------*\ | 320 | /*-------------------------------------------------------------------------*\ |
@@ -292,27 +292,13 @@ static int meth_listen(lua_State *L) | |||
292 | \*-------------------------------------------------------------------------*/ | 292 | \*-------------------------------------------------------------------------*/ |
293 | static int meth_shutdown(lua_State *L) | 293 | static int meth_shutdown(lua_State *L) |
294 | { | 294 | { |
295 | p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1); | 295 | /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ |
296 | const char *how = luaL_optstring(L, 2, "both"); | 296 | static const char* methods[] = { "receive", "send", "both", NULL }; |
297 | switch (how[0]) { | 297 | p_unix tcp = (p_unix) auxiliar_checkclass(L, "unix{client}", 1); |
298 | case 'b': | 298 | int how = luaL_checkoption(L, 2, "both", methods); |
299 | if (strcmp(how, "both")) goto error; | 299 | socket_shutdown(&tcp->sock, how); |
300 | socket_shutdown(&un->sock, 2); | ||
301 | break; | ||
302 | case 's': | ||
303 | if (strcmp(how, "send")) goto error; | ||
304 | socket_shutdown(&un->sock, 1); | ||
305 | break; | ||
306 | case 'r': | ||
307 | if (strcmp(how, "receive")) goto error; | ||
308 | socket_shutdown(&un->sock, 0); | ||
309 | break; | ||
310 | } | ||
311 | lua_pushnumber(L, 1); | 300 | lua_pushnumber(L, 1); |
312 | return 1; | 301 | return 1; |
313 | error: | ||
314 | luaL_argerror(L, 2, "invalid shutdown method"); | ||
315 | return 0; | ||
316 | } | 302 | } |
317 | 303 | ||
318 | /*-------------------------------------------------------------------------*\ | 304 | /*-------------------------------------------------------------------------*\ |