TSVCONNFDCREATE(3ts)
β¨ TSVCONNFDCREATE β¨
okay bestie, welcome to the TSVConnFdCreate page, straight out of the Apache Traffic Server manual (that's the 3ts section, iykyk). this one's short, sweet, and honestly kinda iconic β it's the glow-up that turns a plain old socket into a whole TSVConn. π
πΈ NAME πΈ
TSVConnFdCreate β create a TSVConn from a socket
no cap, that's the whole job. it takes a socket and gives it main character energy. β¨
π SYNOPSIS π
#include <ts/ts.h>
TSVConn TSVConnFdCreate(int fd)
she takes one little int fd and returns you a TSVConn. that's it. that's the whole vibe. π¦
π DESCRIPTION π
so like, TSVConnFdCreate() takes a network socket fd and hands you back a brand new TSVConn built out of that socket. fr fr.
heads up bestie: that socket descriptor has to be an already connected socket. like, it needs to have already done its whole connect arc. no half-finished situationships here. π«
once it's yours-as-a-TSVConn, it gets placed into non-blocking mode. so she's asynchronous now. she's free. she's not gonna sit there holding up the whole event loop. π§
π RETURN VALUES π
two timelines, bestie:
- success β the returned
TSVConnobject owns the socket, and the caller must not close it. it's not yours anymore, it's hers. hands off. π - failure β
NULLcomes back, the socket is unchanged, and the caller must close it. so like, if she says no, you still gotta take care of it yourself. π
π₯ EXAMPLES π₯
this one's an excerpt from example/plugins/c-api/intercept/intercept.cc in the Traffic Server source distribution. it's showing off how you'd use TSVConnFdCreate() to construct a TSVConn from a connected socket. very demure, very mindful. β¨
// the TSHttpTxn pointer.
VDEBUG("allocated server intercept state istate=%p for txn=%p", istate, cdata.txn);
// Set up a connection to our real origin, which will be
// 127.0.0.1:$PORT.
memset(&addr, 0, sizeof(addr));
addr.sin.sin_family = AF_INET;
addr.sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); // XXX config option
addr.sin.sin_port = htons(PORT); // XXX config option
// Normally, we would use TSNetConnect to connect to a secondary service, but to demonstrate
// the use of TSVConnFdCreate, we do a blocking connect inline. This it not recommended for
// production plugins, since it might block an event thread for an arbitrary time.
fd = ::socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
TSReleaseAssert(fd != -1);
if (::connect(fd, &addr.sa, sizeof(addr.sin)) == -1) {
// We failed to connect to the intercepted origin. Abort the
// server intercept since we cannot handle it.
VDEBUG("connect failed with %s (%d)", strerror(errno), errno);
TSVConnAbort(arg.vc, TS_VC_CLOSE_ABORT);
delete istate;
TSContDestroy(contp);
::close(fd);
return TS_EVENT_NONE;
}
if ((istate->server.vc = TSVConnFdCreate(fd)) == nullptr) {
VDEBUG("TSVconnFdCreate() failed");
TSVConnAbort(arg.vc, TS_VC_CLOSE_ABORT);
delete istate;
TSContDestroy(contp);
::close(fd);
return TS_EVENT_NONE;
}
VDEBUG("binding client vc=%p to %s:%u", istate->client.vc, inet_ntop(AF_INET, &addr.sin.sin_addr, buf, sizeof(buf)),
(unsigned)ntohs(addr.sin.sin_port));
istate->txn = cdata.txn;
istate->client.vc = arg.vc;
// Reset the continuation data to be our intercept state
// block. We will need this so that we can access both of the
// VCs at the same time. We need to do this before calling
lowkey important: see that comment about the blocking connect inline? that's not recommended for production plugins, because it might block an event thread for an arbitrary amount of time. cute for a demo, cursed in prod. π
π SEE ALSO π
go read that one too, bestie, it's the whole friend group. π«Ά
π COPYRIGHT π
2026, dev@trafficserver.apache.org
and that's the page!! slay π this was TSVCONNFDCREATE(3ts) from the Apache Traffic Server manual, version 9.2, dated Feb 12, 2026. go forth and construct your TSVConns responsibly, mwah πβ¨
π¦ 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