Merge 0.9->0.10
[prosody.git] / net / server_select.lua
index daad0f50fb7fd05abcf7f0dd25bb2d985ba643a2..486e953b6cb0269f3c1eb94b762fdc5be118e912 100644 (file)
@@ -285,6 +285,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
        local disconnect = listeners.ondisconnect
        local drain = listeners.ondrain
        local onreadtimeout = listeners.onreadtimeout;
+       local detach = listeners.ondetach
 
        local bufferqueue = { } -- buffer array
        local bufferqueuelen = 0        -- end of buffer array
@@ -316,11 +317,15 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
        handler.onreadtimeout = onreadtimeout;
 
        handler.setlistener = function( self, listeners )
+               if detach then
+                       detach(self) -- Notify listener that it is no longer responsible for this connection
+               end
                dispatch = listeners.onincoming
                disconnect = listeners.ondisconnect
                status = listeners.onstatus
                drain = listeners.ondrain
                handler.onreadtimeout = listeners.onreadtimeout
+               detach = listeners.ondetach
        end
        handler.getstats = function( )
                return readtraffic, sendtraffic
@@ -563,6 +568,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
                                                _ = status and status( handler, "ssl-handshake-complete" )
                                                if self.autostart_ssl and listeners.onconnect then
                                                        listeners.onconnect(self);
+                                                       if bufferqueuelen ~= 0 then
+                                                               _sendlistlen = addsocket(_sendlist, client, _sendlistlen)
+                                                       end
                                                end
                                                _readlistlen = addsocket(_readlist, client, _readlistlen)
                                                return true
@@ -709,6 +717,7 @@ local function link(sender, receiver, buffersize)
                        sender:lock_read(true);
                end
        end
+       sender:set_mode("*a");
 end
 
 ----------------------------------// PUBLIC //--
@@ -877,6 +886,8 @@ loop = function(once) -- this is the main loop of the program
                                        if not(handler.onreadtimeout) or handler:onreadtimeout() ~= true then
                                                handler.disconnect( )( handler, "read timeout" )
                                                handler:close( )        -- forced disconnect?
+                                       else
+                                               _readtimes[ handler ] = _currenttime -- reset timer
                                        end
                                end
                        end