aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_select.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-09-01 01:55:55 +0200
committerKim Alvefur <zash@zash.se>2019-09-01 01:55:55 +0200
commit9a6332e037265977a9ba8075ede746af0ab32961 (patch)
tree34d632de89573f0c4aebf7c9282e50aa9105e274 /net/server_select.lua
parent4cbaf2e6479906b22f20319423a43c4da9d05884 (diff)
downloadprosody-9a6332e037265977a9ba8075ede746af0ab32961.tar.gz
prosody-9a6332e037265977a9ba8075ede746af0ab32961.zip
net.server: Accept and save an 'extra' field for client connections
This lets code attach some extra data to be attached to client connections.
Diffstat (limited to 'net/server_select.lua')
-rw-r--r--net/server_select.lua12
1 files changed, 7 insertions, 5 deletions
diff --git a/net/server_select.lua b/net/server_select.lua
index e14c126e..de183331 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -266,7 +266,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, ssldi
return handler
end
-wrapconnection = function( server, listeners, socket, ip, serverport, clientport, pattern, sslctx, ssldirect ) -- this function wraps a client to a handler object
+wrapconnection = function( server, listeners, socket, ip, serverport, clientport, pattern, sslctx, ssldirect, extra ) -- this function wraps a client to a handler object
if socket:getfd() >= _maxfd then
out_error("server.lua: Disallowed FD number: "..socket:getfd()) -- PROTIP: Switch to libevent
@@ -316,6 +316,8 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
local handler = bufferqueue -- saves a table ^_^
+ handler.extra = extra
+
handler.dispatch = function( )
return dispatch
end
@@ -1005,8 +1007,8 @@ end
--// EXPERIMENTAL //--
-local wrapclient = function( socket, ip, serverport, listeners, pattern, sslctx )
- local handler, socket, err = wrapconnection( nil, listeners, socket, ip, serverport, "clientport", pattern, sslctx, sslctx)
+local wrapclient = function( socket, ip, serverport, listeners, pattern, sslctx, extra )
+ local handler, socket, err = wrapconnection( nil, listeners, socket, ip, serverport, "clientport", pattern, sslctx, sslctx, extra)
if not handler then return nil, err end
_socketlist[ socket ] = handler
if not sslctx then
@@ -1025,7 +1027,7 @@ local wrapclient = function( socket, ip, serverport, listeners, pattern, sslctx
return handler, socket
end
-local addclient = function( address, port, listeners, pattern, sslctx, typ )
+local addclient = function( address, port, listeners, pattern, sslctx, typ, extra )
local err
if type( listeners ) ~= "table" then
err = "invalid listener table"
@@ -1062,7 +1064,7 @@ local addclient = function( address, port, listeners, pattern, sslctx, typ )
client:settimeout( 0 )
local ok, err = client:setpeername( address, port )
if ok or err == "timeout" or err == "Operation already in progress" then
- return wrapclient( client, address, port, listeners, pattern, sslctx )
+ return wrapclient( client, address, port, listeners, pattern, sslctx, extra )
else
return nil, err
end