aboutsummaryrefslogtreecommitdiff
path: root/src/tp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/tp.lua')
-rw-r--r--src/tp.lua9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/tp.lua b/src/tp.lua
index c51d123..7823699 100644
--- a/src/tp.lua
+++ b/src/tp.lua
@@ -13,6 +13,7 @@ local string = require("string")
13local socket = require("socket") 13local socket = require("socket")
14local ltn12 = require("ltn12") 14local ltn12 = require("ltn12")
15module("socket.tp") 15module("socket.tp")
16getmetatable(_M).__index = nil
16 17
17----------------------------------------------------------------------------- 18-----------------------------------------------------------------------------
18-- Program constants 19-- Program constants
@@ -98,7 +99,8 @@ end
98 99
99function metat.__index:source(source, step) 100function metat.__index:source(source, step)
100 local sink = socket.sink("keep-open", self.c) 101 local sink = socket.sink("keep-open", self.c)
101 return ltn12.pump.all(source, sink, step or ltn12.pump.step) 102 local ret, err = ltn12.pump.all(source, sink, step or ltn12.pump.step)
103 return ret, err
102end 104end
103 105
104-- closes the underlying c 106-- closes the underlying c
@@ -108,8 +110,8 @@ function metat.__index:close()
108end 110end
109 111
110-- connect with server and return c object 112-- connect with server and return c object
111function connect(host, port, timeout) 113function connect(host, port, create, timeout)
112 local c, e = socket.tcp() 114 local c, e = (create or socket.tcp())
113 if not c then return nil, e end 115 if not c then return nil, e end
114 c:settimeout(timeout or TIMEOUT) 116 c:settimeout(timeout or TIMEOUT)
115 local r, e = c:connect(host, port) 117 local r, e = c:connect(host, port)
@@ -120,4 +122,3 @@ function connect(host, port, timeout)
120 return base.setmetatable({c = c}, metat) 122 return base.setmetatable({c = c}, metat)
121end 123end
122 124
123--getmetatable(_M).__index = nil