aboutsummaryrefslogtreecommitdiff
path: root/src/socket.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-15 06:24:00 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-15 06:24:00 +0000
commit58096449c6044b7aade5cd41cfd71c6bec1d273d (patch)
tree1814ffebe89c4c2556d84f97f66db37a7e8b4554 /src/socket.lua
parent9ed7f955e5fc69af9bf1794fa2c8cd227981ba24 (diff)
downloadluasocket-58096449c6044b7aade5cd41cfd71c6bec1d273d.tar.gz
luasocket-58096449c6044b7aade5cd41cfd71c6bec1d273d.tar.bz2
luasocket-58096449c6044b7aade5cd41cfd71c6bec1d273d.zip
Manual is almost done. HTTP is missing.
Implemented new distribution scheme. Select is now purely C. HTTP reimplemented seems faster dunno why. LTN12 functions that coroutines fail gracefully.
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