Skip to content

Commit

Permalink
removing separate hash implementation
Browse files Browse the repository at this point in the history
- adding convenience functions to hash.h for curl_off_t keys
- adapting connection filters
  • Loading branch information
icing committed Apr 10, 2024
1 parent ffc4681 commit e4d160c
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 292 deletions.
2 changes: 0 additions & 2 deletions lib/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ LIB_CFILES = \
getinfo.c \
gopher.c \
hash.c \
hash_offt.c \
headers.c \
hmac.c \
hostasyn.c \
Expand Down Expand Up @@ -303,7 +302,6 @@ LIB_HFILES = \
getinfo.h \
gopher.h \
hash.h \
hash_offt.h \
headers.h \
hostip.h \
hsts.h \
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 */
185 changes: 0 additions & 185 deletions lib/hash_offt.c

This file was deleted.

66 changes: 0 additions & 66 deletions lib/hash_offt.h

This file was deleted.

12 changes: 6 additions & 6 deletions lib/http2.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <nghttp2/nghttp2.h>
#include "urldata.h"
#include "bufq.h"
#include "hash_offt.h"
#include "hash.h"
#include "http1.h"
#include "http2.h"
#include "http.h"
Expand Down Expand Up @@ -128,7 +128,7 @@ struct cf_h2_ctx {
struct bufq inbufq; /* network input */
struct bufq outbufq; /* network output */
struct bufc_pool stream_bufcp; /* spares for stream buffers */
struct Curl_hash_offt streams; /* hash of `data->id` to `h2_stream_ctx` */
struct Curl_hash streams; /* hash of `data->id` to `h2_stream_ctx` */
size_t drain_total; /* sum of all stream's UrlState drain */
uint32_t max_concurrent_streams;
int32_t goaway_error;
Expand All @@ -154,7 +154,8 @@ static void cf_h2_ctx_clear(struct cf_h2_ctx *ctx)
Curl_bufq_free(&ctx->inbufq);
Curl_bufq_free(&ctx->outbufq);
Curl_bufcp_free(&ctx->stream_bufcp);
Curl_hash_offt_destroy(&ctx->streams);
Curl_hash_clean(&ctx->streams);
Curl_hash_destroy(&ctx->streams);
memset(ctx, 0, sizeof(*ctx));
ctx->call_data = save;
}
Expand Down Expand Up @@ -247,9 +248,8 @@ static void h2_stream_ctx_free(struct h2_stream_ctx *stream)
free(stream);
}

static void h2_stream_hash_free(void *stream, void *user_data)
static void h2_stream_hash_free(void *stream)
{
(void)user_data;
DEBUGASSERT(stream);
h2_stream_ctx_free((struct h2_stream_ctx *)stream);
}
Expand Down Expand Up @@ -431,7 +431,7 @@ static CURLcode cf_h2_ctx_init(struct Curl_cfilter *cf,
Curl_bufcp_init(&ctx->stream_bufcp, H2_CHUNK_SIZE, H2_STREAM_POOL_SPARES);
Curl_bufq_initp(&ctx->inbufq, &ctx->stream_bufcp, H2_NW_RECV_CHUNKS, 0);
Curl_bufq_initp(&ctx->outbufq, &ctx->stream_bufcp, H2_NW_SEND_CHUNKS, 0);
Curl_hash_offt_init(&ctx->streams, 7, h2_stream_hash_free, ctx);
Curl_hash_offt_init(&ctx->streams, 63, h2_stream_hash_free);
ctx->last_stream_id = 2147483647;

rc = nghttp2_session_callbacks_new(&cbs);
Expand Down

0 comments on commit e4d160c

Please sign in to comment.