This is the core of Copas scheduler:
local function _doTick (co, skt, ...)
if not co then return end
local ok, res, new_q = coroutine.resume(co, skt, ...)
if ok and res and new_q then
new_q:insert (res)
new_q:push (res, co)
else
if not ok then copcall (_errhandlers [co] or _deferror,
res, co, skt) end
if skt then skt:close() end
_errhandlers [co] = nil
end
end
As you can see, when the coroutine finishes Copas closes *the socket
that coroutine was awakened with*. So if you do a copas.send, it
yields, and then you exit after coming back, Copas closes the socket
that you sent to. If Javier is here he can tell if that is indeed the
intended behavior or not. :-)
If you remove the skt:close() line then your code should be fine,
although you will now have to remember to close all sockets, unless
you are ok with letting the GC do it. :-)
--
Fabio Mascarenhas
On Fri, Dec 18, 2009 at 8:47 AM, Alexander Gladysh <[email protected]> wrote:
>>>>> Is it legal to store a copas connection in one handler and to use it
>>>>> in another handler?
>
>>>> NO. It's illegal.
>
>> Why? Its operations will yield, but that's not specific to any
>> particular coroutine.
>
> If it is legal, then I'm observing a bug (see case to reproduce it in
> my previous post).
>
> I store a connection from one handler and send data to it from another
> handler.
> If send yields (it does it with 10% probability due to math.random),
> and I exit from second handler on the same tick, then copas closes my
> stored connection instead of the dead handler's original connection.
>
> I'd like to know copas developer's official position on this issue, as
> it is critical for my code.
>
> Alexander.
>
> _______________________________________________
> Kepler-Project mailing list
> [email protected]
> http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
> http://www.keplerproject.org/
>
_______________________________________________
Kepler-Project mailing list
[email protected]
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/