lua-users home
lua-l archive

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


Hi,

Input is buffered in LuaSocket, so I don't understand the
subject of the message.

The current API does not support a limit on the size of
the input when you use patterns "*l" or "*a".

If you really need to limit the amount of input, you'd have
to do something similar to what you suggested, although
you'd need something slightly more sophisticated.

I assume you are not using coroutines with non-blocking I/O,
so I'd implement something like this:

    -- untested code
    function readlineupto(tcp, maxlen, maxtime)
        maxtime = maxtime + socket.gettime()
        tcp:settimeout(0)
        local readable = {tcp}
        local value, error, partial
        repeat
            local wait = math.max(0, maxtime - socket.gettime())
            if not socket.select(readable, nil, wait) then
                error = "timeout"
                break
            end
            value, error, partial = tcp:receive("*l", partial)
        until error ~= "timeout" or #partial > n
        if #partial > n then
            error = "truncated"
        end
        return value, error, partial
    end

Regards,
Diego