diff options
| author | moteus <mimir@newmail.ru> | 2013-05-27 12:45:09 +0400 |
|---|---|---|
| committer | moteus <mimir@newmail.ru> | 2013-05-27 12:45:09 +0400 |
| commit | 920bc9762954454468d056a61391635cbd849406 (patch) | |
| tree | 048c112f95fa578d239ae3e35b2aec0a482f0c23 /src/tp.lua | |
| parent | bd51d8c1a5bb30e6a358dee6e85963f777edfff4 (diff) | |
| download | luasocket-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.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 | ||
