aboutsummaryrefslogtreecommitdiff
path: root/src/socket.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/socket.lua')
-rw-r--r--src/socket.lua13
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-----------------------------------------------------------------------------
10local open = assert(loadlib("luasocket", "luaopen_socket")) 10local socket = requirelib("luasocket", "luaopen_socket", getfenv(1))
11local 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)
116end 116end
117 117
118socket.sourcet["until-closed"] = function(sock) 118socket.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 })
132end 135end
133 136