diff options
author | Kim Alvefur <zash@zash.se> | 2013-12-23 17:55:41 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2013-12-23 17:55:41 +0100 |
commit | 24118d8f74b097bf71f61d240c855ff5655e510d (patch) | |
tree | f168330bb6ef7081313505a401411ce04f24dd77 /net | |
parent | 8184587aa4a1ace6268e9ceb2059f1c72bf14633 (diff) | |
download | prosody-24118d8f74b097bf71f61d240c855ff5655e510d.tar.gz prosody-24118d8f74b097bf71f61d240c855ff5655e510d.zip |
net.server_{select,event}: addclient: Add argument for overriding socket type
Diffstat (limited to 'net')
-rw-r--r-- | net/server_event.lua | 17 | ||||
-rw-r--r-- | net/server_select.lua | 11 |
2 files changed, 22 insertions, 6 deletions
diff --git a/net/server_event.lua b/net/server_event.lua index 81dc4512..ae64d50e 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -736,12 +736,19 @@ do --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 @@ do 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 --git a/net/server_select.lua b/net/server_select.lua index 91b8b01f..1ce3c8c7 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -930,7 +930,7 @@ local wrapclient = function( socket, ip, serverport, listeners, pattern, sslctx 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 @@ local addclient = function( address, port, listeners, pattern, sslctx ) 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 |