lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 06/04/11 00:27, Fabio Mascarenhas wrote:
[...]
> I have commited a change that only closes the socket if
> copas.autoclose is true (the default for now).

This isn't going to fix the underlying issue, though, isn't it? (Which
is that the socket which last unblocked a handler coroutine isn't
necessarily the socket the handler belongs to.)

Perhaps replacing something accept with something like (sorry, don't
have the copas code handy, pseudocode follows):

function accept(mastersocket, handler)
  local serversocket = accept(mastersocket)
  if serversocket then
    local co = coroutine.wrap(
      function()
        -- This call should actually be wrapped with pcall...
        handler(serversocket)
        -- ...so this gets called, even on error.
        serversocket:close()
      end)
    queue(co)
  end
end

Then take the call to close() out of _doTick().

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup

Attachment: signature.asc
Description: OpenPGP digital signature