1 /*- 2 * Copyright (c) 2006 Verdens Gang AS 3 * Copyright (c) 2006-2015 Varnish Software AS 4 * All rights reserved. 5 * 6 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk> 7 * 8 * SPDX-License-Identifier: BSD-2-Clause 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * Outgoing TCP|UDS connection pools 32 * 33 */ 34 35 struct conn_pool; 36 struct pfd; 37 38 #define PFD_STATE_AVAIL (1<<0) 39 #define PFD_STATE_USED (1<<1) 40 #define PFD_STATE_STOLEN (1<<2) 41 #define PFD_STATE_CLEANUP (1<<3) 42 43 /*--------------------------------------------------------------------- 44 */ 45 46 unsigned PFD_State(const struct pfd *); 47 int *PFD_Fd(struct pfd *); 48 void PFD_LocalName(const struct pfd *, char *, unsigned, char *, unsigned); 49 void PFD_RemoteName(const struct pfd *, char *, unsigned, char *, unsigned); 50 51 /*--------------------------------------------------------------------- 52 * Prototypes 53 */ 54 55 struct conn_pool *VCP_Ref(const struct vrt_endpoint *, const char *ident); 56 /* 57 * Get a reference to a connection pool. Either one or both of ipv4 or 58 * ipv6 arg must be non-NULL, or uds must be non-NULL. If recycling 59 * is to be used, the ident pointer distinguishes the pool from 60 * other pools with same {ipv4, ipv6, uds}. 61 */ 62 63 void VCP_AddRef(struct conn_pool *); 64 /* 65 * Get another reference to an already referenced connection pool. 66 */ 67 68 void VCP_Rel(struct conn_pool **); 69 /* 70 * Release reference to a connection pool. When last reference 71 * is released the pool is destroyed and all cached connections 72 * closed. 73 */ 74 75 int VCP_Open(struct conn_pool *, vtim_dur tmo, VCL_IP *, int*); 76 /* 77 * Open a new connection and return the address used. 78 * errno will be returned in the last argument. 79 */ 80 81 void VCP_Close(struct pfd **); 82 /* 83 * Close a connection. 84 */ 85 86 void VCP_Recycle(const struct worker *, struct pfd **); 87 /* 88 * Recycle an open connection. 89 */ 90 91 struct pfd *VCP_Get(struct conn_pool *, vtim_dur tmo, struct worker *, 92 unsigned force_fresh, int *err); 93 /* 94 * Get a (possibly) recycled connection. 95 * errno will be stored in err 96 */ 97 98 int VCP_Wait(struct worker *, struct pfd *, vtim_real tmo); 99 /* 100 * If the connection was recycled (state != VCP_STATE_USED) call this 101 * function before attempting to receive on the connection. 102 */ 103 104 VCL_IP VCP_GetIp(struct pfd *); 105 106