forked from devyte/nodemcu-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpserver2.lua
42 lines (31 loc) · 1.12 KB
/
httpserver2.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
return function(port)
local httpsrv = net.createServer(net.TCP, 180)
httpsrv:listen(port, function(socket)
fullPayload = nil
bBodyMossing = nil
local function onReceive(connection, payload)
collectgarbage()
--print("httpserver: onReceive() heap="..node.heap())
payload, fullPayload, bBodyMissing = dofile("httpserver-payload.lc")(payload, fullPayload, bBodyMissing)
collectgarbage()
if bBodyMissing then
--print("onReceive(): incomplete payload, will concat")
return
end
local serveFunction, req = dofile("httpserver-servefunction.lc")(connection, payload)
payload = nil
collectgarbage()
--print("startServing() heap="..node.heap())
local tbconn = dofile("tbconnection.lc")(connection)
tbconn:run(serveFunction, req, req.uri.args)
tbconn = nil
--print("startServing() end heap="..node.heap())
serveFunction = nil
req = nil
collectgarbage()
--print("httpserver: onReceive() end heap="..node.heap())
end
end)
print("httpserver running on port "..port)
return httpsrv
end