[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaSocket - COPAS - CoSocket
- From: Diego Nehab <diego@...>
- Date: Thu, 10 May 2007 13:08:11 -0400 (EDT)
Hi,
socket.http uses a function called protect(), which uses
pcall. There is a sample pair in the LuaSocket distribution
that works around this problem by redefining protect(). Take
a look at dispatch.lua and check-links.lua. Not sure how
this would interact with COPAS, but might be worth it a try.
------------------------------------------------------------------------
-- Embarrassing mega hack. Don't try to do this at home.
-------------------------------------------------------------------------
-- we can't yield across calls to protect, so we rewrite it with coxpcall
-- make sure you don't require any module that uses socket.protect before
-- loading our hack
function socket.protect(f)
return function(...)
local co = coroutine.create(f)
while true do
local results = {coroutine.resume(co, base.unpack(arg))}
local status = table.remove(results, 1)
if not status then
if type(results[1]) == 'table' then
return nil, results[1][1]
else error(results[1]) end
end
if coroutine.status(co) == "suspended" then
arg = {coroutine.yield(base.unpack(results))}
else
return base.unpack(results)
end
end
end
end
Make sure you redefine this after require("socket") but
before require("socket.http").
[]s,
Diego.