aboutsummaryrefslogtreecommitdiffstats
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
commit58bb5f01fdc000bb77fb9e65d2b9eb51ad0d9a28 (patch)
tree385240a3cc3fa639d82cb948e2a7846f605b5f1c
parent0d7c7060984b1677c81e2a38089fabe7ebb9f79e (diff)
downloadprosody-58bb5f01fdc000bb77fb9e65d2b9eb51ad0d9a28.tar.gz
prosody-58bb5f01fdc000bb77fb9e65d2b9eb51ad0d9a28.zip
net.server_{select,event}: addclient: Add argument for overriding socket type
-rw-r--r--net/server_event.lua11
-rw-r--r--net/server_select.lua11
2 files changed, 18 insertions, 4 deletions
diff --git a/net/server_event.lua b/net/server_event.lua
index 7575044a..bc67d175 100644
--- a/net/server_event.lua
+++ b/net/server_event.lua
@@ -742,12 +742,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
diff --git a/net/server_select.lua b/net/server_select.lua
index 71db5006..537ff440 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -942,7 +942,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"
@@ -953,12 +953,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