mod_statistics/prosodytop.lua: Simplify and fix buffering and line separation (thanks Ge0rG)

Mon, 08 Dec 2014 17:04:49 +0100

author
Kim Alvefur <zash@zash.se>
date
Mon, 08 Dec 2014 17:04:49 +0100
changeset 1585
64f55bcab9f7
parent 1584
4713f9d453ec
child 1586
b51e596c5a02

mod_statistics/prosodytop.lua: Simplify and fix buffering and line separation (thanks Ge0rG)

mod_statistics/prosodytop.lua file | annotate | diff | comparison | revisions
--- 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)

mercurial