lua-users home
lua-l archive

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


If it helps, I did something very simiar with ruby at:

https://sites.google.com/site/luizluca/port-forward-over-http

Take  a look at the code. 

---
     Luiz Angelo Daros de Luca, Me.
            luizluca@gmail.com


2011/4/6 David Given <dg@cowlark.com>
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