diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-22 08:33:29 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-22 08:33:29 +0000 |
| commit | d55a5826e81136a9ecf65c4cd407152a56684dc2 (patch) | |
| tree | 109ad44c75cee890ad5e98583e12b15b5e65a18e /src/tp.lua | |
| parent | a2b780bf7a78c66d54a248fa99b5fc862c12a127 (diff) | |
| download | luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.gz luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.bz2 luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.zip | |
Few tweaks in installation, some missing files, etc.
Diffstat (limited to 'src/tp.lua')
| -rw-r--r-- | src/tp.lua | 20 |
1 files changed, 10 insertions, 10 deletions
| @@ -37,7 +37,7 @@ local function get_reply(c) | |||
| 37 | current, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)")) | 37 | current, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)")) |
| 38 | reply = reply .. "\n" .. line | 38 | reply = reply .. "\n" .. line |
| 39 | -- reply ends with same code | 39 | -- reply ends with same code |
| 40 | until code == current and sep == " " | 40 | until code == current and sep == " " |
| 41 | end | 41 | end |
| 42 | return code, reply | 42 | return code, reply |
| 43 | end | 43 | end |
| @@ -49,25 +49,25 @@ function metat.__index:check(ok) | |||
| 49 | local code, reply = get_reply(self.c) | 49 | local code, reply = get_reply(self.c) |
| 50 | if not code then return nil, reply end | 50 | if not code then return nil, reply end |
| 51 | if base.type(ok) ~= "function" then | 51 | if base.type(ok) ~= "function" then |
| 52 | if base.type(ok) == "table" then | 52 | if base.type(ok) == "table" then |
| 53 | for i, v in base.ipairs(ok) do | 53 | for i, v in base.ipairs(ok) do |
| 54 | if string.find(code, v) then | 54 | if string.find(code, v) then |
| 55 | return base.tonumber(code), reply | 55 | return base.tonumber(code), reply |
| 56 | end | 56 | end |
| 57 | end | 57 | end |
| 58 | return nil, reply | 58 | return nil, reply |
| 59 | else | 59 | else |
| 60 | if string.find(code, ok) then return base.tonumber(code), reply | 60 | if string.find(code, ok) then return base.tonumber(code), reply |
| 61 | else return nil, reply end | 61 | else return nil, reply end |
| 62 | end | 62 | end |
| 63 | else return ok(base.tonumber(code), reply) end | 63 | else return ok(base.tonumber(code), reply) end |
| 64 | end | 64 | end |
| 65 | 65 | ||
| 66 | function metat.__index:command(cmd, arg) | 66 | function metat.__index:command(cmd, arg) |
| 67 | if arg then | 67 | if arg then |
| 68 | return self.c:send(cmd .. " " .. arg.. "\r\n") | 68 | return self.c:send(cmd .. " " .. arg.. "\r\n") |
| 69 | else | 69 | else |
| 70 | return self.c:send(cmd .. "\r\n") | 70 | return self.c:send(cmd .. "\r\n") |
| 71 | end | 71 | end |
| 72 | end | 72 | end |
| 73 | 73 | ||
| @@ -114,8 +114,8 @@ function connect(host, port, create, timeout) | |||
| 114 | if not c then return nil, e end | 114 | if not c then return nil, e end |
| 115 | c:settimeout(timeout or TIMEOUT) | 115 | c:settimeout(timeout or TIMEOUT) |
| 116 | local r, e = c:connect(host, port) | 116 | local r, e = c:connect(host, port) |
| 117 | if not r then | 117 | if not r then |
| 118 | c:close() | 118 | c:close() |
| 119 | return nil, e | 119 | return nil, e |
| 120 | end | 120 | end |
| 121 | return base.setmetatable({c = c}, metat) | 121 | return base.setmetatable({c = c}, metat) |
