# HG changeset patch # User Matthew Wild # Date 1279315730 -3600 # Node ID fea0f8e19e4c09df68d92c48a1f400f1779ff100 # Parent 28cb5ad728707d932d703d03689f2f876ab99d85 net.server_select: Ensure that onconnect is called for server sockets as well as clients, rather than onincoming. Fixes mod_console traceback, issue #197 diff -r 28cb5ad72870 -r fea0f8e19e4c net/server_select.lua --- a/net/server_select.lua Fri Jul 16 16:53:54 2010 +0100 +++ b/net/server_select.lua Fri Jul 16 22:28:50 2010 +0100 @@ -167,7 +167,7 @@ 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 @@ _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 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