From 2df13922256695cb9af041ca1fd28d54a3479c6f Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Sat, 20 Jul 2024 12:28:25 +0200 Subject: [PATCH] fix(luasocket): return the partial results read --- mqtt/connector/base/buffered_base.lua | 3 +++ mqtt/connector/luasocket.lua | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mqtt/connector/base/buffered_base.lua b/mqtt/connector/base/buffered_base.lua index 5ade17a..1b649fd 100644 --- a/mqtt/connector/base/buffered_base.lua +++ b/mqtt/connector/base/buffered_base.lua @@ -76,6 +76,9 @@ end -- is no data to read. If there is no data, then it MUST return -- `nil, self.signal_idle` to indicate it no data was there and we need to retry later. -- +-- If there is partial data, it should return that data (less than the requested +-- number of bytes), with no error/signal. +-- -- If the receive errors, because of a closed connection it should return -- `nil, self.signal_closed` to indicate this. Any other errors can be returned -- as a regular `nil, err`. diff --git a/mqtt/connector/luasocket.lua b/mqtt/connector/luasocket.lua index 6a25431..b5bf004 100644 --- a/mqtt/connector/luasocket.lua +++ b/mqtt/connector/luasocket.lua @@ -118,8 +118,10 @@ function luasocket:plain_receive(size) sock:settimeout(0) - local data, err = sock:receive(size) - if data then + local data, err, partial = sock:receive(size) + + data = data or partial or "" + if #data > 0 then return data end