Finally works when serving multiple files simultaneously. Still need to clan up

This commit is contained in:
Marcos Kirsch 2015-03-15 13:16:59 -05:00
parent d5fcc71c23
commit b10a137712

View File

@ -14,14 +14,25 @@ end
return function (connection, args) return function (connection, args)
sendHeader(connection, 200, "OK", getMimeType(args.ext)) sendHeader(connection, 200, "OK", getMimeType(args.ext))
file.open(args.file) print("Begin sending:", args.file)
-- Send file in little chunks -- Send file in little chunks
while true do local continue = true
local chunk = file.read(1024) local bytesSent = 0
if chunk == nil then break end while continue do
coroutine.yield() file.open(args.file)
connection:send(chunk) file.seek("set", bytesSent)
local chunk = file.read(512)
file.close()
if chunk == nil then
continue = false
else
if #chunk == 512 then
coroutine.yield()
end
connection:send(chunk)
bytesSent = bytesSent + #chunk
print("Sent" .. args.file, bytesSent)
end
end end
print("Finished sending:", args.file) print("Finished sending:", args.file)
file.close()
end end