Coverage Report

Created: 2026-10-15 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl/lib/cshutdn.h
Line
Count
Source
1
#ifndef HEADER_CURL_CSHUTDN_H
2
#define HEADER_CURL_CSHUTDN_H
3
/***************************************************************************
4
 *                                  _   _ ____  _
5
 *  Project                     ___| | | |  _ \| |
6
 *                             / __| | | | |_) | |
7
 *                            | (__| |_| |  _ <| |___
8
 *                             \___|\___/|_| \_\_____|
9
 *
10
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11
 * Copyright (C) Linus Nielsen Feltzing, <linus@haxx.se>
12
 *
13
 * This software is licensed as described in the file COPYING, which
14
 * you should have received as part of this distribution. The terms
15
 * are also available at https://curl.se/docs/copyright.html.
16
 *
17
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
18
 * copies of the Software, and permit persons to whom the Software is
19
 * furnished to do so, under the terms of the COPYING file.
20
 *
21
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22
 * KIND, either express or implied.
23
 *
24
 * SPDX-License-Identifier: curl
25
 *
26
 ***************************************************************************/
27
#include "ptrarray.h"
28
29
struct connectdata;
30
struct Curl_easy;
31
struct curl_pollfds;
32
struct Curl_waitfds;
33
struct Curl_multi;
34
struct Curl_share;
35
struct Curl_sigpipe_ctx;
36
37
38
/* Terminates the connection, e.g. closes and destroys it.
39
 * If `do_shutdown` is TRUE, the shutdown will be run once.
40
 * Takes ownership of `conn`. `conn` MUST no longer be in
41
 * a pool or on a shutdown list. */
42
void Curl_cshutdn_terminate(struct Curl_easy *admin,
43
                            struct connectdata *conn,
44
                            bool do_shutdown);
45
46
/* Start the shutdown timer,
47
 * marks the connection sockindex as being shut down. */
48
void Curl_cshutdn_start_timer(struct Curl_easy *data, int8_t sockindex,
49
                              int timeout_ms);
50
/* Clear the shutdown timer at sockindex again. */
51
void Curl_cshutdn_clear_timer(struct Curl_easy *data, int8_t sockindex);
52
53
/* return how much time there is left to shutdown the connection at
54
 * sockindex. Returns 0 if there is no limit or shutdown has not started. */
55
timediff_t Curl_cshutdn_timeleft_ms(struct Curl_easy *data,
56
                                    struct connectdata *conn,
57
                                    int8_t sockindex);
58
59
439k
#define CURL_CONN_IN_SHUTDOWN(c,i)   ((c)->shutdown.start_ms[(i)] >= 0)
60
61
/* Shutdown the connection at `sockindex` non-blocking.
62
 * Will start the shutdown timer if not already set.
63
 * Return CURLE_OK and *done == FALSE if not finished. */
64
CURLcode Curl_cshutdn_try_once_idx(struct Curl_easy *data,
65
                                   int8_t sockindex, bool *done);
66
67
/* Run the shutdown of the connection once non-blocking for both
68
 * socket indices. Will start the shutdown timer if not already set.
69
 * Shortly attach/detach the admin handle to `conn` while doing so.
70
 * `done` will be set TRUE if any error was encountered or if
71
 * the connection was shut down completely. */
72
void Curl_cshutdn_try_once(struct Curl_easy *admin,
73
                           struct connectdata *conn, bool *done);
74
75
/* A `cshutdown` is always owned by a multi handle to maintain
76
 * the connections to be shut down. It registers timers and
77
 * sockets to monitor via the multi handle. */
78
struct cshutdn {
79
  struct ptrarray conns;    /* connections being shut down */
80
};
81
82
/* Init as part of the given multi handle. */
83
void Curl_cshutdn_init(struct cshutdn *cshutdn);
84
85
/* Terminate all remaining connections and free resources. */
86
void Curl_cshutdn_destroy(struct cshutdn *cshutdn,
87
                          struct Curl_easy *admin);
88
89
/* Number of connections being shut down. */
90
size_t Curl_cshutdn_count(struct cshutdn *cshutdn);
91
92
/* Number of connections to the destination being shut down. */
93
size_t Curl_cshutdn_dest_count(struct cshutdn *cshutdn,
94
                               const char *destination);
95
96
/* Close the oldest `count` connections in shutdown to destination or,
97
 * when destination is NULL for any destination.
98
 * Return the number of connections closed. */
99
size_t Curl_cshutdn_close_oldest(struct cshutdn *cshutdn,
100
                                 struct Curl_easy *admin,
101
                                 const char *destination,
102
                                 size_t count);
103
104
/* Add a connection to have it shut down. Terminate the oldest
105
 * connection when shutdowns exceed max_shutdowns. */
106
void Curl_cshutdn_add(struct cshutdn *cshutdn,
107
                      struct Curl_multi *multi,
108
                      struct connectdata *conn,
109
                      size_t max_shutdowns);
110
111
/* Add sockets and POLLIN/OUT flags for connections being shut down. */
112
CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn,
113
                                  struct Curl_easy *admin,
114
                                  struct curl_pollfds *cpfds);
115
116
unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn,
117
                                      struct Curl_easy *admin,
118
                                      struct Curl_waitfds *cwfds);
119
120
void Curl_cshutdn_setfds(struct cshutdn *cshutdn,
121
                         struct Curl_easy *admin,
122
                         fd_set *read_fd_set, fd_set *write_fd_set,
123
                         int *maxfd);
124
125
/* Run maintenance on all connections. */
126
void Curl_cshutdn_perform(struct cshutdn *cshutdn,
127
                          struct Curl_easy *admin,
128
                          struct Curl_sigpipe_ctx *sigpipe_ctx);
129
130
#endif /* HEADER_CURL_CSHUTDN_H */