aboutsummaryrefslogtreecommitdiff
path: root/src/unix.c
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2012-04-26 16:50:27 -0700
committerSam Roberts <vieuxtech@gmail.com>2012-04-26 16:50:27 -0700
commite86eac96fa69eb59f878abf005ac7cedbfaf5736 (patch)
tree79ee2705ffd5cbacebbd2b40639043f7146a1b4c /src/unix.c
parent30d1aae140db85501672983481a987418eeba2ed (diff)
downloadluasocket-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'.
Diffstat (limited to 'src/unix.c')
-rw-r--r--src/unix.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/unix.c b/src/unix.c
index f972738..73e7b69 100644
--- a/src/unix.c
+++ b/src/unix.c
@@ -292,27 +292,13 @@ static int meth_listen(lua_State *L)
292\*-------------------------------------------------------------------------*/ 292\*-------------------------------------------------------------------------*/
293static int meth_shutdown(lua_State *L) 293static 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;
313error:
314 luaL_argerror(L, 2, "invalid shutdown method");
315 return 0;
316} 302}
317 303
318/*-------------------------------------------------------------------------*\ 304/*-------------------------------------------------------------------------*\