# HG changeset patch # User Kim Alvefur # Date 1387817741 -3600 # Node ID 99d55f12a26f4c5d470409c2b0864f43cf6f655e # Parent ad04170d653315d422197a260a3e6d07d2f4e154 net.server_{select,event}: addclient: Add argument for overriding socket type diff -r ad04170d6533 -r 99d55f12a26f net/server_event.lua --- a/net/server_event.lua Wed Dec 18 19:00:24 2013 -0500 +++ b/net/server_event.lua Mon Dec 23 17:55:41 2013 +0100 @@ -736,12 +736,19 @@ --function handleclient( client, ip, port, server, pattern, listener, _, sslctx ) -- creates an client interface end - function addclient( addr, serverport, listener, pattern, sslctx ) + function addclient( addr, serverport, listener, pattern, sslctx, typ ) if sslctx and not has_luasec then debug "need luasec, but not available" return nil, "luasec not found" end - local client, err = socket.tcp() -- creating new socket + if not typ then + typ = "tcp" + end + local create = socket[typ] + if type( create ) ~= "function" then + return nil, "invalid socket type" + end + local client, err = create() -- creating new socket if not client then debug( "cannot create socket:", err ) return nil, err @@ -749,8 +756,10 @@ client:settimeout( 0 ) -- set nonblocking local res, err = client:connect( addr, serverport ) -- connect if res or ( err == "timeout" ) then - local ip, port = client:getsockname( ) - local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx ) + if client.getsockname then + addr = client:getsockname( ) + end + local interface = wrapclient( client, addr, serverport, listener, pattern, sslctx ) debug( "new connection id:", interface.id ) return interface, err else diff -r ad04170d6533 -r 99d55f12a26f net/server_select.lua --- a/net/server_select.lua Wed Dec 18 19:00:24 2013 -0500 +++ b/net/server_select.lua Mon Dec 23 17:55:41 2013 +0100 @@ -930,7 +930,7 @@ return handler, socket end -local addclient = function( address, port, listeners, pattern, sslctx ) +local addclient = function( address, port, listeners, pattern, sslctx, typ ) local err if type( listeners ) ~= "table" then err = "invalid listener table" @@ -941,12 +941,19 @@ elseif sslctx and not has_luasec then err = "luasec not found" end + if not typ then + typ = "tcp" + end + local create = luasocket[typ] + if type( create ) ~= "function" then + err = "invalid socket type" + end if err then out_error( "server.lua, addclient: ", err ) return nil, err end - local client, err = luasocket.tcp( ) + local client, err = create( ) if err then return nil, err end