aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-02-23 15:30:00 +0000
committerMatthew Wild <mwild1@gmail.com>2018-02-23 15:30:00 +0000
commit17f7c8bc3a0b9ede9507c39245cddd8f1260cc7e (patch)
tree396e06b6e413da3e1699551a2deef98cf608447a
parentdedbe4d9949425353c321c51721ae11cf1de09a1 (diff)
downloadprosody-17f7c8bc3a0b9ede9507c39245cddd8f1260cc7e.tar.gz
prosody-17f7c8bc3a0b9ede9507c39245cddd8f1260cc7e.zip
net.server_select: Better detection of errors for outgoing connections
On connection failure, a socket is marked readable and writable. So to detect initial connection failures (connection refused, etc.) we now watch for sockets becoming readable during initial connection, and also read from readable sockets before writing to writable sockets. This should fix 'onconnect' being called for outgoing connections that actually failed.
-rw-r--r--net/server_select.lua13
1 files changed, 7 insertions, 6 deletions
diff --git a/net/server_select.lua b/net/server_select.lua
index f051da24..31c6306f 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -905,22 +905,22 @@ loop = function(once) -- this is the main loop of the program
end
local read, write, err = socket_select( _readlist, _sendlist, math_min(_selecttimeout, next_timer_time) )
- for _, socket in ipairs( write ) do -- send data waiting in writequeues
+ for _, socket in ipairs( read ) do -- receive data
local handler = _socketlist[ socket ]
if handler then
- handler.sendbuffer( )
+ handler.readbuffer( )
else
closesocket( socket )
- out_put "server.lua: found no handler and closed socket (writelist)" -- this should not happen
+ out_put "server.lua: found no handler and closed socket (readlist)" -- this can happen
end
end
- for _, socket in ipairs( read ) do -- receive data
+ for _, socket in ipairs( write ) do -- send data waiting in writequeues
local handler = _socketlist[ socket ]
if handler then
- handler.readbuffer( )
+ handler.sendbuffer( )
else
closesocket( socket )
- out_put "server.lua: found no handler and closed socket (readlist)" -- this can happen
+ out_put "server.lua: found no handler and closed socket (writelist)" -- this should not happen
end
end
for handler, err in pairs( _closelist ) do
@@ -978,6 +978,7 @@ local wrapclient = function( socket, ip, serverport, listeners, pattern, sslctx
if not handler then return nil, err end
_socketlist[ socket ] = handler
if not sslctx then
+ _readlistlen = addsocket(_readlist, socket, _readlistlen)
_sendlistlen = addsocket(_sendlist, socket, _sendlistlen)
if listeners.onconnect then
-- When socket is writeable, call onconnect