Quantcast
Channel: HAProxy community - Latest topics
Viewing all articles
Browse latest Browse all 4849

Clarify Channel.data() behavior

$
0
0

Can someone please clarify this?
https://www.arpalert.org/src/haproxy-lua-api/2.8/index.html#channel-class

Channel.data(channel[, offset[, length]])

    This function returns length bytes of incoming data from the channel buffer, starting at the
    offset offset. The data are not removed from the buffer.

    By default, if no length is provided, all incoming data found, starting at the given offset, are
    returned. If length is set to -1, the function tries to retrieve a maximum of data and, if
    called by an action, it yields if necessary. It also waits for more data if the requested
    length exceeds the available amount of incoming data. Not providing an offset is the same as
    setting it to 0. A positive offset is relative to the beginning of incoming data of the channel
    buffer while negative offset is relative to the end.

    If there is no incoming data and the channel can’t receive more data, a ‘nil’ value is
    returned.

    Arguments channel (class_channel) – The manipulated Channel.

            offset (integer) – optional The offset in incoming data to start to get data. 0 by
            default. May be negative to be relative to the end of incoming data.

            length (integer) – optional The expected length of data to retrieve. All incoming data
            by default. May be set to -1 to get a maximum of data.

    Returns a string containing the data found or nil. ```

Specifically in my Lua code the calls like `txn.req:data()` or `txn.req:data(0,10)` (with required length specified) frequently return empty string rather than nil or some data.
According to the description it should never return empty string, specifically it should wait for data if the length specified. Or I misunderstood?

How to wait for some data in buffer explicitly?
`core.yield()` in loop does not look right.

Thanks

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4849

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>