aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_event.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2013-12-23 17:55:41 +0100
committerKim Alvefur <zash@zash.se>2013-12-23 17:55:41 +0100
commit3e156487cff0779f075a765451cacb2a7c47b52c (patch)
treef168330bb6ef7081313505a401411ce04f24dd77 /net/server_event.lua
parent5c25cdaa77b2868e99e6ff97d7fd4fe34e115773 (diff)
downloadprosody-3e156487cff0779f075a765451cacb2a7c47b52c.tar.gz
prosody-3e156487cff0779f075a765451cacb2a7c47b52c.zip
net.server_{select,event}: addclient: Add argument for overriding socket type
Diffstat (limited to 'net/server_event.lua')
-rw-r--r--net/server_event.lua17
1 files changed, 13 insertions, 4 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