Comparison

net/server_select.lua @ 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
parent 5956:59997f3f5502
child 5959:9e3b15199ec5
comparison
equal deleted inserted replaced
5956:59997f3f5502 5957:3c5061d937dd
711 end 711 end
712 712
713 ----------------------------------// PUBLIC //-- 713 ----------------------------------// PUBLIC //--
714 714
715 addserver = function( addr, port, listeners, pattern, sslctx ) -- this function provides a way for other scripts to reg a server 715 addserver = function( addr, port, listeners, pattern, sslctx ) -- this function provides a way for other scripts to reg a server
716 addr = addr or "*"
716 local err 717 local err
717 if type( listeners ) ~= "table" then 718 if type( listeners ) ~= "table" then
718 err = "invalid listener table" 719 err = "invalid listener table"
719 end 720 elseif type ( addr ) ~= "string" then
720 if type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then 721 err = "invalid address"
722 elseif type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then
721 err = "invalid port" 723 err = "invalid port"
722 elseif _server[ addr..":"..port ] then 724 elseif _server[ addr..":"..port ] then
723 err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist" 725 err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist"
724 elseif sslctx and not has_luasec then 726 elseif sslctx and not has_luasec then
725 err = "luasec not found" 727 err = "luasec not found"
726 end 728 end
727 if err then 729 if err then
728 out_error( "server.lua, [", addr, "]:", port, ": ", err ) 730 out_error( "server.lua, [", addr, "]:", port, ": ", err )
729 return nil, err 731 return nil, err
730 end 732 end
731 addr = addr or "*"
732 local server, err = socket_bind( addr, port, _tcpbacklog ) 733 local server, err = socket_bind( addr, port, _tcpbacklog )
733 if err then 734 if err then
734 out_error( "server.lua, [", addr, "]:", port, ": ", err ) 735 out_error( "server.lua, [", addr, "]:", port, ": ", err )
735 return nil, err 736 return nil, err
736 end 737 end