.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "TSVCONNFDCREATE" "3ts" "Jan 06, 2024" "9.2" "Apache Traffic Server" .SH NAME TSVConnFdCreate \- create a TSVConn from a socket .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .EX #include .EE .UNINDENT .UNINDENT .INDENT 0.0 .TP .B \fI\%TSVConn\fP TSVConnFdCreate(int fd) .UNINDENT .SH DESCRIPTION .sp \fI\%TSVConnFdCreate()\fP accepts a network socket \fIfd\fP and returns a new \fI\%TSVConn\fP constructed from the socket. The socket descriptor must be an already connected socket. It will be placed into non\-blocking mode. .SH RETURN VALUES .sp On success, the returned \fI\%TSVConn\fP object owns the socket and the caller must not close it. If \fI\%TSVConnFdCreate()\fP fails, \fBNULL\fP is returned, the socket is unchanged and the caller must close it. .SH EXAMPLES .sp The example below is excerpted from \fIexample/plugins/c\-api/intercept/intercept.cc\fP in the Traffic Server source distribution. It demonstrates how to use \fI\%TSVConnFdCreate()\fP to construct a \fI\%TSVConn\fP from a connected socket. .INDENT 0.0 .INDENT 3.5 .sp .EX // the TSHttpTxn pointer. VDEBUG(\(dqallocated server intercept state istate=%p for txn=%p\(dq, 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(\(dqconnect failed with %s (%d)\(dq, 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(\(dqTSVconnFdCreate() failed\(dq); TSVConnAbort(arg.vc, TS_VC_CLOSE_ABORT); delete istate; TSContDestroy(contp); ::close(fd); return TS_EVENT_NONE; } VDEBUG(\(dqbinding client vc=%p to %s:%u\(dq, 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 .EE .UNINDENT .UNINDENT .SH SEE ALSO .sp \fBTSAPI(3ts)\fP .SH COPYRIGHT 2024, dev@trafficserver.apache.org .\" Generated by docutils manpage writer. .