TSIOBUFFERREADER(3ts)

πŸ“¦
version 9.2.5 Β· 4 versions
, in ubuntu noble, ubuntu questing

🌸 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 buffer bufp is 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). Use TSIOBufferReaderClone() to get another reader if the buffer is already in use.
  • TSIOBufferReaderClone() β€” duplicate a reader. A reader for bufp is allocated and the initial reader position is set to be the same as reader. twin energy, matching bookmarks ✨
  • TSIOBufferReaderFree() β€” de-allocate reader. This also effectively consumes (see TSIOBufferReaderConsume()) all data for reader. 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 of reader in its IO buffer by the smaller of nbytes and 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 the TSIOBufferBlock which contains the first byte available to reader.
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 from reader. it's the "how much is in here for me" number πŸ”₯
  • TSIOBufferReaderCopy() β€” copies data from reader into buff. This copies data from the IO buffer for reader to the target buffer bufp. The amount of data read in this fashion is the smaller of the amount of data available in the IO buffer for reader and 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 🌈


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