#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***************************************************************************/2627#include <curl/curl.h>28#include "curlx/timeval.h"2930struct connectdata;31struct Curl_easy;32struct curl_pollfds;33struct Curl_waitfds;34struct Curl_multi;35struct Curl_share;3637/* Run the shutdown of the connection once.38* Will shortly attach/detach `data` to `conn` while doing so.39* `done` will be set TRUE if any error was encountered or if40* the connection was shut down completely. */41void Curl_cshutdn_run_once(struct Curl_easy *data,42struct connectdata *conn,43bool *done);4445/* Terminates the connection, e.g. closes and destroys it.46* If `run_shutdown` is TRUE, the shutdown will be run once before47* terminating it.48* Takes ownership of `conn`. */49void Curl_cshutdn_terminate(struct Curl_easy *data,50struct connectdata *conn,51bool run_shutdown);5253/* A `cshutdown` is always owned by a multi handle to maintain54* the connections to be shut down. It registers timers and55* sockets to monitor via the multi handle. */56struct cshutdn {57struct Curl_llist list; /* connections being shut down */58struct Curl_multi *multi; /* the multi owning this */59BIT(initialised);60};6162/* Init as part of the given multi handle. */63int Curl_cshutdn_init(struct cshutdn *cshutdn,64struct Curl_multi *multi);6566/* Terminate all remaining connections and free resources. */67void Curl_cshutdn_destroy(struct cshutdn *cshutdn,68struct Curl_easy *data);6970/* Number of connections being shut down. */71size_t Curl_cshutdn_count(struct Curl_easy *data);7273/* Number of connections to the destination being shut down. */74size_t Curl_cshutdn_dest_count(struct Curl_easy *data,75const char *destination);7677/* Close the oldest connection in shutdown to destination or,78* when destination is NULL for any destination.79* Return TRUE if a connection has been closed. */80bool Curl_cshutdn_close_oldest(struct Curl_easy *data,81const char *destination);8283/* Add a connection to have it shut down. Will terminate the oldest84* connection when total connection limit of multi is being reached. */85void Curl_cshutdn_add(struct cshutdn *cshutdn,86struct connectdata *conn,87size_t conns_in_pool);8889/* Add sockets and POLLIN/OUT flags for connections being shut down. */90CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn,91struct Curl_easy *data,92struct curl_pollfds *cpfds);9394unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn,95struct Curl_easy *data,96struct Curl_waitfds *cwfds);9798void Curl_cshutdn_setfds(struct cshutdn *cshutdn,99struct Curl_easy *data,100fd_set *read_fd_set, fd_set *write_fd_set,101int *maxfd);102103/* Run shut down connections using socket. If socket is CURL_SOCKET_TIMEOUT,104* run maintenance on all connections. */105void Curl_cshutdn_perform(struct cshutdn *cshutdn,106struct Curl_easy *data,107curl_socket_t s);108109#endif /* HEADER_CURL_CSHUTDN_H */110111112