-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.lua
62 lines (50 loc) · 1.36 KB
/
target.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
-- helpers definitions
--
local cjson = require "cjson"
local upload = require "upload"
local random = math.random
local shm = ngx.shared.shm
-- static definitions
-- Caution: Keep this value WAY far from client.max_body_size!
local chunksize = 1024 -- in bytes
local retries = 1
local timeout = 0 -- in seconds
local lockFirst = true
local lockRecv = false
local form, err = upload:new(chunk_size)
if not form then
ngx.log(ngx.ERR, "failed to new upload: ", err)
ngx.exit(500)
end
form:set_timeout(5000) -- in milliseconds
-- ToDo: add objects expiration!
local cliente = '127.0.0.1'
shm:set('xchgKey','1')
shm:set(cliente, '1')
-- ToDo: handle xchgKey on receiver end
if not shm:get('xchgKey') then
ngx.log(ngx.ERR,'[ BREAK ] Exchange key not found: ',xchgKey)
end
while true do
local typ, res, err = form:read()
if not typ then
ngx.log(ngx.ERR, "failed to read: ", err)
return
end
while not shm:get(cliente) and retries > 0 do
os.execute('sleep '..timeout)
retries = retries -1
end
if not shm:get(cliente) then
ngx.log(ngx.ERR,'No receiver found on the line. Die miserably.')
break
ngx.exit(408)
end
if typ == 'body' and lockRecv then
shm:set('toXclient_chunk', res)
shm:set('')
end
if typ == "eof" then
break
end
end