multi: introduce sh_getentry() for looking up sockets in the sockhash
Simplify the code by using a single entry that looks for a socket in the socket hash. As indicated in #712, the code looked for CURL_SOCKET_BAD at some point and that is ineffective/wrong and this makes it easier to avoid that.
This commit is contained in:
parent
c0717a7059
commit
8eaf884417
42
lib/multi.c
42
lib/multi.c
@ -172,13 +172,22 @@ struct Curl_sh_entry {
|
|||||||
#define SH_READ 1
|
#define SH_READ 1
|
||||||
#define SH_WRITE 2
|
#define SH_WRITE 2
|
||||||
|
|
||||||
|
/* look up a given socket in the socket hash, skip invalid sockets */
|
||||||
|
static struct Curl_sh_entry *sh_getentry(struct curl_hash *sh,
|
||||||
|
curl_socket_t s)
|
||||||
|
{
|
||||||
|
if(s != CURL_SOCKET_BAD)
|
||||||
|
/* only look for proper sockets */
|
||||||
|
return Curl_hash_pick(sh, (char *)&s, sizeof(curl_socket_t));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* make sure this socket is present in the hash for this handle */
|
/* make sure this socket is present in the hash for this handle */
|
||||||
static struct Curl_sh_entry *sh_addentry(struct curl_hash *sh,
|
static struct Curl_sh_entry *sh_addentry(struct curl_hash *sh,
|
||||||
curl_socket_t s,
|
curl_socket_t s,
|
||||||
struct SessionHandle *data)
|
struct SessionHandle *data)
|
||||||
{
|
{
|
||||||
struct Curl_sh_entry *there =
|
struct Curl_sh_entry *there = sh_getentry(sh, s);
|
||||||
Curl_hash_pick(sh, (char *)&s, sizeof(curl_socket_t));
|
|
||||||
struct Curl_sh_entry *check;
|
struct Curl_sh_entry *check;
|
||||||
|
|
||||||
if(there)
|
if(there)
|
||||||
@ -206,15 +215,9 @@ static struct Curl_sh_entry *sh_addentry(struct curl_hash *sh,
|
|||||||
/* delete the given socket + handle from the hash */
|
/* delete the given socket + handle from the hash */
|
||||||
static void sh_delentry(struct curl_hash *sh, curl_socket_t s)
|
static void sh_delentry(struct curl_hash *sh, curl_socket_t s)
|
||||||
{
|
{
|
||||||
struct Curl_sh_entry *there =
|
/* We remove the hash entry. This will end up in a call to
|
||||||
Curl_hash_pick(sh, (char *)&s, sizeof(curl_socket_t));
|
sh_freeentry(). */
|
||||||
|
Curl_hash_delete(sh, (char *)&s, sizeof(curl_socket_t));
|
||||||
if(there) {
|
|
||||||
/* this socket is in the hash */
|
|
||||||
/* We remove the hash entry. (This'll end up in a call to
|
|
||||||
sh_freeentry().) */
|
|
||||||
Curl_hash_delete(sh, (char *)&s, sizeof(curl_socket_t));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2019,7 +2022,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 = sh_getentry(&multi->sockhash, s);
|
||||||
|
|
||||||
if(curraction & GETSOCK_READSOCK(i))
|
if(curraction & GETSOCK_READSOCK(i))
|
||||||
action |= CURL_POLL_IN;
|
action |= CURL_POLL_IN;
|
||||||
@ -2070,7 +2073,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 = sh_getentry(&multi->sockhash, 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
|
||||||
@ -2151,8 +2154,7 @@ void Curl_multi_closed(struct connectdata *conn, curl_socket_t s)
|
|||||||
if(multi) {
|
if(multi) {
|
||||||
/* 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 = sh_getentry(&multi->sockhash, s);
|
||||||
Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
|
|
||||||
|
|
||||||
if(entry) {
|
if(entry) {
|
||||||
if(multi->socket_cb)
|
if(multi->socket_cb)
|
||||||
@ -2253,8 +2255,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 = sh_getentry(&multi->sockhash, 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
|
||||||
@ -2741,9 +2742,7 @@ CURLMcode curl_multi_assign(CURLM *multi_handle,
|
|||||||
struct Curl_sh_entry *there = NULL;
|
struct Curl_sh_entry *there = NULL;
|
||||||
struct Curl_multi *multi = (struct Curl_multi *)multi_handle;
|
struct Curl_multi *multi = (struct Curl_multi *)multi_handle;
|
||||||
|
|
||||||
if(s != CURL_SOCKET_BAD)
|
there = sh_getentry(&multi->sockhash, s);
|
||||||
there = Curl_hash_pick(&multi->sockhash, (char *)&s,
|
|
||||||
sizeof(curl_socket_t));
|
|
||||||
|
|
||||||
if(!there)
|
if(!there)
|
||||||
return CURLM_BAD_SOCKET;
|
return CURLM_BAD_SOCKET;
|
||||||
@ -2821,8 +2820,7 @@ void Curl_multi_dump(const struct Curl_multi *multi_handle)
|
|||||||
statename[data->mstate], data->numsocks);
|
statename[data->mstate], data->numsocks);
|
||||||
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 = sh_getentry(&multi->sockhash, s);
|
||||||
Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
|
|
||||||
|
|
||||||
fprintf(stderr, "%d ", (int)s);
|
fprintf(stderr, "%d ", (int)s);
|
||||||
if(!entry) {
|
if(!entry) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user