2012-12-11 00:04:13 +08:00
|
|
|
#ifndef HEADER_CURL_CONNCACHE_H
|
|
|
|
#define HEADER_CURL_CONNCACHE_H
|
2012-12-06 19:12:04 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2022-04-25 22:25:42 +08:00
|
|
|
* Copyright (C) 2015 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2014-08-11 06:06:20 +08:00
|
|
|
* Copyright (C) 2012 - 2014, Linus Nielsen Feltzing, <linus@haxx.se>
|
2012-12-06 19:12:04 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2012-12-06 19:12:04 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2012-12-06 19:12:04 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
2017-12-02 21:27:00 +08:00
|
|
|
/*
|
|
|
|
* All accesses to struct fields and changing of data in the connection cache
|
|
|
|
* and connectbundles must be done with the conncache LOCKED. The cache might
|
|
|
|
* be shared.
|
|
|
|
*/
|
|
|
|
|
2022-09-07 18:19:29 +08:00
|
|
|
#include <curl/curl.h>
|
2020-12-11 16:05:47 +08:00
|
|
|
#include "timeval.h"
|
|
|
|
|
|
|
|
struct connectdata;
|
|
|
|
|
2012-12-06 19:12:04 +08:00
|
|
|
struct conncache {
|
2020-09-02 18:07:44 +08:00
|
|
|
struct Curl_hash hash;
|
2017-12-02 21:27:00 +08:00
|
|
|
size_t num_conn;
|
2014-07-23 18:05:47 +08:00
|
|
|
long next_connection_id;
|
2017-07-28 21:49:36 +08:00
|
|
|
struct curltime last_cleanup;
|
2017-11-02 06:37:45 +08:00
|
|
|
/* handle used for closing cached connections */
|
|
|
|
struct Curl_easy *closure_handle;
|
2012-12-06 19:12:04 +08:00
|
|
|
};
|
|
|
|
|
2015-05-18 14:56:29 +08:00
|
|
|
#define BUNDLE_NO_MULTIUSE -1
|
|
|
|
#define BUNDLE_UNKNOWN 0 /* initial value */
|
|
|
|
#define BUNDLE_MULTIPLEX 2
|
|
|
|
|
2019-12-09 18:53:54 +08:00
|
|
|
#ifdef CURLDEBUG
|
|
|
|
/* the debug versions of these macros make extra certain that the lock is
|
|
|
|
never doubly locked or unlocked */
|
2020-12-26 22:43:25 +08:00
|
|
|
#define CONNCACHE_LOCK(x) \
|
|
|
|
do { \
|
|
|
|
if((x)->share) { \
|
|
|
|
Curl_share_lock((x), CURL_LOCK_DATA_CONNECT, \
|
|
|
|
CURL_LOCK_ACCESS_SINGLE); \
|
|
|
|
DEBUGASSERT(!(x)->state.conncache_lock); \
|
|
|
|
(x)->state.conncache_lock = TRUE; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2019-12-09 18:53:54 +08:00
|
|
|
|
2020-12-26 22:43:25 +08:00
|
|
|
#define CONNCACHE_UNLOCK(x) \
|
|
|
|
do { \
|
|
|
|
if((x)->share) { \
|
|
|
|
DEBUGASSERT((x)->state.conncache_lock); \
|
|
|
|
(x)->state.conncache_lock = FALSE; \
|
|
|
|
Curl_share_unlock((x), CURL_LOCK_DATA_CONNECT); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2019-12-09 18:53:54 +08:00
|
|
|
#else
|
2020-04-27 06:33:21 +08:00
|
|
|
#define CONNCACHE_LOCK(x) if((x)->share) \
|
2019-12-09 18:53:54 +08:00
|
|
|
Curl_share_lock((x), CURL_LOCK_DATA_CONNECT, CURL_LOCK_ACCESS_SINGLE)
|
2020-04-27 06:33:21 +08:00
|
|
|
#define CONNCACHE_UNLOCK(x) if((x)->share) \
|
2019-12-09 18:53:54 +08:00
|
|
|
Curl_share_unlock((x), CURL_LOCK_DATA_CONNECT)
|
|
|
|
#endif
|
|
|
|
|
2015-05-13 05:06:11 +08:00
|
|
|
struct connectbundle {
|
2015-05-18 14:56:29 +08:00
|
|
|
int multiuse; /* supports multi-use */
|
2015-05-13 05:06:11 +08:00
|
|
|
size_t num_connections; /* Number of connections in the bundle */
|
2020-09-02 18:06:20 +08:00
|
|
|
struct Curl_llist conn_list; /* The connectdata members of the bundle */
|
2015-05-13 05:06:11 +08:00
|
|
|
};
|
|
|
|
|
2017-11-02 06:37:45 +08:00
|
|
|
/* returns 1 on error, 0 is fine */
|
2015-05-12 15:15:02 +08:00
|
|
|
int Curl_conncache_init(struct conncache *, int size);
|
2012-12-06 19:12:04 +08:00
|
|
|
void Curl_conncache_destroy(struct conncache *connc);
|
|
|
|
|
2015-03-11 18:54:22 +08:00
|
|
|
/* return the correct bundle, to a host or a proxy */
|
2021-01-18 18:56:50 +08:00
|
|
|
struct connectbundle *Curl_conncache_find_bundle(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
2022-04-25 22:25:42 +08:00
|
|
|
struct conncache *connc);
|
2017-12-02 21:27:00 +08:00
|
|
|
/* returns number of connections currently held in the connection cache */
|
|
|
|
size_t Curl_conncache_size(struct Curl_easy *data);
|
2012-12-06 19:12:04 +08:00
|
|
|
|
2019-12-09 18:53:54 +08:00
|
|
|
bool Curl_conncache_return_conn(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn);
|
2021-01-18 18:56:50 +08:00
|
|
|
CURLcode Curl_conncache_add_conn(struct Curl_easy *data) WARN_UNUSED_RESULT;
|
2018-12-20 23:39:02 +08:00
|
|
|
void Curl_conncache_remove_conn(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
2017-12-02 21:27:00 +08:00
|
|
|
bool lock);
|
|
|
|
bool Curl_conncache_foreach(struct Curl_easy *data,
|
2017-11-02 06:37:45 +08:00
|
|
|
struct conncache *connc,
|
2012-12-06 19:12:04 +08:00
|
|
|
void *param,
|
2021-01-09 00:58:15 +08:00
|
|
|
int (*func)(struct Curl_easy *data,
|
|
|
|
struct connectdata *conn,
|
2012-12-12 03:13:29 +08:00
|
|
|
void *param));
|
2012-12-06 19:12:04 +08:00
|
|
|
|
|
|
|
struct connectdata *
|
|
|
|
Curl_conncache_find_first_connection(struct conncache *connc);
|
|
|
|
|
2017-11-02 06:37:45 +08:00
|
|
|
struct connectdata *
|
2017-12-02 21:27:00 +08:00
|
|
|
Curl_conncache_extract_bundle(struct Curl_easy *data,
|
|
|
|
struct connectbundle *bundle);
|
|
|
|
struct connectdata *
|
|
|
|
Curl_conncache_extract_oldest(struct Curl_easy *data);
|
2017-11-02 06:37:45 +08:00
|
|
|
void Curl_conncache_close_all_connections(struct conncache *connc);
|
2012-12-06 19:12:04 +08:00
|
|
|
void Curl_conncache_print(struct conncache *connc);
|
|
|
|
|
2012-12-11 00:04:13 +08:00
|
|
|
#endif /* HEADER_CURL_CONNCACHE_H */
|