Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmcurl/lib/cshutdn.h
5025 views
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, <[email protected]>, et al.
11
* Copyright (C) Linus Nielsen Feltzing, <[email protected]>
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
struct connectdata;
28
struct Curl_easy;
29
struct curl_pollfds;
30
struct Curl_waitfds;
31
struct Curl_multi;
32
struct Curl_share;
33
34
/* Run the shutdown of the connection once.
35
* Will shortly attach/detach `data` to `conn` while doing so.
36
* `done` will be set TRUE if any error was encountered or if
37
* the connection was shut down completely. */
38
void Curl_cshutdn_run_once(struct Curl_easy *data,
39
struct connectdata *conn,
40
bool *done);
41
42
/* Terminates the connection, e.g. closes and destroys it.
43
* If `run_shutdown` is TRUE, the shutdown will be run once before
44
* terminating it.
45
* Takes ownership of `conn`. */
46
void Curl_cshutdn_terminate(struct Curl_easy *data,
47
struct connectdata *conn,
48
bool run_shutdown);
49
50
/* A `cshutdown` is always owned by a multi handle to maintain
51
* the connections to be shut down. It registers timers and
52
* sockets to monitor via the multi handle. */
53
struct cshutdn {
54
struct Curl_llist list; /* connections being shut down */
55
struct Curl_multi *multi; /* the multi owning this */
56
BIT(initialised);
57
};
58
59
/* Init as part of the given multi handle. */
60
int Curl_cshutdn_init(struct cshutdn *cshutdn,
61
struct Curl_multi *multi);
62
63
/* Terminate all remaining connections and free resources. */
64
void Curl_cshutdn_destroy(struct cshutdn *cshutdn,
65
struct Curl_easy *data);
66
67
/* Number of connections being shut down. */
68
size_t Curl_cshutdn_count(struct Curl_easy *data);
69
70
/* Number of connections to the destination being shut down. */
71
size_t Curl_cshutdn_dest_count(struct Curl_easy *data,
72
const char *destination);
73
74
/* Close the oldest connection in shutdown to destination or,
75
* when destination is NULL for any destination.
76
* Return TRUE if a connection has been closed. */
77
bool Curl_cshutdn_close_oldest(struct Curl_easy *data,
78
const char *destination);
79
80
/* Add a connection to have it shut down. Will terminate the oldest
81
* connection when total connection limit of multi is being reached. */
82
void Curl_cshutdn_add(struct cshutdn *cshutdn,
83
struct connectdata *conn,
84
size_t conns_in_pool);
85
86
/* Add sockets and POLLIN/OUT flags for connections being shut down. */
87
CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn,
88
struct Curl_easy *data,
89
struct curl_pollfds *cpfds);
90
91
unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn,
92
struct Curl_easy *data,
93
struct Curl_waitfds *cwfds);
94
95
void Curl_cshutdn_setfds(struct cshutdn *cshutdn,
96
struct Curl_easy *data,
97
fd_set *read_fd_set, fd_set *write_fd_set,
98
int *maxfd);
99
100
/* Run shut down connections using socket. If socket is CURL_SOCKET_TIMEOUT,
101
* run maintenance on all connections. */
102
void Curl_cshutdn_perform(struct cshutdn *cshutdn,
103
struct Curl_easy *data,
104
curl_socket_t s);
105
106
#endif /* HEADER_CURL_CSHUTDN_H */
107
108