mirror of
				https://github.com/lunarmodules/luasocket.git
				synced 2025-10-31 10:25:55 +01:00 
			
		
		
		
	:shutdown() errors on all invalid argument strings
It used to error only on invalid argument strings that started with 's', 'r', or 'b'.
This commit is contained in:
		
							
								
								
									
										22
									
								
								src/tcp.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/tcp.c
									
									
									
									
									
								
							| @@ -308,27 +308,13 @@ static int meth_listen(lua_State *L) | |||||||
| \*-------------------------------------------------------------------------*/ | \*-------------------------------------------------------------------------*/ | ||||||
| static int meth_shutdown(lua_State *L) | static int meth_shutdown(lua_State *L) | ||||||
| { | { | ||||||
|  |     /* SHUT_RD,  SHUT_WR,  SHUT_RDWR  have  the value 0, 1, 2, so we can use method index directly */ | ||||||
|  |     static const char* methods[] = { "receive", "send", "both", NULL }; | ||||||
|     p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{client}", 1); |     p_tcp tcp = (p_tcp) auxiliar_checkclass(L, "tcp{client}", 1); | ||||||
|     const char *how = luaL_optstring(L, 2, "both"); |     int how = luaL_checkoption(L, 2, "both", methods); | ||||||
|     switch (how[0]) { |     socket_shutdown(&tcp->sock, how); | ||||||
|         case 'b': |  | ||||||
|             if (strcmp(how, "both")) goto error; |  | ||||||
|             socket_shutdown(&tcp->sock, 2); |  | ||||||
|             break; |  | ||||||
|         case 's': |  | ||||||
|             if (strcmp(how, "send")) goto error; |  | ||||||
|             socket_shutdown(&tcp->sock, 1); |  | ||||||
|             break; |  | ||||||
|         case 'r': |  | ||||||
|             if (strcmp(how, "receive")) goto error; |  | ||||||
|             socket_shutdown(&tcp->sock, 0); |  | ||||||
|             break; |  | ||||||
|     } |  | ||||||
|     lua_pushnumber(L, 1); |     lua_pushnumber(L, 1); | ||||||
|     return 1; |     return 1; | ||||||
| error: |  | ||||||
|     luaL_argerror(L, 2, "invalid shutdown method"); |  | ||||||
|     return 0; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /*-------------------------------------------------------------------------*\ | /*-------------------------------------------------------------------------*\ | ||||||
|   | |||||||
							
								
								
									
										24
									
								
								src/unix.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/unix.c
									
									
									
									
									
								
							| @@ -292,27 +292,13 @@ static int meth_listen(lua_State *L) | |||||||
| \*-------------------------------------------------------------------------*/ | \*-------------------------------------------------------------------------*/ | ||||||
| static int meth_shutdown(lua_State *L) | static int meth_shutdown(lua_State *L) | ||||||
| { | { | ||||||
|     p_unix un = (p_unix) auxiliar_checkclass(L, "unix{client}", 1); |     /* SHUT_RD,  SHUT_WR,  SHUT_RDWR  have  the value 0, 1, 2, so we can use method index directly */ | ||||||
|     const char *how = luaL_optstring(L, 2, "both"); |     static const char* methods[] = { "receive", "send", "both", NULL }; | ||||||
|     switch (how[0]) { |     p_unix tcp = (p_unix) auxiliar_checkclass(L, "unix{client}", 1); | ||||||
|         case 'b': |     int how = luaL_checkoption(L, 2, "both", methods); | ||||||
|             if (strcmp(how, "both")) goto error; |     socket_shutdown(&tcp->sock, how); | ||||||
|             socket_shutdown(&un->sock, 2); |  | ||||||
|             break; |  | ||||||
|         case 's': |  | ||||||
|             if (strcmp(how, "send")) goto error; |  | ||||||
|             socket_shutdown(&un->sock, 1); |  | ||||||
|             break; |  | ||||||
|         case 'r': |  | ||||||
|             if (strcmp(how, "receive")) goto error; |  | ||||||
|             socket_shutdown(&un->sock, 0); |  | ||||||
|             break; |  | ||||||
|     } |  | ||||||
|     lua_pushnumber(L, 1); |     lua_pushnumber(L, 1); | ||||||
|     return 1; |     return 1; | ||||||
| error: |  | ||||||
|     luaL_argerror(L, 2, "invalid shutdown method"); |  | ||||||
|     return 0; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /*-------------------------------------------------------------------------*\ | /*-------------------------------------------------------------------------*\ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user