diff options
Diffstat (limited to 'src/tp.lua')
| -rw-r--r-- | src/tp.lua | 11 |
1 files changed, 7 insertions, 4 deletions
| @@ -11,12 +11,14 @@ local base = _G | |||
| 11 | local string = require("string") | 11 | local string = require("string") |
| 12 | local socket = require("socket") | 12 | local socket = require("socket") |
| 13 | local ltn12 = require("ltn12") | 13 | local ltn12 = require("ltn12") |
| 14 | module("socket.tp") | 14 | |
| 15 | socket.tp = {} | ||
| 16 | local _M = socket.tp | ||
| 15 | 17 | ||
| 16 | ----------------------------------------------------------------------------- | 18 | ----------------------------------------------------------------------------- |
| 17 | -- Program constants | 19 | -- Program constants |
| 18 | ----------------------------------------------------------------------------- | 20 | ----------------------------------------------------------------------------- |
| 19 | TIMEOUT = 60 | 21 | _M.TIMEOUT = 60 |
| 20 | 22 | ||
| 21 | ----------------------------------------------------------------------------- | 23 | ----------------------------------------------------------------------------- |
| 22 | -- Implementation | 24 | -- Implementation |
| @@ -109,10 +111,10 @@ function metat.__index:close() | |||
| 109 | end | 111 | end |
| 110 | 112 | ||
| 111 | -- connect with server and return c object | 113 | -- connect with server and return c object |
| 112 | function connect(host, port, timeout, create) | 114 | function _M.connect(host, port, timeout, create) |
| 113 | local c, e = (create or socket.tcp)() | 115 | local c, e = (create or socket.tcp)() |
| 114 | if not c then return nil, e end | 116 | if not c then return nil, e end |
| 115 | c:settimeout(timeout or TIMEOUT) | 117 | c:settimeout(timeout or _M.TIMEOUT) |
| 116 | local r, e = c:connect(host, port) | 118 | local r, e = c:connect(host, port) |
| 117 | if not r then | 119 | if not r then |
| 118 | c:close() | 120 | c:close() |
| @@ -121,3 +123,4 @@ function connect(host, port, timeout, create) | |||
| 121 | return base.setmetatable({c = c}, metat) | 123 | return base.setmetatable({c = c}, metat) |
| 122 | end | 124 | end |
| 123 | 125 | ||
| 126 | return _M \ No newline at end of file | ||
