Comparison

net/server_select.lua @ 6812:7af63377a1cf

net/server_select: Check arguments to add_server correctly
author daurnimator <quae@daurnimator.com>
date Wed, 18 Dec 2013 17:51:27 -0500
parent 6782:ec172dbe9d14
child 6813:b1615fa62e59
comparison
equal deleted inserted replaced
6810:533fd843d91f 6812:7af63377a1cf
721 end 721 end
722 722
723 ----------------------------------// PUBLIC //-- 723 ----------------------------------// PUBLIC //--
724 724
725 addserver = function( addr, port, listeners, pattern, sslctx ) -- this function provides a way for other scripts to reg a server 725 addserver = function( addr, port, listeners, pattern, sslctx ) -- this function provides a way for other scripts to reg a server
726 addr = addr or "*"
726 local err 727 local err
727 if type( listeners ) ~= "table" then 728 if type( listeners ) ~= "table" then
728 err = "invalid listener table" 729 err = "invalid listener table"
729 end 730 elseif type ( addr ) ~= "string" then
730 if type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then 731 err = "invalid address"
732 elseif type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then
731 err = "invalid port" 733 err = "invalid port"
732 elseif _server[ addr..":"..port ] then 734 elseif _server[ addr..":"..port ] then
733 err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist" 735 err = "listeners on '[" .. addr .. "]:" .. port .. "' already exist"
734 elseif sslctx and not has_luasec then 736 elseif sslctx and not has_luasec then
735 err = "luasec not found" 737 err = "luasec not found"
736 end 738 end
737 if err then 739 if err then
738 out_error( "server.lua, [", addr, "]:", port, ": ", err ) 740 out_error( "server.lua, [", addr, "]:", port, ": ", err )
739 return nil, err 741 return nil, err
740 end 742 end
741 addr = addr or "*"
742 local server, err = socket_bind( addr, port, _tcpbacklog ) 743 local server, err = socket_bind( addr, port, _tcpbacklog )
743 if err then 744 if err then
744 out_error( "server.lua, [", addr, "]:", port, ": ", err ) 745 out_error( "server.lua, [", addr, "]:", port, ": ", err )
745 return nil, err 746 return nil, err
746 end 747 end