- Timestamp:
- Jul 24, 2013 8:06:59 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/nat_detect.c
r4537 r4573 76 76 { 77 77 pj_pool_t *pool; 78 pj_ mutex_t *mutex;78 pj_grp_lock_t *grp_lock; 79 79 80 80 pj_timer_heap_t *timer_heap; … … 134 134 pj_timer_entry *te); 135 135 static void sess_destroy(nat_detect_session *sess); 136 136 static void sess_on_destroy(void *member); 137 137 138 138 /* … … 234 234 sess->cb = cb; 235 235 236 status = pj_mutex_create_recursive(pool, pool->obj_name, &sess->mutex); 237 if (status != PJ_SUCCESS) 238 goto on_error; 239 236 status = pj_grp_lock_create(pool, NULL, &sess->grp_lock); 237 if (status != PJ_SUCCESS) { 238 /* Group lock not created yet, just destroy pool and return */ 239 pj_pool_release(pool); 240 return status; 241 } 242 243 pj_grp_lock_add_ref(sess->grp_lock); 244 pj_grp_lock_add_handler(sess->grp_lock, pool, sess, &sess_on_destroy); 245 240 246 pj_memcpy(&sess->server, server, sizeof(pj_sockaddr_in)); 241 247 … … 295 301 ioqueue_cb.on_read_complete = &on_read_complete; 296 302 297 status = pj_ioqueue_register_sock (sess->pool, stun_cfg->ioqueue,298 sess->sock, sess, &ioqueue_cb,299 &sess->key);303 status = pj_ioqueue_register_sock2(sess->pool, stun_cfg->ioqueue, 304 sess->sock, sess->grp_lock, sess, 305 &ioqueue_cb, &sess->key); 300 306 if (status != PJ_SUCCESS) 301 307 goto on_error; … … 308 314 sess_cb.on_send_msg = &on_send_msg; 309 315 status = pj_stun_session_create(stun_cfg, pool->obj_name, &sess_cb, 310 PJ_FALSE, NULL, &sess->stun_sess);316 PJ_FALSE, sess->grp_lock, &sess->stun_sess); 311 317 if (status != PJ_SUCCESS) 312 318 goto on_error; … … 339 345 if (sess->stun_sess) { 340 346 pj_stun_session_destroy(sess->stun_sess); 347 sess->stun_sess = NULL; 341 348 } 342 349 343 350 if (sess->key) { 344 351 pj_ioqueue_unregister(sess->key); 352 sess->key = NULL; 353 sess->sock = PJ_INVALID_SOCKET; 345 354 } else if (sess->sock && sess->sock != PJ_INVALID_SOCKET) { 346 355 pj_sock_close(sess->sock); 347 } 348 349 if (sess->mutex) { 350 pj_mutex_destroy(sess->mutex); 351 } 352 356 sess->sock = PJ_INVALID_SOCKET; 357 } 358 359 if (sess->grp_lock) { 360 pj_grp_lock_dec_ref(sess->grp_lock); 361 } 362 } 363 364 static void sess_on_destroy(void *member) 365 { 366 nat_detect_session *sess = (nat_detect_session*)member; 353 367 if (sess->pool) { 354 368 pj_pool_release(sess->pool); 355 369 } 356 370 } 357 358 371 359 372 static void end_session(nat_detect_session *sess, … … 403 416 pj_assert(sess != NULL); 404 417 405 pj_mutex_lock(sess->mutex); 418 pj_grp_lock_acquire(sess->grp_lock); 419 420 /* Ignore packet when STUN session has been destroyed */ 421 if (!sess->stun_sess) 422 goto on_return; 406 423 407 424 if (bytes_read < 0) { … … 436 453 437 454 on_return: 438 pj_ mutex_unlock(sess->mutex);455 pj_grp_lock_release(sess->grp_lock); 439 456 } 440 457 … … 491 508 sess = (nat_detect_session*) pj_stun_session_get_user_data(stun_sess); 492 509 493 pj_ mutex_lock(sess->mutex);510 pj_grp_lock_acquire(sess->grp_lock); 494 511 495 512 /* Find errors in the response */ … … 787 804 788 805 on_return: 789 pj_ mutex_unlock(sess->mutex);806 pj_grp_lock_release(sess->grp_lock); 790 807 } 791 808 … … 866 883 867 884 if (te->id == TIMER_DESTROY) { 868 pj_ mutex_lock(sess->mutex);885 pj_grp_lock_acquire(sess->grp_lock); 869 886 pj_ioqueue_unregister(sess->key); 870 887 sess->key = NULL; 871 888 sess->sock = PJ_INVALID_SOCKET; 872 889 te->id = 0; 873 pj_ mutex_unlock(sess->mutex);890 pj_grp_lock_release(sess->grp_lock); 874 891 875 892 sess_destroy(sess); … … 879 896 pj_bool_t next_timer; 880 897 881 pj_ mutex_lock(sess->mutex);898 pj_grp_lock_acquire(sess->grp_lock); 882 899 883 900 next_timer = PJ_FALSE; … … 904 921 } 905 922 906 pj_ mutex_unlock(sess->mutex);923 pj_grp_lock_release(sess->grp_lock); 907 924 908 925 } else {
Note: See TracChangeset
for help on using the changeset viewer.