#define SH_READ 1
#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 */
static struct Curl_sh_entry *sh_addentry(struct curl_hash *sh,
curl_socket_t s,
struct SessionHandle *data)
{
- struct Curl_sh_entry *there =
- Curl_hash_pick(sh, (char *)&s, sizeof(curl_socket_t));
+ struct Curl_sh_entry *there = sh_getentry(sh, s);
struct Curl_sh_entry *check;
if(there)
/* delete the given socket + handle from the hash */
static void sh_delentry(struct curl_hash *sh, curl_socket_t s)
{
- struct Curl_sh_entry *there =
- Curl_hash_pick(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));
- }
+ /* We remove the hash entry. This will end up in a call to
+ sh_freeentry(). */
+ Curl_hash_delete(sh, (char *)&s, sizeof(curl_socket_t));
}
/*
s = socks[i];
/* 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))
action |= CURL_POLL_IN;
/* this socket has been removed. Tell the app to remove it */
remove_sock_from_hash = TRUE;
- entry = Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
+ entry = sh_getentry(&multi->sockhash, s);
if(entry) {
/* 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
if(multi) {
/* this is set if this connection is part of a handle that is added to
a multi handle, and only then this is necessary */
- struct Curl_sh_entry *entry =
- Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
+ struct Curl_sh_entry *entry = sh_getentry(&multi->sockhash, s);
if(entry) {
if(multi->socket_cb)
}
else if(s != CURL_SOCKET_TIMEOUT) {
- struct Curl_sh_entry *entry =
- Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
+ struct Curl_sh_entry *entry = sh_getentry(&multi->sockhash, s);
if(!entry)
/* Unmatched socket, we can't act on it but we ignore this fact. In
struct Curl_sh_entry *there = NULL;
struct Curl_multi *multi = (struct Curl_multi *)multi_handle;
- if(s != CURL_SOCKET_BAD)
- there = Curl_hash_pick(&multi->sockhash, (char *)&s,
- sizeof(curl_socket_t));
+ there = sh_getentry(&multi->sockhash, s);
if(!there)
return CURLM_BAD_SOCKET;
statename[data->mstate], data->numsocks);
for(i=0; i < data->numsocks; i++) {
curl_socket_t s = data->sockets[i];
- struct Curl_sh_entry *entry =
- Curl_hash_pick(&multi->sockhash, (char *)&s, sizeof(s));
+ struct Curl_sh_entry *entry = sh_getentry(&multi->sockhash, s);
fprintf(stderr, "%d ", (int)s);
if(!entry) {