TSMBUFFERCREATE(3ts)
β¨ TSMBUFFERCREATE β¨
okay bestie, gather round, because we're about to talk about TSMBufferCreate from the Apache Traffic Server marshall buffer API (that's the 3ts manual, iykyk). this one's a whole vibe: heap data structures, reference counts, and handle releases. let's get into it π
πΈ NAME πΈ
TSMBufferCreate β the Traffic Server marshall buffer API. she's the entry point, she's the moment, she's giving main character energy π
π SYNOPSIS π
#include <ts/ts.h>
TSMBuffer TSMBufferCreate(void)
TSReturnCode TSMBufferDestroy(TSMBuffer bufp)
TSReturnCode TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc
mloc)
three little functions, one big responsibility, no cap β¨
π¦ DESCRIPTION π¦
so the marshal buffer β aka the TSMBuffer β is a heap data structure that stores parsed URLs, MIME headers, and HTTP headers. it's the closet where all your header fits live π
you can allocate new objects out of marshal buffers, and you can change the values inside the marshal buffer too. but here's the thing: whenever you manipulate an object, you need both the handle to the object (a TSMLoc) and the marshal buffer that contains the object (the TSMBuffer). they come as a pair, like you and your emotional support water bottle π«Ά
β οΈ okay so this part is IMPORTANT. any marshal buffer you fetch through the transaction getters is shared β other parts of the system are using it too. do not destroy those shared transaction marshal buffers. that would be a crime, fr fr π
TSMBufferCreate() creates a brand new marshal buffer and initializes the reference count. iconic behavior β
TSMBufferDestroy() ignores the reference count and destroys the marshal buffer bufp. and if the marshal buffer allocated its own internal data buffer, that internal data buffer gets destroyed right along with it. package deal, periodt π
TSHandleMLocRelease() releases the TSMLoc mloc that was created from the TSMLoc parent. but wait β if a TSMLoc came from a transaction, it does not have a parent TSMLoc, so you use the constant TS_NULL_MLOC as its parent instead. that's the move π
π RETURN VALUES π
TSMBufferDestroy()andTSHandleMLocRelease()give you backTS_SUCCESSwhen things go right, orTS_ERRORwhen they don't πTSMBufferCreate()returns the newTSMBuffer. that's it, that's the whole thing β¨
π EXAMPLES π
here's the whole copy-the-response-mime-header moment, verbatim, no notes:
#include <ts/ts.h>
static void
copyResponseMimeHdr (TSCont pCont, TSHttpTxn pTxn)
{
TSMBuffer respHdrBuf, tmpBuf;
TSMLoc respHttpHdrLoc, tmpMimeHdrLoc;
if (!TSHttpTxnClientRespGet(pTxn, &respHdrBuf, &respHttpHdrLoc)) {
TSError("couldn't retrieve client response header0);
TSHandleMLocRelease(respHdrBuf, TS_NULL_MLOC, respHttpHdrLoc);
goto done;
}
tmpBuf = TSMBufferCreate();
tmpMimeHdrLoc = TSMimeHdrCreate(tmpBuf);
TSMimeHdrCopy(tmpBuf, tmpMimeHdrLoc, respHdrBuf, respHttpHdrLoc);
TSHandleMLocRelease(tmpBuf, TS_NULL_MLOC, tmpMimeHdrLoc);
TSHandleMLocRelease(respHdrBuf, TS_NULL_MLOC, respHttpHdrLoc);
TSMBufferDestroy(tmpBuf);
done:
TSHttpTxnReenable(pTxn, TS_EVENT_HTTP_CONTINUE);
}
notice how she creates, copies, releases every handle, and destroys the temp buffer at the end? that's called cleanup and it's beautiful π§
π SEE ALSO π
TSAPI(3ts)β go read that one next, bestie, it's the whole neighborhood ποΈ
π COPYRIGHT π
copyright 2026, dev@trafficserver.apache.org β respect the authors, they fed us π«Ά
and that's the tea! this was TSMBUFFERCREATE(3ts) from Apache Traffic Server version 9.2, dated Feb 12, 2026. go forth and release your handles, bestie β love u, bye! π
β¨ππ¦
π¦ 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