cmake/Utilities/cmcurl/lib/conncache.h

120 lines
5.1 KiB
C
Raw Normal View History

2015-04-27 22:25:09 +02:00
#ifndef HEADER_CURL_CONNCACHE_H
#define HEADER_CURL_CONNCACHE_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
2021-09-14 00:13:48 +02:00
* Copyright (C) 2015 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
2015-04-27 22:25:09 +02:00
* Copyright (C) 2012 - 2014, Linus Nielsen Feltzing, <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
2021-09-14 00:13:48 +02:00
* are also available at https://curl.se/docs/copyright.html.
2015-04-27 22:25:09 +02: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.
*
***************************************************************************/
2018-04-23 21:13:27 +02: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.
*/
2021-09-14 00:13:48 +02:00
#include "timeval.h"
struct connectdata;
2015-04-27 22:25:09 +02:00
struct conncache {
2021-09-14 00:13:48 +02:00
struct Curl_hash hash;
2018-04-23 21:13:27 +02:00
size_t num_conn;
2015-04-27 22:25:09 +02:00
long next_connection_id;
2018-01-26 17:06:56 +01:00
struct curltime last_cleanup;
2018-04-23 21:13:27 +02:00
/* handle used for closing cached connections */
struct Curl_easy *closure_handle;
2015-04-27 22:25:09 +02:00
};
2015-11-17 17:22:37 +01:00
#define BUNDLE_NO_MULTIUSE -1
#define BUNDLE_UNKNOWN 0 /* initial value */
#define BUNDLE_MULTIPLEX 2
2020-08-30 11:54:41 +02:00
#ifdef CURLDEBUG
/* the debug versions of these macros make extra certain that the lock is
never doubly locked or unlocked */
2021-09-14 00:13:48 +02: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)
2020-08-30 11:54:41 +02:00
2021-09-14 00:13:48 +02: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)
2020-08-30 11:54:41 +02:00
#else
#define CONNCACHE_LOCK(x) if((x)->share) \
Curl_share_lock((x), CURL_LOCK_DATA_CONNECT, CURL_LOCK_ACCESS_SINGLE)
#define CONNCACHE_UNLOCK(x) if((x)->share) \
Curl_share_unlock((x), CURL_LOCK_DATA_CONNECT)
#endif
2015-11-17 17:22:37 +01:00
struct connectbundle {
int multiuse; /* supports multi-use */
size_t num_connections; /* Number of connections in the bundle */
2021-09-14 00:13:48 +02:00
struct Curl_llist conn_list; /* The connectdata members of the bundle */
2015-11-17 17:22:37 +01:00
};
2018-04-23 21:13:27 +02:00
/* returns 1 on error, 0 is fine */
2015-11-17 17:22:37 +01:00
int Curl_conncache_init(struct conncache *, int size);
2015-04-27 22:25:09 +02:00
void Curl_conncache_destroy(struct conncache *connc);
2015-11-17 17:22:37 +01:00
/* return the correct bundle, to a host or a proxy */
2021-09-14 00:13:48 +02:00
struct connectbundle *Curl_conncache_find_bundle(struct Curl_easy *data,
struct connectdata *conn,
2020-08-30 11:54:41 +02:00
struct conncache *connc,
const char **hostp);
2018-04-23 21:13:27 +02:00
/* returns number of connections currently held in the connection cache */
size_t Curl_conncache_size(struct Curl_easy *data);
2015-04-27 22:25:09 +02:00
2020-08-30 11:54:41 +02:00
bool Curl_conncache_return_conn(struct Curl_easy *data,
struct connectdata *conn);
2021-09-14 00:13:48 +02:00
CURLcode Curl_conncache_add_conn(struct Curl_easy *data) WARN_UNUSED_RESULT;
2019-11-11 23:01:05 +01:00
void Curl_conncache_remove_conn(struct Curl_easy *data,
struct connectdata *conn,
2018-04-23 21:13:27 +02:00
bool lock);
bool Curl_conncache_foreach(struct Curl_easy *data,
struct conncache *connc,
2015-04-27 22:25:09 +02:00
void *param,
2021-09-14 00:13:48 +02:00
int (*func)(struct Curl_easy *data,
struct connectdata *conn,
2015-04-27 22:25:09 +02:00
void *param));
struct connectdata *
Curl_conncache_find_first_connection(struct conncache *connc);
2018-04-23 21:13:27 +02:00
struct connectdata *
Curl_conncache_extract_bundle(struct Curl_easy *data,
struct connectbundle *bundle);
struct connectdata *
Curl_conncache_extract_oldest(struct Curl_easy *data);
void Curl_conncache_close_all_connections(struct conncache *connc);
2015-04-27 22:25:09 +02:00
void Curl_conncache_print(struct conncache *connc);
#endif /* HEADER_CURL_CONNCACHE_H */