aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-07-16 22:28:50 +0100
committerMatthew Wild <mwild1@gmail.com>2010-07-16 22:28:50 +0100
commitb0c03f83ced2271d0939cdd57324db469d75e31a (patch)
tree69c087229dca5c7e45c5146c06442defb60eec43 /net
parentdd08ddb30b0dff37bfda45bc408d7e9c4c670ea8 (diff)
downloadprosody-b0c03f83ced2271d0939cdd57324db469d75e31a.tar.gz
prosody-b0c03f83ced2271d0939cdd57324db469d75e31a.zip
net.server_select: Ensure that onconnect is called for server sockets as well as clients, rather than onincoming. Fixes mod_console traceback, issue #197
Diffstat (limited to 'net')
-rw-r--r--net/server_select.lua24
1 files changed, 13 insertions, 11 deletions
diff --git a/net/server_select.lua b/net/server_select.lua
index 298e560a..12cbc621 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -167,7 +167,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco
local connections = 0
- local dispatch, disconnect = listeners.onincoming, listeners.ondisconnect
+ local dispatch, disconnect = listeners.onconnect or listeners.onincoming, listeners.ondisconnect
local accept = socket.accept
@@ -623,16 +623,6 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
_socketlist[ socket ] = handler
_readlistlen = addsocket(_readlist, socket, _readlistlen)
- if listeners.onconnect then
- _sendlistlen = addsocket(_sendlist, socket, _sendlistlen)
- handler.sendbuffer = function ()
- listeners.onconnect(handler);
- handler.sendbuffer = _sendbuffer;
- if bufferqueuelen > 0 then
- return _sendbuffer();
- end
- end
- end
return handler, socket
end
@@ -854,6 +844,18 @@ local wrapclient = function( socket, ip, serverport, listeners, pattern, sslctx
local handler = wrapconnection( nil, listeners, socket, ip, serverport, "clientport", pattern, sslctx )
_socketlist[ socket ] = handler
_sendlistlen = addsocket(_sendlist, socket, _sendlistlen)
+ if listeners.onconnect then
+ -- When socket is writeable, call onconnect
+ local _sendbuffer = handler.sendbuffer;
+ handler.sendbuffer = function ()
+ listeners.onconnect(handler);
+ handler.sendbuffer = _sendbuffer;
+ -- If there was data with the incoming packet, handle it now.
+ if #handler:bufferqueue() > 0 then
+ return _sendbuffer();
+ end
+ end
+ end
return handler, socket
end