Comparison

net/server_select.lua @ 6818:ae9d1289a868

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 6815:46546d57f639
child 6819:ffb2b5e31456
comparison
equal deleted inserted replaced
6817:07f43c7aa059 6818:ae9d1289a868
940 end 940 end
941 end 941 end
942 return handler, socket 942 return handler, socket
943 end 943 end
944 944
945 local addclient = function( address, port, listeners, pattern, sslctx ) 945 local addclient = function( address, port, listeners, pattern, sslctx, typ )
946 local err 946 local err
947 if type( listeners ) ~= "table" then 947 if type( listeners ) ~= "table" then
948 err = "invalid listener table" 948 err = "invalid listener table"
949 elseif type ( address ) ~= "string" then 949 elseif type ( address ) ~= "string" then
950 err = "invalid address" 950 err = "invalid address"
951 elseif type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then 951 elseif type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then
952 err = "invalid port" 952 err = "invalid port"
953 elseif sslctx and not has_luasec then 953 elseif sslctx and not has_luasec then
954 err = "luasec not found" 954 err = "luasec not found"
955 end 955 end
956 if not typ then
957 typ = "tcp"
958 end
959 local create = luasocket[typ]
960 if type( create ) ~= "function" then
961 err = "invalid socket type"
962 end
956 if err then 963 if err then
957 out_error( "server.lua, addclient: ", err ) 964 out_error( "server.lua, addclient: ", err )
958 return nil, err 965 return nil, err
959 end 966 end
960 967
961 local client, err = luasocket.tcp( ) 968 local client, err = create( )
962 if err then 969 if err then
963 return nil, err 970 return nil, err
964 end 971 end
965 client:settimeout( 0 ) 972 client:settimeout( 0 )
966 local ok, err = client:connect( address, port ) 973 local ok, err = client:connect( address, port )