Got lua mqtt issue fixed it seems
This commit is contained in:
@@ -1073,14 +1073,25 @@ function client_mt:_apply_network_timeout()
|
||||
|
||||
-- replace connection recv_func with coroutine-based version
|
||||
local sync_recv_func = conn.recv_func
|
||||
conn.recv_func = function(...)
|
||||
conn.recv_func = function(totalSize, ...)
|
||||
print("Args: ("..(1+#{...})..")", totalSize, ...)
|
||||
while true do
|
||||
local data, err = sync_recv_func(...)
|
||||
if not data and (err == "timeout" or err == "wantread") then
|
||||
loop.timeouted = true
|
||||
coroutine_yield(err)
|
||||
else
|
||||
return data, err
|
||||
local allData = ""
|
||||
while true do
|
||||
local size = math.min(totalSize, 16384)
|
||||
local data, err = sync_recv_func(size)
|
||||
if not data and (err == "timeout" or err == "wantread") then
|
||||
loop.timeouted = true
|
||||
coroutine_yield(err)
|
||||
elseif data then
|
||||
allData = allData .. data
|
||||
totalSize = totalSize - size
|
||||
if totalSize == 0 then
|
||||
return allData, nil
|
||||
end
|
||||
else
|
||||
return nil, err
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1167,6 +1178,7 @@ function client_mt:_receive_packet()
|
||||
return false, "network connection is not opened"
|
||||
end
|
||||
-- parse packet
|
||||
print("Calling ", conn.recv_func)
|
||||
local packet, err = self._parse_packet(conn.recv_func)
|
||||
if not packet then
|
||||
return false, err
|
||||
|
||||
@@ -24,7 +24,14 @@ end
|
||||
|
||||
-- Send data to network connection
|
||||
function luasocket.send(conn, data, i, j)
|
||||
conn.sock:settimeout(nil, "t")
|
||||
print("Sending bytes ", #data, i, j)
|
||||
local ok, err = conn.sock:send(data, i, j)
|
||||
if err == "timeout" then
|
||||
print("Oops, got timeout")
|
||||
print(debug.traceback())
|
||||
end
|
||||
conn.sock:settimeout(conn.timeout, "t")
|
||||
-- print(" luasocket.send:", ok, err, require("mqtt.tools").hex(data))
|
||||
return ok, err
|
||||
end
|
||||
@@ -32,16 +39,25 @@ end
|
||||
-- Receive given amount of data from network connection
|
||||
function luasocket.receive(conn, size)
|
||||
local ok, err = conn.sock:receive(size)
|
||||
-- if ok then
|
||||
-- print(" luasocket.receive:", size, require("mqtt.tools").hex(ok))
|
||||
-- elseif err ~= "timeout" then
|
||||
-- print(" luasocket.receive:", ok, err)
|
||||
-- end
|
||||
if ok then
|
||||
if #ok ~= size then
|
||||
assert(false, "bad size")
|
||||
end
|
||||
if #ok > 100 then
|
||||
print(" luasocket.receive good:", size, #ok, "(long)")
|
||||
else
|
||||
--print(debug.traceback())
|
||||
print(" luasocket.receive good:", size, #ok, require("mqtt.tools").hex(ok))
|
||||
end
|
||||
elseif err ~= "timeout" then
|
||||
print(" luasocket.receive fail:", ok, err)
|
||||
end
|
||||
return ok, err
|
||||
end
|
||||
|
||||
-- Set connection's socket to non-blocking mode and set a timeout for it
|
||||
function luasocket.settimeout(conn, timeout)
|
||||
print("Setting timeout to " .. timeout)
|
||||
conn.timeout = timeout
|
||||
conn.sock:settimeout(timeout, "t")
|
||||
end
|
||||
|
||||
@@ -490,12 +490,16 @@ function protocol.start_parse_packet(read_func)
|
||||
len, err = parse_var_length(read_func)
|
||||
if not len then
|
||||
return false, "failed to parse remaining length: "..err
|
||||
else
|
||||
print("Variable length is: " .. len)
|
||||
end
|
||||
|
||||
-- create packet parser instance (aka input)
|
||||
local input = {1, available = 0} -- input data offset and available size
|
||||
if len > 0 then
|
||||
print("Reading payload body")
|
||||
data, err = read_func(len)
|
||||
print("Reading payload body done")
|
||||
else
|
||||
data = ""
|
||||
end
|
||||
@@ -516,6 +520,7 @@ function protocol.start_parse_packet(read_func)
|
||||
return res
|
||||
end
|
||||
|
||||
print("Available data is: " .. input.available)
|
||||
return ptype, flags, input
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user