summaryrefslogtreecommitdiff
path: root/pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-12-26 03:56:29 +0000
committerBenny Prijono <bennylp@teluu.com>2006-12-26 03:56:29 +0000
commitf9017cbd238e567ae0bea2c60611bd8fd8814e3e (patch)
tree3d84be440b523d871dfae27492c78fd401a13b31 /pjsip
parentbbfa7dfea405d9c1de743aee269e30449839dde2 (diff)
Fixed ticket #42: duplicate hash entry when TCP/TLS connection is created while previous one is shutting down
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@866 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r--pjsip/src/pjsip/sip_transport.c25
-rw-r--r--pjsip/src/pjsip/sip_transport_tcp.c2
2 files changed, 22 insertions, 5 deletions
diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c
index 8fd80d52..38db3993 100644
--- a/pjsip/src/pjsip/sip_transport.c
+++ b/pjsip/src/pjsip/sip_transport.c
@@ -638,6 +638,8 @@ PJ_DEF(pj_status_t) pjsip_transport_register( pjsip_tpmgr *mgr,
pjsip_transport *tp )
{
int key_len;
+ pj_uint32_t hval;
+ void *entry;
/* Init. */
tp->tpmgr = mgr;
@@ -646,11 +648,20 @@ PJ_DEF(pj_status_t) pjsip_transport_register( pjsip_tpmgr *mgr,
tp->idle_timer.cb = &transport_idle_callback;
/*
- * Register to hash table.
+ * Register to hash table (see Trac ticket #42).
*/
key_len = sizeof(tp->key.type) + tp->addr_len;
pj_lock_acquire(mgr->lock);
- pj_hash_set(tp->pool, mgr->table, &tp->key, key_len, 0, tp);
+
+ /* If entry already occupied, unregister previous entry */
+ hval = 0;
+ entry = pj_hash_get(mgr->table, &tp->key, key_len, &hval);
+ if (entry != NULL)
+ pj_hash_set(NULL, mgr->table, &tp->key, key_len, hval, NULL);
+
+ /* Register new entry */
+ pj_hash_set(tp->pool, mgr->table, &tp->key, key_len, hval, tp);
+
pj_lock_release(mgr->lock);
TRACE_((THIS_FILE,"Transport %s registered: type=%s, remote=%s:%d",
@@ -667,6 +678,8 @@ static pj_status_t destroy_transport( pjsip_tpmgr *mgr,
pjsip_transport *tp )
{
int key_len;
+ pj_uint32_t hval;
+ void *entry;
TRACE_((THIS_FILE, "Transport %s is being destroyed", tp->obj_name));
@@ -683,11 +696,13 @@ static pj_status_t destroy_transport( pjsip_tpmgr *mgr,
}
/*
- * Unregister from hash table.
+ * Unregister from hash table (see Trac ticket #42).
*/
key_len = sizeof(tp->key.type) + tp->addr_len;
- pj_assert(pj_hash_get(mgr->table, &tp->key, key_len, NULL) != NULL);
- pj_hash_set(tp->pool, mgr->table, &tp->key, key_len, 0, NULL);
+ hval = 0;
+ entry = pj_hash_get(mgr->table, &tp->key, key_len, &hval);
+ if (entry == (void*)tp)
+ pj_hash_set(NULL, mgr->table, &tp->key, key_len, hval, NULL);
pj_lock_release(mgr->lock);
diff --git a/pjsip/src/pjsip/sip_transport_tcp.c b/pjsip/src/pjsip/sip_transport_tcp.c
index b3a03c06..7eefec48 100644
--- a/pjsip/src/pjsip/sip_transport_tcp.c
+++ b/pjsip/src/pjsip/sip_transport_tcp.c
@@ -1221,6 +1221,7 @@ static void on_read_complete(pj_ioqueue_key_t *key,
{
/* Socket error. */
+ PJ_LOG(4,(tcp->base.obj_name, "TCP connection reset"));
/* We can not destroy the transport since high level objects may
* still keep reference to this transport. So we can only
@@ -1262,6 +1263,7 @@ static void on_read_complete(pj_ioqueue_key_t *key,
} else {
/* Socket error */
+ PJ_LOG(4,(tcp->base.obj_name, "TCP connection reset"));
/* We can not destroy the transport since high level objects may
* still keep reference to this transport. So we can only