mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 15:48:49 -05:00
bundles: merged into conncache.c
All the existing Curl_bundle* functions were only ever used from within the conncache.c file, so I moved them over and made them static (and removed the Curl_ prefix).
This commit is contained in:
parent
b419e7ae0c
commit
fd137786e5
@ -44,7 +44,7 @@ LIB_CFILES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
|
||||
http_negotiate_sspi.c http_proxy.c non-ascii.c asyn-ares.c \
|
||||
asyn-thread.c curl_gssapi.c curl_ntlm.c curl_ntlm_wb.c \
|
||||
curl_ntlm_core.c curl_ntlm_msgs.c curl_sasl.c curl_multibyte.c \
|
||||
hostcheck.c bundles.c conncache.c pipeline.c dotdot.c x509asn1.c \
|
||||
hostcheck.c conncache.c pipeline.c dotdot.c x509asn1.c \
|
||||
http2.c curl_sasl_sspi.c smb.c curl_sasl_gssapi.c curl_endian.c \
|
||||
curl_des.c
|
||||
|
||||
@ -62,7 +62,7 @@ LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
|
||||
rtsp.h curl_threads.h warnless.h curl_hmac.h curl_rtmp.h \
|
||||
curl_gethostname.h gopher.h http_proxy.h non-ascii.h asyn.h \
|
||||
curl_ntlm.h curl_gssapi.h curl_ntlm_wb.h curl_ntlm_core.h \
|
||||
curl_ntlm_msgs.h curl_sasl.h curl_multibyte.h hostcheck.h bundles.h \
|
||||
curl_ntlm_msgs.h curl_sasl.h curl_multibyte.h hostcheck.h \
|
||||
conncache.h curl_setup_once.h multihandle.h setup-vms.h pipeline.h \
|
||||
dotdot.h x509asn1.h http2.h sigpipe.h smb.h curl_endian.h curl_des.h \
|
||||
curl_printf.h
|
||||
|
110
lib/bundles.c
110
lib/bundles.c
@ -1,110 +0,0 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2012, Linus Nielsen Feltzing, <linus@haxx.se>
|
||||
* Copyright (C) 2012-2015, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "curl_setup.h"
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "urldata.h"
|
||||
#include "url.h"
|
||||
#include "progress.h"
|
||||
#include "multiif.h"
|
||||
#include "bundles.h"
|
||||
#include "sendf.h"
|
||||
#include "rawstr.h"
|
||||
|
||||
#include "curl_memory.h"
|
||||
/* The last #include file should be: */
|
||||
#include "memdebug.h"
|
||||
|
||||
static void conn_llist_dtor(void *user, void *element)
|
||||
{
|
||||
struct connectdata *data = element;
|
||||
(void)user;
|
||||
|
||||
data->bundle = NULL;
|
||||
}
|
||||
|
||||
CURLcode Curl_bundle_create(struct SessionHandle *data,
|
||||
struct connectbundle **cb_ptr)
|
||||
{
|
||||
(void)data;
|
||||
DEBUGASSERT(*cb_ptr == NULL);
|
||||
*cb_ptr = malloc(sizeof(struct connectbundle));
|
||||
if(!*cb_ptr)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
(*cb_ptr)->num_connections = 0;
|
||||
(*cb_ptr)->server_supports_pipelining = FALSE;
|
||||
|
||||
(*cb_ptr)->conn_list = Curl_llist_alloc((curl_llist_dtor) conn_llist_dtor);
|
||||
if(!(*cb_ptr)->conn_list) {
|
||||
Curl_safefree(*cb_ptr);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
void Curl_bundle_destroy(struct connectbundle *cb_ptr)
|
||||
{
|
||||
if(!cb_ptr)
|
||||
return;
|
||||
|
||||
if(cb_ptr->conn_list) {
|
||||
Curl_llist_destroy(cb_ptr->conn_list, NULL);
|
||||
cb_ptr->conn_list = NULL;
|
||||
}
|
||||
free(cb_ptr);
|
||||
}
|
||||
|
||||
/* Add a connection to a bundle */
|
||||
CURLcode Curl_bundle_add_conn(struct connectbundle *cb_ptr,
|
||||
struct connectdata *conn)
|
||||
{
|
||||
if(!Curl_llist_insert_next(cb_ptr->conn_list, cb_ptr->conn_list->tail, conn))
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
conn->bundle = cb_ptr;
|
||||
|
||||
cb_ptr->num_connections++;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
/* Remove a connection from a bundle */
|
||||
int Curl_bundle_remove_conn(struct connectbundle *cb_ptr,
|
||||
struct connectdata *conn)
|
||||
{
|
||||
struct curl_llist_element *curr;
|
||||
|
||||
curr = cb_ptr->conn_list->head;
|
||||
while(curr) {
|
||||
if(curr->ptr == conn) {
|
||||
Curl_llist_remove(cb_ptr->conn_list, curr, NULL);
|
||||
cb_ptr->num_connections--;
|
||||
conn->bundle = NULL;
|
||||
return 1; /* we removed a handle */
|
||||
}
|
||||
curr = curr->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
#ifndef HEADER_CURL_BUNDLES_H
|
||||
#define HEADER_CURL_BUNDLES_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2012, 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
|
||||
* are also available at http://curl.haxx.se/docs/copyright.html.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
struct connectbundle {
|
||||
bool server_supports_pipelining; /* TRUE if server supports pipelining,
|
||||
set after first response */
|
||||
size_t num_connections; /* Number of connections in the bundle */
|
||||
struct curl_llist *conn_list; /* The connectdata members of the bundle */
|
||||
};
|
||||
|
||||
CURLcode Curl_bundle_create(struct SessionHandle *data,
|
||||
struct connectbundle **cb_ptr);
|
||||
|
||||
void Curl_bundle_destroy(struct connectbundle *cb_ptr);
|
||||
|
||||
CURLcode Curl_bundle_add_conn(struct connectbundle *cb_ptr,
|
||||
struct connectdata *conn);
|
||||
|
||||
int Curl_bundle_remove_conn(struct connectbundle *cb_ptr,
|
||||
struct connectdata *conn);
|
||||
|
||||
|
||||
#endif /* HEADER_CURL_BUNDLES_H */
|
||||
|
@ -31,18 +31,89 @@
|
||||
#include "multiif.h"
|
||||
#include "sendf.h"
|
||||
#include "rawstr.h"
|
||||
#include "bundles.h"
|
||||
#include "conncache.h"
|
||||
|
||||
#include "curl_memory.h"
|
||||
/* The last #include file should be: */
|
||||
#include "memdebug.h"
|
||||
|
||||
static void conn_llist_dtor(void *user, void *element)
|
||||
{
|
||||
struct connectdata *data = element;
|
||||
(void)user;
|
||||
|
||||
data->bundle = NULL;
|
||||
}
|
||||
|
||||
static CURLcode bundle_create(struct SessionHandle *data,
|
||||
struct connectbundle **cb_ptr)
|
||||
{
|
||||
(void)data;
|
||||
DEBUGASSERT(*cb_ptr == NULL);
|
||||
*cb_ptr = malloc(sizeof(struct connectbundle));
|
||||
if(!*cb_ptr)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
(*cb_ptr)->num_connections = 0;
|
||||
(*cb_ptr)->server_supports_pipelining = FALSE;
|
||||
|
||||
(*cb_ptr)->conn_list = Curl_llist_alloc((curl_llist_dtor) conn_llist_dtor);
|
||||
if(!(*cb_ptr)->conn_list) {
|
||||
Curl_safefree(*cb_ptr);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static void bundle_destroy(struct connectbundle *cb_ptr)
|
||||
{
|
||||
if(!cb_ptr)
|
||||
return;
|
||||
|
||||
if(cb_ptr->conn_list) {
|
||||
Curl_llist_destroy(cb_ptr->conn_list, NULL);
|
||||
cb_ptr->conn_list = NULL;
|
||||
}
|
||||
free(cb_ptr);
|
||||
}
|
||||
|
||||
/* Add a connection to a bundle */
|
||||
static CURLcode bundle_add_conn(struct connectbundle *cb_ptr,
|
||||
struct connectdata *conn)
|
||||
{
|
||||
if(!Curl_llist_insert_next(cb_ptr->conn_list, cb_ptr->conn_list->tail, conn))
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
conn->bundle = cb_ptr;
|
||||
|
||||
cb_ptr->num_connections++;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
/* Remove a connection from a bundle */
|
||||
static int bundle_remove_conn(struct connectbundle *cb_ptr,
|
||||
struct connectdata *conn)
|
||||
{
|
||||
struct curl_llist_element *curr;
|
||||
|
||||
curr = cb_ptr->conn_list->head;
|
||||
while(curr) {
|
||||
if(curr->ptr == conn) {
|
||||
Curl_llist_remove(cb_ptr->conn_list, curr, NULL);
|
||||
cb_ptr->num_connections--;
|
||||
conn->bundle = NULL;
|
||||
return 1; /* we removed a handle */
|
||||
}
|
||||
curr = curr->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_bundle_hash_entry(void *freethis)
|
||||
{
|
||||
struct connectbundle *b = (struct connectbundle *) freethis;
|
||||
|
||||
Curl_bundle_destroy(b);
|
||||
bundle_destroy(b);
|
||||
}
|
||||
|
||||
int Curl_conncache_init(struct conncache *connc, int size)
|
||||
@ -57,6 +128,8 @@ void Curl_conncache_destroy(struct conncache *connc)
|
||||
Curl_hash_clean(&connc->hash);
|
||||
}
|
||||
|
||||
/* Look up the bundle with all the connections to the same host this
|
||||
connectdata struct is setup to use. */
|
||||
struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
|
||||
struct conncache *connc)
|
||||
{
|
||||
@ -117,18 +190,18 @@ CURLcode Curl_conncache_add_conn(struct conncache *connc,
|
||||
if(!bundle) {
|
||||
char *hostname = conn->bits.proxy?conn->proxy.name:conn->host.name;
|
||||
|
||||
result = Curl_bundle_create(data, &new_bundle);
|
||||
result = bundle_create(data, &new_bundle);
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
if(!conncache_add_bundle(data->state.conn_cache, hostname, new_bundle)) {
|
||||
Curl_bundle_destroy(new_bundle);
|
||||
bundle_destroy(new_bundle);
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
bundle = new_bundle;
|
||||
}
|
||||
|
||||
result = Curl_bundle_add_conn(bundle, conn);
|
||||
result = bundle_add_conn(bundle, conn);
|
||||
if(result) {
|
||||
if(new_bundle)
|
||||
conncache_remove_bundle(data->state.conn_cache, new_bundle);
|
||||
@ -153,7 +226,7 @@ void Curl_conncache_remove_conn(struct conncache *connc,
|
||||
/* The bundle pointer can be NULL, since this function can be called
|
||||
due to a failed connection attempt, before being added to a bundle */
|
||||
if(bundle) {
|
||||
Curl_bundle_remove_conn(bundle, conn);
|
||||
bundle_remove_conn(bundle, conn);
|
||||
if(bundle->num_connections == 0) {
|
||||
conncache_remove_bundle(connc, bundle);
|
||||
}
|
||||
|
@ -30,6 +30,13 @@ struct conncache {
|
||||
struct timeval last_cleanup;
|
||||
};
|
||||
|
||||
struct connectbundle {
|
||||
bool server_supports_pipelining; /* TRUE if server supports pipelining,
|
||||
set after first response */
|
||||
size_t num_connections; /* Number of connections in the bundle */
|
||||
struct curl_llist *conn_list; /* The connectdata members of the bundle */
|
||||
};
|
||||
|
||||
int Curl_conncache_init(struct conncache *, int size);
|
||||
|
||||
void Curl_conncache_destroy(struct conncache *connc);
|
||||
|
@ -72,7 +72,7 @@
|
||||
#include "http_proxy.h"
|
||||
#include "warnless.h"
|
||||
#include "non-ascii.h"
|
||||
#include "bundles.h"
|
||||
#include "conncache.h"
|
||||
#include "pipeline.h"
|
||||
#include "http2.h"
|
||||
#include "connect.h"
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "warnless.h"
|
||||
#include "speedcheck.h"
|
||||
#include "conncache.h"
|
||||
#include "bundles.h"
|
||||
#include "multihandle.h"
|
||||
#include "pipeline.h"
|
||||
#include "sigpipe.h"
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "pipeline.h"
|
||||
#include "sendf.h"
|
||||
#include "rawstr.h"
|
||||
#include "bundles.h"
|
||||
|
||||
#include "curl_memory.h"
|
||||
/* The last #include file should be: */
|
||||
|
19
lib/url.c
19
lib/url.c
@ -124,7 +124,6 @@ int curl_win32_idn_to_ascii(const char *in, char **out);
|
||||
#include "curl_rtmp.h"
|
||||
#include "gopher.h"
|
||||
#include "http_proxy.h"
|
||||
#include "bundles.h"
|
||||
#include "conncache.h"
|
||||
#include "multihandle.h"
|
||||
#include "pipeline.h"
|
||||
@ -3403,20 +3402,6 @@ ConnectionDone(struct SessionHandle *data, struct connectdata *conn)
|
||||
return (conn_candidate == conn) ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* The given input connection struct pointer is to be stored in the connection
|
||||
* cache. If the cache is already full, least interesting existing connection
|
||||
* (if any) gets closed.
|
||||
*
|
||||
* The given connection should be unique. That must've been checked prior to
|
||||
* this call.
|
||||
*/
|
||||
static CURLcode ConnectionStore(struct SessionHandle *data,
|
||||
struct connectdata *conn)
|
||||
{
|
||||
return Curl_conncache_add_conn(data->state.conn_cache, conn);
|
||||
}
|
||||
|
||||
/* after a TCP connection to the proxy has been verified, this function does
|
||||
the next magic step.
|
||||
|
||||
@ -5600,7 +5585,7 @@ static CURLcode create_conn(struct SessionHandle *data,
|
||||
conn->data = data;
|
||||
conn->bits.tcpconnect[FIRSTSOCKET] = TRUE; /* we are "connected */
|
||||
|
||||
ConnectionStore(data, conn);
|
||||
Curl_conncache_add_conn(data->state.conn_cache, conn);
|
||||
|
||||
/*
|
||||
* Setup whatever necessary for a resumed transfer
|
||||
@ -5761,7 +5746,7 @@ static CURLcode create_conn(struct SessionHandle *data,
|
||||
* This is a brand new connection, so let's store it in the connection
|
||||
* cache of ours!
|
||||
*/
|
||||
ConnectionStore(data, conn);
|
||||
Curl_conncache_add_conn(data->state.conn_cache, conn);
|
||||
}
|
||||
|
||||
#if defined(USE_NTLM)
|
||||
|
Loading…
Reference in New Issue
Block a user