Comparison

net/server_select.lua @ 5965:99d55f12a26f

net.server_{select,event}: addclient: Add argument for overriding socket type
author Kim Alvefur <zash@zash.se>
date Mon, 23 Dec 2013 17:55:41 +0100
parent 5961:5745bb2b6890
child 5966:958ad646c0f2
comparison
equal deleted inserted replaced
5964:ad04170d6533 5965:99d55f12a26f
928 end 928 end
929 end 929 end
930 return handler, socket 930 return handler, socket
931 end 931 end
932 932
933 local addclient = function( address, port, listeners, pattern, sslctx ) 933 local addclient = function( address, port, listeners, pattern, sslctx, typ )
934 local err 934 local err
935 if type( listeners ) ~= "table" then 935 if type( listeners ) ~= "table" then
936 err = "invalid listener table" 936 err = "invalid listener table"
937 elseif type ( address ) ~= "string" then 937 elseif type ( address ) ~= "string" then
938 err = "invalid address" 938 err = "invalid address"
939 elseif type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then 939 elseif type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then
940 err = "invalid port" 940 err = "invalid port"
941 elseif sslctx and not has_luasec then 941 elseif sslctx and not has_luasec then
942 err = "luasec not found" 942 err = "luasec not found"
943 end 943 end
944 if not typ then
945 typ = "tcp"
946 end
947 local create = luasocket[typ]
948 if type( create ) ~= "function" then
949 err = "invalid socket type"
950 end
944 if err then 951 if err then
945 out_error( "server.lua, addclient: ", err ) 952 out_error( "server.lua, addclient: ", err )
946 return nil, err 953 return nil, err
947 end 954 end
948 955
949 local client, err = luasocket.tcp( ) 956 local client, err = create( )
950 if err then 957 if err then
951 return nil, err 958 return nil, err
952 end 959 end
953 client:settimeout( 0 ) 960 client:settimeout( 0 )
954 local ok, err = client:connect( address, port ) 961 local ok, err = client:connect( address, port )