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