Changeset

5957:3c5061d937dd

net/server_select: Check arguments to add_server correctly
author daurnimator <quae@daurnimator.com>
date Wed, 18 Dec 2013 17:51:27 -0500
parents 5956:59997f3f5502
children 5958:451b4649fad2
files net/server_select.lua
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/net/server_select.lua	Wed Dec 18 17:50:38 2013 -0500
+++ b/net/server_select.lua	Wed Dec 18 17:51:27 2013 -0500
@@ -713,11 +713,13 @@
 ----------------------------------// PUBLIC //--
 
 addserver = function( addr, port, listeners, pattern, sslctx ) -- this function provides a way for other scripts to reg a server
+	addr = addr or "*"
 	local err
 	if type( listeners ) ~= "table" then
 		err = "invalid listener table"
-	end
-	if type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then
+	elseif type ( addr ) ~= "string" then
+		err = "invalid address"
+	elseif type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then
 		err = "invalid port"
 	elseif _server[ addr..":"..port ] then
 		err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist"
@@ -728,7 +730,6 @@
 		out_error( "server.lua, [", addr, "]:", port, ": ", err )
 		return nil, err
 	end
-	addr = addr or "*"
 	local server, err = socket_bind( addr, port, _tcpbacklog )
 	if err then
 		out_error( "server.lua, [", addr, "]:", port, ": ", err )