IO::Buffered
Opt-in buffer pooling for IO::Buffered, enabled with #buffer_pool=.
- Write buffer: acquired on first write, released after each flush
- Read buffer: released when all buffered data has been consumed. Sockets only acquire a buffer once data is available, so idle sockets waiting for data hold no read buffer at all.
Instance methods
Use buffers from pool (also sets buffer_size to the pool's buffer size).
Must be set before any buffer has been allocated.
Pooled buffers are released while not in use, so the stdlib's check for allocated buffers doesn't stop a change to a size the pool's buffers don't have
Flushes through the pool, so that the write buffer is detached and returned like on any flush, then detaches the IO from the pool. A reader that still holds the read buffer returns it when its read fails.
Drops data buffered for writing, so that a following close doesn't
flush it. Used when abandoning a connection: after a failed write the
buffer still holds data that may already have been partly sent.
A write that doesn't fit what's left of the buffer tops the buffer up first, so that the buffered bytes go out with the start of it instead of as a small write of their own. Those writes happen before the caller's flush, and with TCP_NODELAY each would be sent as a TCP segment of its own, so a TCP socket is corked until that flush, which sends whatever is left right away. A write that fits the buffer doesn't cork.