aboutsummaryrefslogtreecommitdiff
path: root/src/tp.lua
diff options
context:
space:
mode:
authormoteus <mimir@newmail.ru>2013-05-27 12:45:09 +0400
committermoteus <mimir@newmail.ru>2013-05-27 12:45:09 +0400
commit920bc9762954454468d056a61391635cbd849406 (patch)
tree048c112f95fa578d239ae3e35b2aec0a482f0c23 /src/tp.lua
parentbd51d8c1a5bb30e6a358dee6e85963f777edfff4 (diff)
downloadluasocket-920bc9762954454468d056a61391635cbd849406.tar.gz
luasocket-920bc9762954454468d056a61391635cbd849406.tar.bz2
luasocket-920bc9762954454468d056a61391635cbd849406.zip
Build with Lua 5.2 without LUA_COMPAT_MODULE flag.
LUASOCKET_USE_GLOBAL flag enable create global variables when load socket/mime modules.
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