Only one request at a time
This commit is contained in:
parent
7052c4c25a
commit
784a75241c
@ -1,7 +1,7 @@
|
|||||||
--TODO:
|
--TODO:
|
||||||
|
|
||||||
configFile="config.lua"
|
configFile="config.lua"
|
||||||
|
|
||||||
|
httpSending=false
|
||||||
sentBytes=0
|
sentBytes=0
|
||||||
function sendPage(conn, nameOfFile, replaceMap)
|
function sendPage(conn, nameOfFile, replaceMap)
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
@ -11,8 +11,9 @@ function sendPage(conn, nameOfFile, replaceMap)
|
|||||||
conn:close()
|
conn:close()
|
||||||
print("Page sent")
|
print("Page sent")
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
|
httpSending=false
|
||||||
else
|
else
|
||||||
print("Next")
|
collectgarbage()
|
||||||
sendPage(conn, nameOfFile, replaceMap)
|
sendPage(conn, nameOfFile, replaceMap)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -32,7 +33,6 @@ function sendPage(conn, nameOfFile, replaceMap)
|
|||||||
local line = file.readline()
|
local line = file.readline()
|
||||||
|
|
||||||
while (line ~= nil) do
|
while (line ~= nil) do
|
||||||
|
|
||||||
-- all placeholder begin with a $, so search for it in the current line
|
-- all placeholder begin with a $, so search for it in the current line
|
||||||
if (line:find("$") ~= nil) then
|
if (line:find("$") ~= nil) then
|
||||||
-- Replace the placeholder with the dynamic content
|
-- Replace the placeholder with the dynamic content
|
||||||
@ -43,6 +43,8 @@ function sendPage(conn, nameOfFile, replaceMap)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- increase the amount of sent bytes
|
-- increase the amount of sent bytes
|
||||||
sentBytes=sentBytes+string.len(line)
|
sentBytes=sentBytes+string.len(line)
|
||||||
|
|
||||||
@ -126,8 +128,14 @@ function startWebServer()
|
|||||||
srv=net.createServer(net.TCP)
|
srv=net.createServer(net.TCP)
|
||||||
srv:listen(80,function(conn)
|
srv:listen(80,function(conn)
|
||||||
conn:on("receive", function(conn,payload)
|
conn:on("receive", function(conn,payload)
|
||||||
|
if (httpSending) then
|
||||||
|
print("HTTP sending... be patient!")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
if (payload:find("GET /") ~= nil) then
|
if (payload:find("GET /") ~= nil) then
|
||||||
|
httpSending=true
|
||||||
--here is code for handling http request from a web-browser
|
--here is code for handling http request from a web-browser
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
|
|
||||||
@ -297,3 +305,4 @@ function startWebServer()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
--FileView done.
|
||||||
|
Loading…
Reference in New Issue
Block a user