lua-users home
lua-l archive

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


My application asynchronously receives UDP packets from several sources, but timeouts seem to be problematic. My code looks like this:

-- Initialize
for i=1,5 do            -- FIXME: count shouldnt be hard coded
        local udp
        host=datasources[i].host
        port=datasources[i].port
        DEBUG("Binding to host '" ..host.. "' and port " ..port.. "...")
        udp = assert(socket.udp())
        assert(udp:setsockname(host, port))
        ip, port = udp:getsockname()
        assert(ip, port)
        DEBUG("Waiting for packets on " .. ip .. ":" .. port .. "...")
        receive_sockets[i] = udp
end

while 1 do

	socket_timeout = whatever	-- Computed timeout

        -- Make sure each individual socket has the same timeout
        for i=1,5 do    -- FIXME, remove hardcode
                local udp = receive_sockets[i]
                assert(udp:settimeout(socket_timeout))
        end

        -- Wait on sockets
local readable,writable,e=socket.select(receive_sockets, nil, socket_timeout)

        local src,_
        for src,_ in ipairs(readable) do
                local udp=receive_sockets[src]

                local dgram, ip, port = udp:receivefrom()
                if dgram then
DEBUG("Packet received on "..ip.."/"..port.." "..string.len(dgram).." bytes")
			process_dgram(dgram)
                end
        end
end



=========================================================

What happens is that the select waits for the computed timeout, despite the fact that packets are being recieved in the interim (verified by capturing packets via tcpdump). I recompile luasocket to use poll instead of select, but the problem persists.

Using Luasocket 2.0, Luajit 1.1.0 (problem also occurs on Lua 5.1) on Freebsd 4.10









--
Jim Mellander
Incident Response Manager
Computer Protection Program
Lawrence Berkeley National Laboratory
(510) 486-7204

Your fortune for today is:

Always borrow money from a pessimist; he doesn't expect to be paid back.