# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1462368551 -7200
# Node ID 3fc5560557a566daa5595de1f0e7ec7f7c382545
# Parent  325c03f5481bb3b1e21735bc47665bf3edaa07ab
net.server_event: Schedule another read callback if there is still data left in buffer after reading (fixes #583 for real)

diff -r 325c03f5481b -r 3fc5560557a5 net/server_event.lua
--- a/net/server_event.lua	Wed May 04 15:20:33 2016 +0200
+++ b/net/server_event.lua	Wed May 04 15:29:11 2016 +0200
@@ -30,6 +30,7 @@
 	WRITE_TIMEOUT         = 180,  -- timeout in seconds for write data on socket
 	CONNECT_TIMEOUT       = 20,  -- timeout in seconds for connection attempts
 	CLEAR_DELAY           = 5,  -- seconds to wait for clearing interface list (and calling ondisconnect listeners)
+	READ_RETRY_DELAY      = 1e-06, -- if, after reading, there is still data in buffer, wait this long and continue reading
 	DEBUG                 = true,  -- show debug messages
 }
 
@@ -559,7 +560,7 @@
 			interface.eventread = nil
 			return -1
 		end
-		if EV_TIMEOUT == event and interface:onreadtimeout() ~= true then
+		if EV_TIMEOUT == event and not interface.conn:dirty() and interface:onreadtimeout() ~= true then
 			return -1 -- took too long to get some data from client -> disconnect
 		end
 		if interface._usingssl then  -- handle luasec
@@ -605,6 +606,9 @@
 			interface.eventread = nil;
 			return -1;
 		end
+		if interface.conn:dirty() then -- still data left in buffer
+			return EV_TIMEOUT, cfg.READ_RETRY_DELAY;
+		end
 		return EV_READ, cfg.READ_TIMEOUT
 	end