Improve documentation
This commit is contained in:
parent
e7db3dce7d
commit
a75f74efb5
@ -1,7 +1,8 @@
|
|||||||
-- httpserver-connection
|
-- httpserver-connection
|
||||||
-- Part of nodemcu-httpserver, provides a buffered connection object that can handle multiple
|
-- Part of nodemcu-httpserver, provides a buffered connection object that can handle multiple
|
||||||
-- consecutive send() calls.
|
-- consecutive send() calls, and buffers small payloads to send once they get big.
|
||||||
-- For this to work, it must be used from a coroutine.
|
-- For this to work, it must be used from a coroutine and owner is responsible for the final
|
||||||
|
-- flush() and for closing the connection.
|
||||||
-- Author: Philip Gladstone, Marcos Kirsch
|
-- Author: Philip Gladstone, Marcos Kirsch
|
||||||
|
|
||||||
BufferedConnection = {}
|
BufferedConnection = {}
|
||||||
@ -23,18 +24,20 @@ function BufferedConnection:new(connection)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--@TODO What are the hardcoded 1000 and 800 about? Can we increase?
|
|
||||||
function newInstance:send(payload)
|
function newInstance:send(payload)
|
||||||
local l = payload:len()
|
local l = payload:len()
|
||||||
if l + self.size > 1000 then
|
if l + self.size > 1024 then
|
||||||
|
-- Send what we have buffered so far, not including payload.
|
||||||
if self:flush() then
|
if self:flush() then
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if l > 800 then
|
if l > 768 then
|
||||||
|
-- Payload is big. Send it now rather than buffering it for later.
|
||||||
self.connection:send(payload)
|
self.connection:send(payload)
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
else
|
else
|
||||||
|
-- Payload is small. Save off payload for later sending.
|
||||||
table.insert(self.data, payload)
|
table.insert(self.data, payload)
|
||||||
self.size = self.size + l
|
self.size = self.size + l
|
||||||
end
|
end
|
||||||
@ -43,5 +46,4 @@ function BufferedConnection:new(connection)
|
|||||||
return newInstance
|
return newInstance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return BufferedConnection
|
return BufferedConnection
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user