From 95e6ba209dbcb22de55fcdaebdb50867fb214594 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Sat, 8 Jan 2022 20:01:31 +0300 Subject: [PATCH] Fix. Partial recv in debug loop --- src/mobdebug.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/mobdebug.lua b/src/mobdebug.lua index 2a8257f..1797bed 100644 --- a/src/mobdebug.lua +++ b/src/mobdebug.lua @@ -493,6 +493,16 @@ local function is_pending(peer) return buf end +local function buffer_append(data) + if data and data ~= '' then + if buf then + buf = buf .. data + else + buf = data + end + end +end + local function readnext(peer, num) peer:settimeout(0) -- non-blocking local res, err, partial = peer:receive(num) @@ -516,7 +526,7 @@ local function handle_breakpoint(peer) local res, _, partial = peer:receive("*l") -- get the rest of the line; blocking if not res then - if partial then buf = buf .. partial end + buffer_append(partial) return end @@ -771,8 +781,10 @@ local function debugger_loop(sev, svars, sfile, sline) local line, err if mobdebug.yield and server.settimeout then server:settimeout(mobdebug.yieldtimeout) end while true do - line, err = server:receive("*l") + local partial + line, err, partial = server:receive("*l") if not line then + buffer_append(partial) if err == "timeout" then if mobdebug.yield then mobdebug.yield() end elseif err == "closed" then @@ -786,6 +798,7 @@ local function debugger_loop(sev, svars, sfile, sline) break end end + if server.settimeout then server:settimeout() end -- back to blocking command = string.sub(line, string.find(line, "^[A-Z]+")) if command == "SETB" then