diff options
Diffstat (limited to 'src/socket.lua')
-rw-r--r-- | src/socket.lua | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/socket.lua b/src/socket.lua index 418cd1b..9aa6437 100644 --- a/src/socket.lua +++ b/src/socket.lua | |||
@@ -7,8 +7,8 @@ | |||
7 | ----------------------------------------------------------------------------- | 7 | ----------------------------------------------------------------------------- |
8 | -- Load LuaSocket from dynamic library | 8 | -- Load LuaSocket from dynamic library |
9 | ----------------------------------------------------------------------------- | 9 | ----------------------------------------------------------------------------- |
10 | local open = assert(loadlib("luasocket", "luaopen_socket")) | 10 | local socket = requirelib("luasocket", "luaopen_socket", getfenv(1)) |
11 | local socket = assert(open()) | 11 | _LOADED["socket"] = socket |
12 | 12 | ||
13 | ----------------------------------------------------------------------------- | 13 | ----------------------------------------------------------------------------- |
14 | -- Auxiliar functions | 14 | -- Auxiliar functions |
@@ -116,18 +116,21 @@ socket.sourcet["by-length"] = function(sock, length) | |||
116 | end | 116 | end |
117 | 117 | ||
118 | socket.sourcet["until-closed"] = function(sock) | 118 | socket.sourcet["until-closed"] = function(sock) |
119 | local done | ||
119 | return setmetatable({ | 120 | return setmetatable({ |
120 | getfd = function() return sock:getfd() end, | 121 | getfd = function() return sock:getfd() end, |
121 | dirty = function() return sock:dirty() end | 122 | dirty = function() return sock:dirty() end |
122 | }, { | 123 | }, { |
123 | __call = ltn12.source.simplify(function() | 124 | __call = function() |
125 | if done then return nil end | ||
124 | local chunk, err, partial = sock:receive(socket.BLOCKSIZE) | 126 | local chunk, err, partial = sock:receive(socket.BLOCKSIZE) |
125 | if not err then return chunk | 127 | if not err then return chunk |
126 | elseif err == "closed" then | 128 | elseif err == "closed" then |
127 | sock:close() | 129 | sock:close() |
128 | return partial, ltn12.source.empty() | 130 | done = 1 |
131 | return partial | ||
129 | else return nil, err end | 132 | else return nil, err end |
130 | end) | 133 | end |
131 | }) | 134 | }) |
132 | end | 135 | end |
133 | 136 | ||