aboutsummaryrefslogtreecommitdiff
path: root/src/ftp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/ftp.lua')
-rw-r--r--src/ftp.lua16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/ftp.lua b/src/ftp.lua
index ad02c72..1c7ea71 100644
--- a/src/ftp.lua
+++ b/src/ftp.lua
@@ -32,14 +32,10 @@ local metat = { __index = {} }
32 32
33function open(server, port) 33function open(server, port)
34 local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT)) 34 local tp = socket.try(tp.connect(server, port or PORT, TIMEOUT))
35 local f = { tp = tp } 35 local f = setmetat({ tp = tp }, metat)
36 -- make sure everything gets closed in an exception 36 -- make sure everything gets closed in an exception
37 f.try = socket.newtry(function() 37 f.try = socket.newtry(function() f:close() end)
38 tp:close() 38 return f
39 if f.data then f.data:close() end
40 if f.server then f.server:close() end
41 end)
42 return setmetatable(f, metat)
43end 39end
44 40
45function metat.__index:portconnect() 41function metat.__index:portconnect()
@@ -173,13 +169,9 @@ function metat.__index:quit()
173end 169end
174 170
175function metat.__index:close() 171function metat.__index:close()
176 self.tp:close()
177 if self.data then self.data:close() end 172 if self.data then self.data:close() end
178 if self.server then self.server:close() end 173 if self.server then self.server:close() end
179 self.tp = nil 174 return self.tp:close()
180 self.data = nil
181 self.server = nil
182 return 1
183end 175end
184 176
185----------------------------------------------------------------------------- 177-----------------------------------------------------------------------------