Changeset

1585:64f55bcab9f7

mod_statistics/prosodytop.lua: Simplify and fix buffering and line separation (thanks Ge0rG)
author Kim Alvefur <zash@zash.se>
date Mon, 08 Dec 2014 17:04:49 +0100
parents 1584:4713f9d453ec
children 1586:b51e596c5a02
files mod_statistics/prosodytop.lua
diffstat 1 files changed, 3 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mod_statistics/prosodytop.lua	Mon Dec 08 14:27:10 2014 +0100
+++ b/mod_statistics/prosodytop.lua	Mon Dec 08 17:04:49 2014 +0100
@@ -86,26 +86,16 @@
 		--stdscr:mvaddstr(6, 0, "CONNECTED");
 	end
 
-	local partial;
+	local partial = "";
 	function stats_listener.onincoming(conn, data)
 		--print("DATA", data)
-		if partial then
-			partial, data = nil, partial..data;
-		end
-		if not data:match("\n") then
-			partial = data;
-			return;
-		end
+		data = partial..data;
 		local lastpos = 1;
 		for line, pos in data:gmatch("([^\n]+)\n()") do
 			lastpos = pos;
 			handle_line(line);
 		end
-		if lastpos == #data then
-			partial = nil;
-		else
-			partial = data:sub(lastpos);
-		end
+		partial = data:sub(lastpos);
 	end
 
 	function stats_listener.ondisconnect(conn, err)