TSMBUFFERCREATE(3ts)

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

✨ 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() and TSHandleMLocRelease() give you back TS_SUCCESS when things go right, or TS_ERROR when they don't 😭
  • TSMBufferCreate() returns the new TSMBuffer. 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 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