Enfin on dirait que j'ai réussi à boucher la fuite mémoire, mais il faut encore vérifier mieux ;-)

This commit is contained in:
Christian Zufferey
2020-06-21 19:35:22 +02:00
parent eb9801b227
commit 152e78a264
2 changed files with 62 additions and 19 deletions

View File

@@ -3,17 +3,17 @@
function telnet_listener(socket)
print("\n 0_rtelnet1.lua zf200621.1603 \n")
node, table, tmr, uwrite, tostring =
node, table, tmr, uart.write, tostring
-- node, table, tmr, uwrite, tostring =
-- node, table, tmr, uart.write, tostring
print("................telnet_listener")
insert, remove, concat, heap, gc =
table.insert, table.remove, table.concat, node.heap, collectgarbage
-- insert, remove, concat, heap, gc =
-- table.insert, table.remove, table.concat, node.heap, collectgarbage
fifo1, fifo1l, fifo2, fifo2l = {}, 0, {}, 0
-- local s -- s is a copy of the TCP socket if and only if sending is in progress
function flushGarbage()
if heap() < 13440 then gc() end
if node.heap() < 13440 then collectgarbage() end
end
function sendLine()
@@ -25,11 +25,10 @@ function telnet_listener(socket)
end
flushGarbage()
if #fifo2 < 4 then -- Flush FIFO1 into FIFO2
insert(fifo2,concat(fifo1))
table.insert(fifo2,table.concat(fifo1))
fifo2l, fifo1, fifo1l = fifo2l + fifo1l, {}, 0
end
local rec = remove(fifo2,1) .. (remove(fifo2,1) or '') ..
(remove(fifo2,1) or '') .. (remove(fifo2,1) or '')
rec = table.remove(fifo2,1)..(table.remove(fifo2,1) or '') ..(table.remove(fifo2,1) or '') .. (table.remove(fifo2,1) or '')
fifo2l = fifo2l - #rec
flushGarbage()
s:send(rec)
@@ -39,10 +38,9 @@ function telnet_listener(socket)
function queueLine(str)
while #str > 0 do -- this is because str might be longer than the packet size!
local k, l = F1_SIZE - fifo1l, #str
local chunk
k, l = F1_SIZE - fifo1l, #str
if #fifo1 >= 32 or (k < l and k < 16) then
insert(fifo2, concat(fifo1))
table.insert(fifo2, table.concat(fifo1))
fifo2l, fifo1, fifo1l, k = fifo2l + fifo1l, {}, 0, F1_SIZE
end
if l > k+16 then -- also tolerate a size overrun of 16 bytes to avoid a split
@@ -50,7 +48,7 @@ function telnet_listener(socket)
else
chunk, str = str, ''
end
insert(fifo1, chunk)
table.insert(fifo1, chunk)
fifo1l = fifo1l + #chunk
end
if not s and socket then
@@ -73,28 +71,46 @@ function telnet_listener(socket)
if socket~=nil then
-- if http_post~=nil then http_post(influxdb_url,"energy,memory=srv_rt_no_nil_"..yellow_id.." ram="..node.heap()) end
print("................disconnect 2e", socket, socket:getpeer())
socket=nil
end
-- fifo1, fifo1l, fifo2, fifo2l, s = nil, nil, nil, nil, nil
print("disconnected... "..zerr..", "..node.heap())
-- if debug_rec~=nil then debug_rec("disconnect, disconnected, "..zerr..", "..node.heap()) end
-- telnet_listener=nil
node, table, tmr, uwrite, tostring = nil, nil, nil, nil, nil
insert, remove, concat, heap, gc = nil, nil, nil, nil, nil
-- node, table, tmr, uwrite, tostring = nil, nil, nil, nil, nil
-- insert, remove, concat, heap, gc = nil, nil, nil, nil, nil
-- fifo1, fifo1l, fifo2, fifo2l = nil, nil, nil, nil
-- rec = nil
-- s = nil
-- socket = nil
-- flushGarbage = nil
-- sendLine = nil
-- queueLine = nil
-- receiveLine = nil
-- zconnection = nil
-- disconnect = nil
-- -- telnet_listener=nil
fifo1, fifo1l, fifo2, fifo2l = nil, nil, nil, nil
rec = nil
k = nil
l = nil
s = nil
chunk = nil
socket = nil
flushGarbage = nil
sendLine = nil
queueLine = nil
receiveLine = nil
zconnection = nil
disconnect = nil
telnet_listener=nil
srv_rt=nil
collectgarbage()
-- collectgarbage()
-- rt_connect()
end

View File

@@ -1,13 +1,40 @@
zf200621.1125
verbose=true
=node.heap()
rt_connect()
node, table, tmr, uwrite, tostring = nil, nil, nil, nil, nil
insert, remove, concat, heap, gc = nil, nil, nil, nil, nil
fifo1, fifo1l, fifo2, fifo2l = nil, nil, nil, nil
rec = nil
s = nil
socket = nil
flushGarbage = nil
sendLine = nil
queueLine = nil
receiveLine = nil
zconnection = nil
disconnect = nil
telnet_listener=nil
=node.heap()
dofile("0_rtelnet1.lua")
=node.heap()
telnet_listener=nil
=node.heap()
srv_rt=nil
=node.heap()
for k,v in ipairs(debug.getregistry()) do print(k,v) end
@@ -25,7 +52,7 @@ print(socket)
print(socket:getpeer())
socket:close()
verbose=true
node.output(nil)
http_post(influxdb_url,"energy,value=test1_"..yellow_id.." val=1") print("toto",node.heap(),#t_zurl)