MCPcopy Create free account
hub / github.com/apache/httpd / ap_proxy_tunnel_create

Function ap_proxy_tunnel_create

modules/proxy/proxy_util.c:5395–5517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5393};
5394
5395PROXY_DECLARE(apr_status_t) ap_proxy_tunnel_create(proxy_tunnel_rec **ptunnel,
5396 request_rec *r, conn_rec *c_o,
5397 const char *scheme)
5398{
5399 apr_status_t rv;
5400 conn_rec *c_i = r->connection;
5401 apr_interval_time_t client_timeout = -1, origin_timeout = -1;
5402 proxy_tunnel_rec *tunnel;
5403
5404 *ptunnel = NULL;
5405
5406 tunnel = apr_pcalloc(r->pool, sizeof(*tunnel));
5407
5408 rv = apr_pollset_create(&tunnel->pollset, 2, r->pool, APR_POLLSET_NOCOPY);
5409 if (rv != APR_SUCCESS) {
5410 return rv;
5411 }
5412
5413 tunnel->r = r;
5414 tunnel->scheme = apr_pstrdup(r->pool, scheme);
5415 tunnel->client = apr_pcalloc(r->pool, sizeof(struct proxy_tunnel_conn));
5416 tunnel->origin = apr_pcalloc(r->pool, sizeof(struct proxy_tunnel_conn));
5417 tunnel->pfds = apr_array_make(r->pool, 2, sizeof(apr_pollfd_t));
5418 tunnel->read_buf_size = ap_get_read_buf_size(r);
5419 tunnel->client->other = tunnel->origin;
5420 tunnel->origin->other = tunnel->client;
5421 tunnel->timeout = -1;
5422
5423 tunnel->client->c = c_i;
5424 tunnel->client->name = "client";
5425 tunnel->client->bb = apr_brigade_create(c_i->pool, c_i->bucket_alloc);
5426 tunnel->client->pfd = &APR_ARRAY_PUSH(tunnel->pfds, apr_pollfd_t);
5427 tunnel->client->pfd->p = r->pool;
5428 tunnel->client->pfd->desc_type = APR_NO_DESC;
5429 rv = ap_get_pollfd_from_conn(tunnel->client->c,
5430 tunnel->client->pfd, &client_timeout);
5431 if (rv != APR_SUCCESS) {
5432 return rv;
5433 }
5434 tunnel->client->pfd->client_data = tunnel->client;
5435 if (tunnel->client->pfd->desc_type == APR_POLL_SOCKET) {
5436 apr_socket_opt_set(tunnel->client->pfd->desc.s, APR_SO_NONBLOCK, 1);
5437 }
5438
5439 tunnel->origin->c = c_o;
5440 tunnel->origin->name = "origin";
5441 tunnel->origin->bb = apr_brigade_create(c_o->pool, c_o->bucket_alloc);
5442 tunnel->origin->pfd = &APR_ARRAY_PUSH(tunnel->pfds, apr_pollfd_t);
5443 tunnel->origin->pfd->p = r->pool;
5444 tunnel->origin->pfd->desc_type = APR_POLL_SOCKET;
5445 tunnel->origin->pfd->desc.s = ap_get_conn_socket(c_o);
5446 tunnel->origin->pfd->client_data = tunnel->origin;
5447 apr_socket_timeout_get(tunnel->origin->pfd->desc.s, &origin_timeout);
5448 apr_socket_opt_set(tunnel->origin->pfd->desc.s, APR_SO_NONBLOCK, 1);
5449
5450 /* Defaults to the largest timeout of both connections */
5451 tunnel->timeout = (client_timeout >= 0 && client_timeout > origin_timeout ?
5452 client_timeout : origin_timeout);

Callers 2

proxy_connect_handlerFunction · 0.85

Calls 5

ap_get_read_buf_sizeFunction · 0.85
ap_get_pollfd_from_connFunction · 0.85
ap_get_conn_socketFunction · 0.85

Tested by

no test coverage detected