diff options
Diffstat (limited to 'src/ftp.lua')
-rw-r--r-- | src/ftp.lua | 16 |
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 | ||
33 | function open(server, port) | 33 | function 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) | ||
43 | end | 39 | end |
44 | 40 | ||
45 | function metat.__index:portconnect() | 41 | function metat.__index:portconnect() |
@@ -173,13 +169,9 @@ function metat.__index:quit() | |||
173 | end | 169 | end |
174 | 170 | ||
175 | function metat.__index:close() | 171 | function 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 | ||
183 | end | 175 | end |
184 | 176 | ||
185 | ----------------------------------------------------------------------------- | 177 | ----------------------------------------------------------------------------- |