Skip to content

Commit

Permalink
Merge pull request #148 from dboltovskyi/fix/frequency_of_streaming_p…
Browse files Browse the repository at this point in the history
…ackets

Increase number of streaming packets per second
  • Loading branch information
dboltovskyi authored Oct 25, 2018
2 parents c69fa29 + b301857 commit 6ed5c5c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions modules/message_dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ function MD.FileStream(filename, version, sessionId, service, encryption, bandwi

local frameSize = (constants.FRAME_SIZE["P" .. res.version]
- constants.PROTOCOL_HEADER_SIZE)

res.chunksize = (frameSize < bandwidth) and frameSize or (bandwidth - 1)
local chunkSize = (frameSize < bandwidth) and frameSize or (bandwidth)
local numberOfChunksPerSecond = 2
res.chunksize = math.floor(chunkSize / numberOfChunksPerSecond + 0.5) -- allow to send 2 chunks per 1 second
res.protocol_handler = ph.ProtocolHandler()
res.messageId = 1
res.rfd, errmsg = io.open(filename, "r")
Expand All @@ -123,13 +124,8 @@ end
-- @treturn number timeout Timeout for next message
function fstream_mt.__index:GetMessage()
local timespan = timestamp() - self.ts
if timespan > 5000 then
self.ts = self.ts + timespan - 1000
self.bytesSent = self.bytesSent / (timespan / 1000)
timespan = 1000
end
if (self.bytesSent + self.chunksize) / (timespan / 1000) > self.bandwidth then
return nil, 200
return nil, 250 -- timeout for next message
end
local res = nil
if self.keep then
Expand Down

0 comments on commit 6ed5c5c

Please sign in to comment.