diff options
Diffstat (limited to 'src/tp.lua')
| -rw-r--r-- | src/tp.lua | 9 |
1 files changed, 5 insertions, 4 deletions
| @@ -13,6 +13,7 @@ local string = require("string") | |||
| 13 | local socket = require("socket") | 13 | local socket = require("socket") |
| 14 | local ltn12 = require("ltn12") | 14 | local ltn12 = require("ltn12") |
| 15 | module("socket.tp") | 15 | module("socket.tp") |
| 16 | getmetatable(_M).__index = nil | ||
| 16 | 17 | ||
| 17 | ----------------------------------------------------------------------------- | 18 | ----------------------------------------------------------------------------- |
| 18 | -- Program constants | 19 | -- Program constants |
| @@ -98,7 +99,8 @@ end | |||
| 98 | 99 | ||
| 99 | function metat.__index:source(source, step) | 100 | function 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 | ||
| 102 | end | 104 | end |
| 103 | 105 | ||
| 104 | -- closes the underlying c | 106 | -- closes the underlying c |
| @@ -108,8 +110,8 @@ function metat.__index:close() | |||
| 108 | end | 110 | end |
| 109 | 111 | ||
| 110 | -- connect with server and return c object | 112 | -- connect with server and return c object |
| 111 | function connect(host, port, timeout) | 113 | function 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) |
| 121 | end | 123 | end |
| 122 | 124 | ||
| 123 | --getmetatable(_M).__index = nil | ||
