diff mod_statistics/prosodytop.lua @ 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 7dbde05b48a9
children 54b93cf0f631
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)