1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-11 20:15:03 -05:00

multi: converted socket hash into non-allocated struct

avoids extra dynamic allocation
This commit is contained in:
Daniel Stenberg 2015-05-12 09:28:37 +02:00
parent 640296c95d
commit d37e0160c2
2 changed files with 17 additions and 18 deletions

View File

@ -252,9 +252,9 @@ static size_t hash_fd(void *key, size_t key_length, size_t slots_num)
* per call." * per call."
* *
*/ */
static struct curl_hash *sh_init(int hashsize) static int sh_init(struct curl_hash *hash, int hashsize)
{ {
return Curl_hash_alloc(hashsize, hash_fd, fd_key_compare, return Curl_hash_init(hash, hashsize, hash_fd, fd_key_compare,
sh_freeentry); sh_freeentry);
} }
@ -298,8 +298,7 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */
if(!multi->hostcache) if(!multi->hostcache)
goto error; goto error;
multi->sockhash = sh_init(hashsize); if(sh_init(&multi->sockhash, hashsize))
if(!multi->sockhash)
goto error; goto error;
if(Curl_conncache_init(&multi->conn_cache, chashsize)) if(Curl_conncache_init(&multi->conn_cache, chashsize))
@ -329,8 +328,7 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */
error: error:
Curl_hash_destroy(multi->sockhash); Curl_hash_clean(&multi->sockhash);
multi->sockhash = NULL;
Curl_hash_destroy(multi->hostcache); Curl_hash_destroy(multi->hostcache);
multi->hostcache = NULL; multi->hostcache = NULL;
Curl_conncache_destroy(&multi->conn_cache); Curl_conncache_destroy(&multi->conn_cache);
@ -1870,7 +1868,7 @@ CURLMcode curl_multi_cleanup(CURLM *multi_handle)
Curl_close(multi->closure_handle); Curl_close(multi->closure_handle);
} }
Curl_hash_destroy(multi->sockhash); Curl_hash_clean(&multi->sockhash);
Curl_conncache_destroy(&multi->conn_cache); Curl_conncache_destroy(&multi->conn_cache);
Curl_llist_destroy(multi->msglist, NULL); Curl_llist_destroy(multi->msglist, NULL);
Curl_llist_destroy(multi->pending, NULL); Curl_llist_destroy(multi->pending, NULL);
@ -1982,7 +1980,7 @@ static void singlesocket(struct Curl_multi *multi,
s = socks[i]; s = socks[i];
/* get it from the hash */ /* get it from the hash */
entry = Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s)); entry = Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
if(curraction & GETSOCK_READSOCK(i)) if(curraction & GETSOCK_READSOCK(i))
action |= CURL_POLL_IN; action |= CURL_POLL_IN;
@ -1997,7 +1995,7 @@ static void singlesocket(struct Curl_multi *multi,
} }
else { else {
/* this is a socket we didn't have before, add it! */ /* this is a socket we didn't have before, add it! */
entry = sh_addentry(multi->sockhash, s, data); entry = sh_addentry(&multi->sockhash, s, data);
if(!entry) if(!entry)
/* fatal */ /* fatal */
return; return;
@ -2033,7 +2031,7 @@ static void singlesocket(struct Curl_multi *multi,
/* this socket has been removed. Tell the app to remove it */ /* this socket has been removed. Tell the app to remove it */
remove_sock_from_hash = TRUE; remove_sock_from_hash = TRUE;
entry = Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s)); entry = Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
if(entry) { if(entry) {
/* check if the socket to be removed serves a connection which has /* check if the socket to be removed serves a connection which has
other easy-s in a pipeline. In this case the socket should not be other easy-s in a pipeline. In this case the socket should not be
@ -2088,7 +2086,7 @@ static void singlesocket(struct Curl_multi *multi,
CURL_POLL_REMOVE, CURL_POLL_REMOVE,
multi->socket_userp, multi->socket_userp,
entry->socketp); entry->socketp);
sh_delentry(multi->sockhash, s); sh_delentry(&multi->sockhash, s);
} }
} }
@ -2115,7 +2113,7 @@ void Curl_multi_closed(struct connectdata *conn, curl_socket_t s)
/* this is set if this connection is part of a handle that is added to /* this is set if this connection is part of a handle that is added to
a multi handle, and only then this is necessary */ a multi handle, and only then this is necessary */
struct Curl_sh_entry *entry = struct Curl_sh_entry *entry =
Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s)); Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
if(entry) { if(entry) {
if(multi->socket_cb) if(multi->socket_cb)
@ -2124,7 +2122,7 @@ void Curl_multi_closed(struct connectdata *conn, curl_socket_t s)
entry->socketp); entry->socketp);
/* now remove it from the socket hash */ /* now remove it from the socket hash */
sh_delentry(multi->sockhash, s); sh_delentry(&multi->sockhash, s);
} }
} }
} }
@ -2217,7 +2215,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
else if(s != CURL_SOCKET_TIMEOUT) { else if(s != CURL_SOCKET_TIMEOUT) {
struct Curl_sh_entry *entry = struct Curl_sh_entry *entry =
Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s)); Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
if(!entry) if(!entry)
/* Unmatched socket, we can't act on it but we ignore this fact. In /* Unmatched socket, we can't act on it but we ignore this fact. In
@ -2709,7 +2707,8 @@ CURLMcode curl_multi_assign(CURLM *multi_handle,
struct Curl_multi *multi = (struct Curl_multi *)multi_handle; struct Curl_multi *multi = (struct Curl_multi *)multi_handle;
if(s != CURL_SOCKET_BAD) if(s != CURL_SOCKET_BAD)
there = Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(curl_socket_t)); there = Curl_hash_pick(&multi->sockhash, (char *)&s,
sizeof(curl_socket_t));
if(!there) if(!there)
return CURLM_BAD_SOCKET; return CURLM_BAD_SOCKET;
@ -2793,7 +2792,7 @@ void Curl_multi_dump(const struct Curl_multi *multi_handle)
for(i=0; i < data->numsocks; i++) { for(i=0; i < data->numsocks; i++) {
curl_socket_t s = data->sockets[i]; curl_socket_t s = data->sockets[i];
struct Curl_sh_entry *entry = struct Curl_sh_entry *entry =
Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s)); Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
fprintf(stderr, "%d ", (int)s); fprintf(stderr, "%d ", (int)s);
if(!entry) { if(!entry) {

View File

@ -95,7 +95,7 @@ struct Curl_multi {
/* 'sockhash' is the lookup hash for socket descriptor => easy handles (note /* 'sockhash' is the lookup hash for socket descriptor => easy handles (note
the pluralis form, there can be more than one easy handle waiting on the the pluralis form, there can be more than one easy handle waiting on the
same actual socket) */ same actual socket) */
struct curl_hash *sockhash; struct curl_hash sockhash;
/* Whether pipelining is enabled for this multi handle */ /* Whether pipelining is enabled for this multi handle */
bool pipelining_enabled; bool pipelining_enabled;