lua-users home
lua-l archive

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


Hi,

Looking trough LuaSocket's dispatch.lua code, i see that
there's a check for a time without activity over a socket,
and then the socket is killed. In  doing so, it emits
"timeout" error code (from function abort).  On the other
hand, looking at the forward.lua code,there's this
fragment:

       local data, error, partial = foo:receive(2048)
       live = data or error == "timeout"
       data = data or partial
       local result, error = bar:send(data)
       if not live or not result then
           foo:close()
           bar:close()
           break
       end

If i understand this right, this is tought as with plain
non blocking sockets, and won't do the right thing if the
dispatcher kills the socket for lack of activity.  Looks
like there are two different "timeouts" mixed.

Yes. There are two "timeout" mixed. I agree. But there is
rarely enough reason to distinguish between them.

Nevertheless, there is a bug in the forward.lua sample, I
think. When dispatch.lua aborts the transfer, both data and
partial will be nil. So forward.lua will try to send nil
through bar. I think the following code would fix it:

    local function move(foo, bar)
        while 1 do
            local data, error, partial = foo:receive(2048)
            local hasmore = data or error == "timeout"
            data = data or partial
            local sent = data and bar:send(data)
            if not hasmore or not sent then
                foo:close()
                bar:close()
                break
            end
        end
    end

Does this work? Can you verify it?

Regards,
Diego