net.server_select: Pass on all arguments to addclient on to wrapclient
[prosody.git] / net / server_select.lua
index 1665524f453a65af2c95b290186f6a4b18f88242..d5d272065bafaf8793bec36c9ee5252d874e3302 100644 (file)
@@ -1,7 +1,7 @@
--- 
+--
 -- server.lua by blastbeat of the luadch project
 -- Re-used here under the MIT/X Consortium License
--- 
+--
 -- Modifications (C) 2008-2010 Matthew Wild, Waqas Hussain
 --
 
@@ -150,7 +150,7 @@ _sendtimeout = 60000 -- allowed send idle time in secs
 _readtimeout = 6 * 60 * 60 -- allowed read idle time in secs
 
 local is_windows = package.config:sub(1,1) == "\\" -- check the directory separator, to detemine whether this is Windows
-_maxfd = luasocket._SETSIZE or (is_windows and math.huge) or 1024 -- max fd number, limit to 1024 by default to prevent glibc buffer overflow, but not on Windows
+_maxfd = (is_windows and math.huge) or luasocket._SETSIZE or 1024 -- max fd number, limit to 1024 by default to prevent glibc buffer overflow, but not on Windows
 _maxselectlen = luasocket._SETSIZE or 1024 -- But this still applies on Windows
 
 _maxsslhandshake = 30 -- max handshake round-trips
@@ -263,7 +263,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
        if socket:getfd() >= _maxfd then
                out_error("server.lua: Disallowed FD number: "..socket:getfd()) -- PROTIP: Switch to libevent
                socket:close( ) -- Should we send some kind of error here?
-               server.pause( )
+               if server then
+                       server.pause( )
+               end
                return nil, nil, "fd-too-large"
        end
        socket:settimeout( 0 )
@@ -605,7 +607,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
                        shutdown = id
                        _socketlist[ socket ] = handler
                        _readlistlen = addsocket(_readlist, socket, _readlistlen)
-                       
+
                        -- remove traces of the old socket
                        _readlistlen = removesocket( _readlist, oldsocket, _readlistlen )
                        _sendlistlen = removesocket( _sendlist, oldsocket, _sendlistlen )
@@ -693,7 +695,7 @@ local function link(sender, receiver, buffersize)
                        sender_locked = nil;
                end
        end
-       
+
        local _readbuffer = sender.readbuffer;
        function sender.readbuffer()
                _readbuffer();
@@ -935,7 +937,7 @@ local addclient = function( address, port, listeners, pattern, sslctx )
        client:settimeout( 0 )
        _, err = client:connect( address, port )
        if err then -- try again
-               local handler = wrapclient( client, address, port, listeners )
+               local handler = wrapclient( client, address, port, listeners, pattern, sslctx )
        else
                wrapconnection( nil, listeners, client, address, port, "clientport", pattern, sslctx )
        end
@@ -967,7 +969,7 @@ return {
 
        addclient = addclient,
        wrapclient = wrapclient,
-       
+
        loop = loop,
        link = link,
        step = step,