aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ftp.lua9
-rw-r--r--src/ltn12.lua58
2 files changed, 35 insertions, 32 deletions
diff --git a/src/ftp.lua b/src/ftp.lua
index 43c62c2..9902c88 100644
--- a/src/ftp.lua
+++ b/src/ftp.lua
@@ -125,8 +125,10 @@ function metat.__index:send(sendt)
125 if string.find(code, "1..") then self.try(self.tp:check("2..")) end 125 if string.find(code, "1..") then self.try(self.tp:check("2..")) end
126 -- done with data connection 126 -- done with data connection
127 self.data:close() 127 self.data:close()
128 -- find out how many bytes were sent
129 local sent = socket.skip(1, self.data:getstats())
128 self.data = nil 130 self.data = nil
129 return 1 131 return sent
130end 132end
131 133
132function metat.__index:receive(recvt) 134function metat.__index:receive(recvt)
@@ -186,9 +188,10 @@ local function tput(putt)
186 f:login(putt.user, putt.password) 188 f:login(putt.user, putt.password)
187 if putt.type then f:type(putt.type) end 189 if putt.type then f:type(putt.type) end
188 f:pasv() 190 f:pasv()
189 f:send(putt) 191 local sent = f:send(putt)
190 f:quit() 192 f:quit()
191 return f:close() 193 f:close()
194 return sent
192end 195end
193 196
194local default = { 197local default = {
diff --git a/src/ltn12.lua b/src/ltn12.lua
index 6c5ea28..9917ce8 100644
--- a/src/ltn12.lua
+++ b/src/ltn12.lua
@@ -31,40 +31,40 @@ function filter.cycle(low, ctx, extra)
31 end 31 end
32end 32end
33 33
34-- chains a bunch of filters together 34local function chain2(f1, f2)
35-- by Wim Couwenberg 35 local ff1, ff2 = "", ""
36function filter.chain(...)
37 local current = 1
38 local bottom = 1
39 local top = table.getn(arg)
40 local retry = ""
41 return function(chunk) 36 return function(chunk)
42 if chunk ~= retry then 37 local rf1 = chunk and ""
43 current = bottom 38 local rf2 = ff1 and ""
44 retry = chunk and retry 39 -- if f2 still has pending data, get it and return it
40 if ff2 ~= rf2 then
41 ff2 = f2(rf2)
42 if ff2 ~= "" then return ff2 end
43 end
44 -- here we know f2 needs more data
45 -- we try to get it from f1
46 ff1 = f1(chunk)
47 while 1 do
48 -- if f1 can't produce data, we need more data from the user
49 if ff1 == "" then return "" end
50 -- otherwise we pass new data to f2 until it produces something
51 -- or f1 runs out of data too
52 ff2 = f2(ff1)
53 if ff2 ~= "" then return ff2 end
54 ff1 = f1(rf1)
45 end 55 end
46 repeat
47 if current == bottom then
48 chunk = arg[current](chunk)
49 if chunk == "" or bottom == top then return chunk
50 elseif chunk then current = current + 1
51 else
52 bottom = bottom + 1
53 current = bottom
54 end
55 else
56 chunk = arg[current](chunk or "")
57 if chunk == "" then
58 chunk = retry
59 current = current - 1
60 elseif current == top then return chunk
61 else current = current + 1
62 end
63 end
64 until false
65 end 56 end
66end 57end
67 58
59-- chains a bunch of filters together
60function filter.chain(...)
61 local f = arg[1]
62 for i = 2, table.getn(arg) do
63 f = chain2(f, arg[i])
64 end
65 return f
66end
67
68----------------------------------------------------------------------------- 68-----------------------------------------------------------------------------
69-- Source stuff 69-- Source stuff
70----------------------------------------------------------------------------- 70-----------------------------------------------------------------------------