prepared sending of one file in multiple parts
This commit is contained in:
parent
4b1cea0224
commit
7f0d578ca5
@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
configFile="config.lua"
|
configFile="config.lua"
|
||||||
|
|
||||||
sentLines=0
|
sentBytes=0
|
||||||
sendFile=nil
|
sendFile=nil
|
||||||
function sendPage(conn, nameOfFile)
|
function sendPage(conn, nameOfFile)
|
||||||
if (sentLines > 0) then
|
if (sentBytes <= 0) then
|
||||||
print("There is a site already sent")
|
print("There is a site already sent")
|
||||||
return
|
|
||||||
end
|
|
||||||
sendFile=nameOfFile
|
sendFile=nameOfFile
|
||||||
|
end
|
||||||
|
|
||||||
if file.open(sendFile, "r") then
|
if file.open(sendFile, "r") then
|
||||||
local line = file.readLine()
|
local line = file.readLine()
|
||||||
@ -17,11 +16,13 @@ function sendPage(conn, nameOfFile)
|
|||||||
local buf=""
|
local buf=""
|
||||||
while (line ~= nil) do
|
while (line ~= nil) do
|
||||||
buf = buf .. line
|
buf = buf .. line
|
||||||
sentLines= sentLines+1
|
sentBytes=sentBytes+string.len(line)
|
||||||
-- Sent after 1k data
|
-- Sent after 1k data
|
||||||
if (string.len(buf) >= 1000) then
|
if (string.len(buf) >= 1000) then
|
||||||
line=nil
|
line=nil
|
||||||
conn.send(buf)
|
conn.send(buf)
|
||||||
|
-- end the function, this part is sent
|
||||||
|
return
|
||||||
else
|
else
|
||||||
-- fetch the next line
|
-- fetch the next line
|
||||||
line = file.readLine()
|
line = file.readLine()
|
||||||
@ -30,10 +31,14 @@ function sendPage(conn, nameOfFile)
|
|||||||
end
|
end
|
||||||
|
|
||||||
conn:on("sent", function(conn)
|
conn:on("sent", function(conn)
|
||||||
|
if (sentBytes == 0) then
|
||||||
conn:close()
|
conn:close()
|
||||||
-- Clear the webpage generation
|
-- Clear the webpage generation
|
||||||
sendWebPage=nil
|
sendWebPage=nil
|
||||||
print("Clean webpage from RAM")
|
print("Clean webpage from RAM")
|
||||||
|
else
|
||||||
|
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user