Changeset

7094:e8f202856fc0

server_select: Keep track of which server listeners are full
author Kim Alvefur <zash@zash.se>
date Fri, 22 Jan 2016 01:58:39 +0100
parents 7093:388281be2bc7
children 7095:3e1dac35af87
files net/server_select.lua
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/net/server_select.lua	Thu Jan 21 22:26:46 2016 +0100
+++ b/net/server_select.lua	Fri Jan 22 01:58:39 2016 +0100
@@ -88,6 +88,7 @@
 local _closelist
 local _readtimes
 local _writetimes
+local _fullservers
 
 --// simple data types //--
 
@@ -130,6 +131,7 @@
 _readtimes = { } -- key = handler, value = timestamp of last data reading
 _writetimes = { } -- key = handler, value = timestamp of last data writing/sending
 _closelist = { } -- handlers to close
+_fullservers = { } -- servers in a paused state while there are too many clients
 
 _readlistlen = 0 -- length of readlist
 _sendlistlen = 0 -- length of sendlist
@@ -219,6 +221,7 @@
 			end
 			_readlistlen = addsocket(_readlist, socket, _readlistlen)
 			_socketlist[ socket ] = handler
+			_fullservers[ handler ] = nil
 			handler.paused = false;
 		end
 	end
@@ -234,6 +237,7 @@
 	handler.readbuffer = function( )
 		if _readlistlen >= _maxselectlen or _sendlistlen >= _maxselectlen then
 			handler.pause( )
+			_fullservers[ handler ] = _currenttime
 			out_put( "server.lua: refused new client connection: server full" )
 			return false
 		end
@@ -264,6 +268,7 @@
 		out_error("server.lua: Disallowed FD number: "..socket:getfd()) -- PROTIP: Switch to libevent
 		socket:close( ) -- Should we send some kind of error here?
 		if server then
+			_fullservers[ server ] = _currenttime
 			server.pause( )
 		end
 		return nil, nil, "fd-too-large"