Skip to content

Commit

Permalink
filter internal handles
Browse files Browse the repository at this point in the history
- add easy struct member 'internal' to signal an easy handle is for
  internal use and the user does not have ownership.

- set easy 'internal' true for DoH easy handle and connection cache
  easy handle.

- add a CURLHND parameter to curl_multi_get_handles so that the user can
  request only their (user) easy handles, or internal handles, or both,
  in the multi.
  • Loading branch information
jay committed Aug 29, 2023
1 parent d07038f commit dd0e389
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
8 changes: 7 additions & 1 deletion include/curl/multi.h
Expand Up @@ -426,6 +426,12 @@ CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
curl_socket_t sockfd, void *sockp);

typedef enum {
CURLHND_USER, /* easy handle owned by the user */
CURLHND_INTERNAL, /* easy handle owned internally */
CURLHND_ALL /* both */
} CURLHND;

/*
* Name: curl_multi_get_handles()
*
Expand All @@ -436,7 +442,7 @@ CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
*
* Returns: NULL on failure, otherwise a CURL **array pointer
*/
CURL_EXTERN CURL **curl_multi_get_handles(CURLM *multi_handle);
CURL_EXTERN CURL **curl_multi_get_handles(CURLM *multi_handle, CURLHND filter);

/*
* Name: curl_push_callback
Expand Down
1 change: 1 addition & 0 deletions lib/conncache.c
Expand Up @@ -107,6 +107,7 @@ int Curl_conncache_init(struct conncache *connc, int size)
connc->closure_handle = curl_easy_init();
if(!connc->closure_handle)
return 1; /* bad */
connc->closure_handle->internal = true;

Curl_hash_init(&connc->hash, size, Curl_hash_str,
Curl_str_key_compare, free_bundle_hash_entry);
Expand Down
1 change: 1 addition & 0 deletions lib/doh.c
Expand Up @@ -242,6 +242,7 @@ static CURLcode dohprobe(struct Curl_easy *data,
/* pass in the struct pointer via a local variable to please coverity and
the gcc typecheck helpers */
struct dynbuf *resp = &p->serverdoh;
doh->internal = true;
ERROR_CHECK_SETOPT(CURLOPT_URL, url);
ERROR_CHECK_SETOPT(CURLOPT_DEFAULT_PROTOCOL, "https");
ERROR_CHECK_SETOPT(CURLOPT_WRITEFUNCTION, doh_write_cb);
Expand Down
8 changes: 6 additions & 2 deletions lib/multi.c
Expand Up @@ -3846,7 +3846,8 @@ unsigned int Curl_multi_max_concurrent_streams(struct Curl_multi *multi)
return multi->max_concurrent_streams;
}

struct Curl_easy **curl_multi_get_handles(struct Curl_multi *multi)
struct Curl_easy **curl_multi_get_handles(struct Curl_multi *multi,
CURLHND filter)
{
struct Curl_easy **a = malloc(sizeof(struct Curl_easy *) *
(multi->num_easy + 1));
Expand All @@ -3855,7 +3856,10 @@ struct Curl_easy **curl_multi_get_handles(struct Curl_multi *multi)
struct Curl_easy *e = multi->easyp;
while(e) {
DEBUGASSERT(i < multi->num_easy);
a[i++] = e;
if(filter == CURLHND_ALL ||
(filter == CURLHND_INTERNAL && e->internal) ||
(filter == CURLHND_USER && !e->internal))
a[i++] = e;
e = e->next;
}
a[i] = NULL; /* last entry is a NULL */
Expand Down
6 changes: 5 additions & 1 deletion lib/urldata.h
Expand Up @@ -1945,7 +1945,7 @@ struct Curl_easy {
other using the same cache. For easier tracking
in log output.
This may wrap around after LONG_MAX to 0 again, so it
has no uniqueness guarantuee for very large processings. */
has no uniqueness guarantee for very large processings. */
curl_off_t id;

/* first, two fields for the linked list of these */
Expand Down Expand Up @@ -2008,6 +2008,10 @@ struct Curl_easy {
#ifdef USE_HYPER
struct hyptransfer hyp;
#endif

/* internal: true if this easy handle was created for internal use and the
user does not have ownership of the handle. */
bool internal;
};

#define LIBCURL_NAME "libcurl"
Expand Down

0 comments on commit dd0e389

Please sign in to comment.