Skip to content

Commit

Permalink
http/2, http/3: decouple stream state from easy handle
Browse files Browse the repository at this point in the history
- add `Curl_hash_offt` as hashmap between a `curl_off_t` and
  an object. Use this in h2+h3 connection filters to associate
  `data->id` with the internal stream state.
- changed implementations of all affected connection filters
- removed `h2_ctx*` and `h3_ctx*` from `struct HTTP` and thus
  the easy handle
- solves the problem of attaching "foreign protocol" easy handles
  during connection shutdown

Test 1616 verifies the new hash functions.

Closes #13204
  • Loading branch information
icing authored and bagder committed Apr 17, 2024
1 parent c03556f commit c6655f7
Show file tree
Hide file tree
Showing 14 changed files with 561 additions and 232 deletions.
13 changes: 13 additions & 0 deletions lib/cfilters.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,19 @@ size_t Curl_conn_get_max_concurrent(struct Curl_easy *data,
return (result || n <= 0)? 1 : (size_t)n;
}

int Curl_conn_get_stream_error(struct Curl_easy *data,
struct connectdata *conn,
int sockindex)
{
CURLcode result;
int n = 0;

struct Curl_cfilter *cf = conn->cfilter[sockindex];
result = cf? cf->cft->query(cf, data, CF_QUERY_STREAM_ERROR,
&n, NULL) : CURLE_UNKNOWN_OPTION;
return (result || n < 0)? 0 : n;
}

int Curl_conn_sockindex(struct Curl_easy *data, curl_socket_t sockfd)
{
if(data && data->conn &&
Expand Down
7 changes: 7 additions & 0 deletions lib/cfilters.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ typedef CURLcode Curl_cft_cntrl(struct Curl_cfilter *cf,
#define CF_QUERY_SOCKET 3 /* - curl_socket_t */
#define CF_QUERY_TIMER_CONNECT 4 /* - struct curltime */
#define CF_QUERY_TIMER_APPCONNECT 5 /* - struct curltime */
#define CF_QUERY_STREAM_ERROR 6 /* error code - */

/**
* Query the cfilter for properties. Filters ignorant of a query will
Expand Down Expand Up @@ -498,6 +499,12 @@ size_t Curl_conn_get_max_concurrent(struct Curl_easy *data,
struct connectdata *conn,
int sockindex);

/**
* Get the underlying error code for a transfer stream or 0 if not known.
*/
int Curl_conn_get_stream_error(struct Curl_easy *data,
struct connectdata *conn,
int sockindex);

/**
* Get the index of the given socket in the connection's sockets.
Expand Down
22 changes: 22 additions & 0 deletions lib/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,25 @@ void Curl_hash_print(struct Curl_hash *h,
fprintf(stderr, "\n");
}
#endif

void Curl_hash_offt_init(struct Curl_hash *h,
unsigned int slots,
Curl_hash_dtor dtor)
{
Curl_hash_init(h, slots, Curl_hash_str, Curl_str_key_compare, dtor);
}

void *Curl_hash_offt_set(struct Curl_hash *h, curl_off_t id, void *elem)
{
return Curl_hash_add(h, &id, sizeof(id), elem);
}

int Curl_hash_offt_remove(struct Curl_hash *h, curl_off_t id)
{
return Curl_hash_delete(h, &id, sizeof(id));
}

void *Curl_hash_offt_get(struct Curl_hash *h, curl_off_t id)
{
return Curl_hash_pick(h, &id, sizeof(id));
}
9 changes: 9 additions & 0 deletions lib/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,14 @@ Curl_hash_next_element(struct Curl_hash_iterator *iter);
void Curl_hash_print(struct Curl_hash *h,
void (*func)(void *));

/* Hash for `curl_off_t` as key */
void Curl_hash_offt_init(struct Curl_hash *h,
unsigned int slots,
Curl_hash_dtor dtor);

void *Curl_hash_offt_set(struct Curl_hash *h, curl_off_t id, void *elem);
int Curl_hash_offt_remove(struct Curl_hash *h, curl_off_t id);
void *Curl_hash_offt_get(struct Curl_hash *h, curl_off_t id);


#endif /* HEADER_CURL_HASH_H */
6 changes: 1 addition & 5 deletions lib/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,8 @@ void Curl_http_exp100_got100(struct Curl_easy *data);
* HTTP unique setup
***************************************************************************/
struct HTTP {
#ifndef CURL_DISABLE_HTTP
void *h2_ctx; /* HTTP/2 implementation context */
void *h3_ctx; /* HTTP/3 implementation context */
#else
/* TODO: no longer used, we should remove it from SingleRequest */
char unused;
#endif
};

CURLcode Curl_http_size(struct Curl_easy *data);
Expand Down

0 comments on commit c6655f7

Please sign in to comment.