From f2af5505314d8b8502fb1bc5b9549abfa7376b89 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/server_select.lua') 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 de47f7e8361773e32f8278c6ae305e1a08636285 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/server_select.lua') 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