TSIOBUFFERREADER(3ts)
πΈ TSIOBUFFERREADER π
okay bestie, so we're in the Apache Traffic Server corner of the manual pages (this one lives in section 3ts, iykyk) and today's main character is TSIOBufferReader β the traffic Server IO buffer reader API. grab a strawberry drink, we're doing pointers πβ¨
β¨ SYNOPSIS β¨
#include <ts/ts.h>
TSIOBufferReader TSIOBufferReaderAlloc(TSIOBuffer bufp)
TSIOBufferReader TSIOBufferReaderClone(TSIOBufferReader readerp)
void TSIOBufferReaderFree(TSIOBufferReader readerp)
void TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes)
TSIOBufferBlock TSIOBufferReaderStart(TSIOBufferReader readerp)
int64_t TSIOBufferReaderAvail(TSIOBufferReader readerp)
int64_t TSIOBufferReaderCopy(TSIOBufferReader reader, void *buf, int64_t length)
π¦ DESCRIPTION π¦
So TSIOBufferReader is a read accessor for TSIOBuffer. basically it's a little bookmark that represents a location in the contents of the buffer. that's the whole vibe π
the way that a buffer can have multiple readers and each reader consumes data in the buffer independently⦠and here's the plot twist: data for which there are no readers is discarded from the buffer. no cap.
this has two VERY important consequences, and I need you to sit with them:
- Data for which there are no readers and no writer will be discarded. In effect this means without any readers only the current write buffer block will be maintained, older buffer blocks will disappear. π (they're gone, bestie, they simply left the chat)
- Conversely, keeping a reader around unused will pin the buffer data in memory. This can be useful or harmful. pick your fighter π
also bestie, a buffer has a fixed amount of possible readers (currently 5) and that's determined at compile time. Reader allocation is fast and cheap until this maximum is reached, at which point it fails. so yeah, 5 is the limit, it's giving exclusive guest list ποΈ
π the functions, one by one
TSIOBufferReaderAlloc()β allocate a reader. A reader for the IO bufferbufpis created and returned. This should only be called on a newly allocated buffer. If not, the location of the reader in the buffer will be indeterminate π (chaos, honestly). UseTSIOBufferReaderClone()to get another reader if the buffer is already in use.TSIOBufferReaderClone()β duplicate a reader. A reader forbufpis allocated and the initial reader position is set to be the same asreader. twin energy, matching bookmarks β¨TSIOBufferReaderFree()β de-allocate reader. This also effectively consumes (seeTSIOBufferReaderConsume()) all data forreader. so freeing it is not just saying bye, it's saying bye AND clearing the table π«ΆTSIOBufferReaderConsume()β consume data from reader. This advances the position ofreaderin its IO buffer by the smaller ofnbytesand the maximum available in the buffer. This is required to release the buffer memory β when data has been consumed by all readers, it is discarded. remember that part, it's load-bearing π§TSIOBufferReaderStart()β Get the first buffer block. This returns theTSIOBufferBlockwhich contains the first byte available toreader.
NOTE: The byte at the position of reader is in the block but is not necessarily the first byte of the block. so like, don't assume, check first π
TSIOBufferReaderAvail()β returns the number of bytes available. The bytes available is the amount of data that could be read fromreader. it's the "how much is in here for me" number π₯TSIOBufferReaderCopy()β copies data fromreaderintobuff. This copies data from the IO buffer forreaderto the target bufferbufp. The amount of data read in this fashion is the smaller of the amount of data available in the IO buffer forreaderand the size of the target buffer (length). The number of bytes copied is returned. it literally tells you how much it copied, so polite β
NOTE: Destroying a TSIOBuffer will de-allocate and destroy all readers for that buffer. everybody out of the pool, immediately π
π SEE ALSO π
π COPYRIGHT π
2026, dev@trafficserver.apache.org
and that's the whole page bestie, you ate it π
β¨ this was version 9.2 of the Apache Traffic Server manual, dated Feb 12, 2026 β periodt, no cap, go read TSIOBufferCreate(3ts) next π¦π
π¦ where this page comes from
- ubuntu noble: trafficserver-dev 9.2.3+ds-1+deb12u1ubuntu0.1 Β· Apache-2.0
- ubuntu questing: trafficserver-dev 9.2.5+ds-1ubuntu2.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms