aboutsummaryrefslogtreecommitdiff
path: root/src/tp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/tp.lua')
-rw-r--r--src/tp.lua11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/tp.lua b/src/tp.lua
index 2ffe9a4..cbeff56 100644
--- a/src/tp.lua
+++ b/src/tp.lua
@@ -11,12 +11,14 @@ local base = _G
11local string = require("string") 11local string = require("string")
12local socket = require("socket") 12local socket = require("socket")
13local ltn12 = require("ltn12") 13local ltn12 = require("ltn12")
14module("socket.tp") 14
15socket.tp = {}
16local _M = socket.tp
15 17
16----------------------------------------------------------------------------- 18-----------------------------------------------------------------------------
17-- Program constants 19-- Program constants
18----------------------------------------------------------------------------- 20-----------------------------------------------------------------------------
19TIMEOUT = 60 21_M.TIMEOUT = 60
20 22
21----------------------------------------------------------------------------- 23-----------------------------------------------------------------------------
22-- Implementation 24-- Implementation
@@ -109,10 +111,10 @@ function metat.__index:close()
109end 111end
110 112
111-- connect with server and return c object 113-- connect with server and return c object
112function connect(host, port, timeout, create) 114function _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)
122end 124end
123 125
126return _M \ No newline at end of file