#ifndef HEADER_CURL_CSHUTDN_H1#define HEADER_CURL_CSHUTDN_H2/***************************************************************************3* _ _ ____ _4* Project ___| | | | _ \| |5* / __| | | | |_) | |6* | (__| |_| | _ <| |___7* \___|\___/|_| \_\_____|8*9* Copyright (C) Daniel Stenberg, <[email protected]>, et al.10* Copyright (C) Linus Nielsen Feltzing, <[email protected]>11*12* This software is licensed as described in the file COPYING, which13* you should have received as part of this distribution. The terms14* are also available at https://curl.se/docs/copyright.html.15*16* You may opt to use, copy, modify, merge, publish, distribute and/or sell17* copies of the Software, and permit persons to whom the Software is18* furnished to do so, under the terms of the COPYING file.19*20* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY21* KIND, either express or implied.22*23* SPDX-License-Identifier: curl24*25***************************************************************************/26struct connectdata;27struct Curl_easy;28struct curl_pollfds;29struct Curl_waitfds;30struct Curl_multi;31struct Curl_share;3233/* Run the shutdown of the connection once.34* Will shortly attach/detach `data` to `conn` while doing so.35* `done` will be set TRUE if any error was encountered or if36* the connection was shut down completely. */37void Curl_cshutdn_run_once(struct Curl_easy *data,38struct connectdata *conn,39bool *done);4041/* Terminates the connection, e.g. closes and destroys it.42* If `run_shutdown` is TRUE, the shutdown will be run once before43* terminating it.44* Takes ownership of `conn`. */45void Curl_cshutdn_terminate(struct Curl_easy *data,46struct connectdata *conn,47bool run_shutdown);4849/* A `cshutdown` is always owned by a multi handle to maintain50* the connections to be shut down. It registers timers and51* sockets to monitor via the multi handle. */52struct cshutdn {53struct Curl_llist list; /* connections being shut down */54struct Curl_multi *multi; /* the multi owning this */55BIT(initialised);56};5758/* Init as part of the given multi handle. */59int Curl_cshutdn_init(struct cshutdn *cshutdn,60struct Curl_multi *multi);6162/* Terminate all remaining connections and free resources. */63void Curl_cshutdn_destroy(struct cshutdn *cshutdn,64struct Curl_easy *data);6566/* Number of connections being shut down. */67size_t Curl_cshutdn_count(struct Curl_easy *data);6869/* Number of connections to the destination being shut down. */70size_t Curl_cshutdn_dest_count(struct Curl_easy *data,71const char *destination);7273/* Close the oldest connection in shutdown to destination or,74* when destination is NULL for any destination.75* Return TRUE if a connection has been closed. */76bool Curl_cshutdn_close_oldest(struct Curl_easy *data,77const char *destination);7879/* Add a connection to have it shut down. Will terminate the oldest80* connection when total connection limit of multi is being reached. */81void Curl_cshutdn_add(struct cshutdn *cshutdn,82struct connectdata *conn,83size_t conns_in_pool);8485/* Add sockets and POLLIN/OUT flags for connections being shut down. */86CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn,87struct Curl_easy *data,88struct curl_pollfds *cpfds);8990unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn,91struct Curl_easy *data,92struct Curl_waitfds *cwfds);9394void Curl_cshutdn_setfds(struct cshutdn *cshutdn,95struct Curl_easy *data,96fd_set *read_fd_set, fd_set *write_fd_set,97int *maxfd);9899/* Run shut down connections using socket. If socket is CURL_SOCKET_TIMEOUT,100* run maintenance on all connections. */101void Curl_cshutdn_perform(struct cshutdn *cshutdn,102struct Curl_easy *data,103curl_socket_t s);104105#endif /* HEADER_CURL_CSHUTDN_H */106107108