Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hash_remove and use in transp to fix #261 #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/re_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct pl;
int hash_alloc(struct hash **hp, uint32_t bsize);
void hash_append(struct hash *h, uint32_t key, struct le *le, void *data);
void hash_unlink(struct le *le);
void hash_remove(struct le *le);
struct le *hash_lookup(const struct hash *h, uint32_t key, list_apply_h *ah,
void *arg);
struct le *hash_apply(const struct hash *h, list_apply_h *ah, void *arg);
Expand Down
17 changes: 17 additions & 0 deletions src/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ void hash_unlink(struct le *le)
}


/**
* If the element is present in the hashmap table, unlink it and deref the object,
* otherwise do nothing. This is like hash_flush but for a single entry.
*
* @param le List element
*/
void hash_remove(struct le *le)
{
if (le->list != NULL)
{
void *data = le->data;
list_unlink(le);
mem_deref(data);
}
}


/**
* Apply a handler function to all elements in the hashmap with a matching key
*
Expand Down
6 changes: 1 addition & 5 deletions src/sip/transp.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ static void conn_close(struct sip_conn *conn, int err)
conn->tc = mem_deref(conn->tc);
tmr_cancel(&conn->tmr_ka);
tmr_cancel(&conn->tmr);
hash_unlink(&conn->he);

le = list_head(&conn->ql);

Expand All @@ -195,6 +194,7 @@ static void conn_close(struct sip_conn *conn, int err)
}

sip_keepalive_signal(&conn->kal, err);
hash_remove(&conn->he);
}


Expand All @@ -203,7 +203,6 @@ static void conn_tmr_handler(void *arg)
struct sip_conn *conn = arg;

conn_close(conn, ETIMEDOUT);
mem_deref(conn);
}


Expand All @@ -221,7 +220,6 @@ static void conn_keepalive_handler(void *arg)
err = tcp_send(conn->tc, &mb);
if (err) {
conn_close(conn, err);
mem_deref(conn);
return;
}

Expand Down Expand Up @@ -448,7 +446,6 @@ static void tcp_recv_handler(struct mbuf *mb, void *arg)
out:
if (err) {
conn_close(conn, err);
mem_deref(conn);
}
}

Expand Down Expand Up @@ -492,7 +489,6 @@ static void tcp_close_handler(int err, void *arg)
struct sip_conn *conn = arg;

conn_close(conn, err ? err : ECONNRESET);
mem_deref(conn);
}


Expand Down