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