aboutsummaryrefslogtreecommitdiff
path: root/src/tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tcp.c')
-rw-r--r--src/tcp.c22
1 files changed, 4 insertions, 18 deletions
diff --git a/src/tcp.c b/src/tcp.c
index 9e1e2bd..94148c5 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -308,27 +308,13 @@ static int meth_listen(lua_State *L)
308\*-------------------------------------------------------------------------*/ 308\*-------------------------------------------------------------------------*/
309static int meth_shutdown(lua_State *L) 309static 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;
329error:
330 luaL_argerror(L, 2, "invalid shutdown method");
331 return 0;
332} 318}
333 319
334/*-------------------------------------------------------------------------*\ 320/*-------------------------------------------------------------------------*\