From c703ee5f64394460e973dfb90a789d72ddd0f5e7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 28 Dec 2012 14:25:11 +0100 Subject: net.server_event: Remove comments about not closing event handlers from within callbacks, fixed in luaevent --- net/server_event.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'net') diff --git a/net/server_event.lua b/net/server_event.lua index f2626f5f..5316866e 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -6,7 +6,6 @@ notes: -- when using luaevent, never register 2 or more EV_READ at one socket, same for EV_WRITE -- you cant even register a new EV_READ/EV_WRITE callback inside another one - -- never call eventcallback:close( ) from inside eventcallback -- to do some of the above, use timeout events or something what will called from outside -- dont let garbagecollect eventcallbacks, as long they are running -- when using luasec, there are 4 cases of timeout errors: wantread or wantwrite during reading or writing @@ -248,7 +247,7 @@ do debug( "closing client with id:", self.id, self.fatalerror ) self:_lock( true, true, true ) -- first of all, lock the interface to avoid further actions local _ - _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks! + _ = self.eventread and self.eventread:close( ) if self.type == "client" then _ = self.eventwrite and self.eventwrite:close( ) _ = self.eventhandshake and self.eventhandshake:close( ) @@ -258,7 +257,7 @@ do _ = self.eventwritetimeout and self.eventwritetimeout:close( ) _ = self.eventreadtimeout and self.eventreadtimeout:close( ) _ = self.ondisconnect and self:ondisconnect( self.fatalerror ~= "client to close" and self.fatalerror) -- call ondisconnect listener (wont be the case if handshake failed on connect) - _ = self.conn and self.conn:close( ) -- close connection, must also be called outside of any socket registered events! + _ = self.conn and self.conn:close( ) -- close connection _ = self._server and self._server:counter(-1); self.eventread, self.eventwrite = nil, nil self.eventstarthandshake, self.eventhandshake, self.eventclose = nil, nil, nil @@ -342,7 +341,7 @@ do debug( "try to close server with id:", tostring(self.id)) self.fatalerror = "server to close" self:_lock( true ) - self:_close( 0 ) -- add new event to remove the server interface + self:_close( 0 ) return true end end -- cgit v1.2.3 From 966f062f889718a4d6a4b95a64f1c0d5d4b0f170 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 28 Dec 2012 14:26:21 +0100 Subject: net.server_event: Destroy interfaces immediately, fixes reopening of servers. --- net/server_event.lua | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'net') diff --git a/net/server_event.lua b/net/server_event.lua index 5316866e..e69530ff 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -120,14 +120,8 @@ do self.position = new_position or self.position return self.position; end - function interface_mt:_close() -- regs event to start self:_destroy() - local callback = function( ) - self:_destroy(); - self.eventclose = nil - return -1 - end - self.eventclose = addevent( base, nil, EV_TIMEOUT, callback, 0 ) - return true + function interface_mt:_close() + return self:_destroy(); end function interface_mt:_start_connection(plainssl) -- should be called from addclient -- cgit v1.2.3 From 387897f53f142e0cde5f8cffc8d40deae406386c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 28 Dec 2012 14:33:27 +0100 Subject: net.server_select: Add pause and resume methods --- net/server_select.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'net') diff --git a/net/server_select.lua b/net/server_select.lua index 8cb4e235..97c29b8c 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -197,6 +197,25 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco --mem_free( ) out_put "server.lua: closed server handler and removed sockets from list" end + handler.pause = function() + if not handler.paused then + socket:close( ) + _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) + _readlistlen = removesocket( _readlist, socket, _readlistlen ) + _socketlist[ socket ] = nil + socket = nil; + handler.paused = true; + end + end + handler.resume = function() + if handler.paused then + socket = socket_bind( ip, serverport ); + socket:settimeout( 0 ) + _readlistlen = addsocket(_readlist, socket, _readlistlen) + _socketlist[ socket ] = handler + handler.paused = false; + end + end handler.ip = function( ) return ip end -- cgit v1.2.3 From b0249c4d4a286172d1f548d0a65bf6154b34e1e8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 28 Dec 2012 14:33:27 +0100 Subject: net.server_select: Pause servers while they are full --- net/server_select.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'net') diff --git a/net/server_select.lua b/net/server_select.lua index 97c29b8c..97b9f199 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -185,6 +185,9 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco end handler.remove = function( ) connections = connections - 1 + if handler then + handler.resume( ) + end end handler.close = function() socket:close( ) @@ -227,6 +230,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco end handler.readbuffer = function( ) if connections > maxconnections then + handler.pause( ) out_put( "server.lua: refused new client connection: server full" ) return false end -- cgit v1.2.3