diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-22 08:33:29 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-22 08:33:29 +0000 |
commit | d55a5826e81136a9ecf65c4cd407152a56684dc2 (patch) | |
tree | 109ad44c75cee890ad5e98583e12b15b5e65a18e /src/socket.lua | |
parent | a2b780bf7a78c66d54a248fa99b5fc862c12a127 (diff) | |
download | luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.gz luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.tar.bz2 luasocket-d55a5826e81136a9ecf65c4cd407152a56684dc2.zip |
Few tweaks in installation, some missing files, etc.
Diffstat (limited to 'src/socket.lua')
-rw-r--r-- | src/socket.lua | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/socket.lua b/src/socket.lua index 6eb3159..458418e 100644 --- a/src/socket.lua +++ b/src/socket.lua | |||
@@ -19,7 +19,7 @@ module("socket") | |||
19 | function connect(address, port, laddress, lport) | 19 | function connect(address, port, laddress, lport) |
20 | local sock, err = socket.tcp() | 20 | local sock, err = socket.tcp() |
21 | if not sock then return nil, err end | 21 | if not sock then return nil, err end |
22 | if laddress then | 22 | if laddress then |
23 | local res, err = sock:bind(laddress, lport, -1) | 23 | local res, err = sock:bind(laddress, lport, -1) |
24 | if not res then return nil, err end | 24 | if not res then return nil, err end |
25 | end | 25 | end |
@@ -65,9 +65,9 @@ sinkt["close-when-done"] = function(sock) | |||
65 | return base.setmetatable({ | 65 | return base.setmetatable({ |
66 | getfd = function() return sock:getfd() end, | 66 | getfd = function() return sock:getfd() end, |
67 | dirty = function() return sock:dirty() end | 67 | dirty = function() return sock:dirty() end |
68 | }, { | 68 | }, { |
69 | __call = function(self, chunk, err) | 69 | __call = function(self, chunk, err) |
70 | if not chunk then | 70 | if not chunk then |
71 | sock:close() | 71 | sock:close() |
72 | return 1 | 72 | return 1 |
73 | else return sock:send(chunk) end | 73 | else return sock:send(chunk) end |
@@ -79,7 +79,7 @@ sinkt["keep-open"] = function(sock) | |||
79 | return base.setmetatable({ | 79 | return base.setmetatable({ |
80 | getfd = function() return sock:getfd() end, | 80 | getfd = function() return sock:getfd() end, |
81 | dirty = function() return sock:dirty() end | 81 | dirty = function() return sock:dirty() end |
82 | }, { | 82 | }, { |
83 | __call = function(self, chunk, err) | 83 | __call = function(self, chunk, err) |
84 | if chunk then return sock:send(chunk) | 84 | if chunk then return sock:send(chunk) |
85 | else return 1 end | 85 | else return 1 end |
@@ -95,7 +95,7 @@ sourcet["by-length"] = function(sock, length) | |||
95 | return base.setmetatable({ | 95 | return base.setmetatable({ |
96 | getfd = function() return sock:getfd() end, | 96 | getfd = function() return sock:getfd() end, |
97 | dirty = function() return sock:dirty() end | 97 | dirty = function() return sock:dirty() end |
98 | }, { | 98 | }, { |
99 | __call = function() | 99 | __call = function() |
100 | if length <= 0 then return nil end | 100 | if length <= 0 then return nil end |
101 | local size = math.min(socket.BLOCKSIZE, length) | 101 | local size = math.min(socket.BLOCKSIZE, length) |
@@ -112,16 +112,16 @@ sourcet["until-closed"] = function(sock) | |||
112 | return base.setmetatable({ | 112 | return base.setmetatable({ |
113 | getfd = function() return sock:getfd() end, | 113 | getfd = function() return sock:getfd() end, |
114 | dirty = function() return sock:dirty() end | 114 | dirty = function() return sock:dirty() end |
115 | }, { | 115 | }, { |
116 | __call = function() | 116 | __call = function() |
117 | if done then return nil end | 117 | if done then return nil end |
118 | local chunk, err, partial = sock:receive(socket.BLOCKSIZE) | 118 | local chunk, err, partial = sock:receive(socket.BLOCKSIZE) |
119 | if not err then return chunk | 119 | if not err then return chunk |
120 | elseif err == "closed" then | 120 | elseif err == "closed" then |
121 | sock:close() | 121 | sock:close() |
122 | done = 1 | 122 | done = 1 |
123 | return partial | 123 | return partial |
124 | else return nil, err end | 124 | else return nil, err end |
125 | end | 125 | end |
126 | }) | 126 | }) |
127 | end | 127 | end |