Changeset 2136
- Timestamp:
- Jul 14, 2008 2:14:00 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/ice_strans.c
r2090 r2136 23 23 #include <pj/assert.h> 24 24 #include <pj/ip_helper.h> 25 #include <pj/lock.h> 25 26 #include <pj/log.h> 26 27 #include <pj/os.h> … … 156 157 pj_ice_strans_cfg cfg; /**< Configuration. */ 157 158 pj_ice_strans_cb cb; /**< Application callback. */ 159 pj_lock_t *init_lock; /**< Initialization mutex. */ 158 160 159 161 pj_ice_sess *ice; /**< ICE session. */ … … 269 271 ///sess_add_ref(ice_st); 270 272 273 PJ_LOG(4,(ice_st->obj_name, 274 "Comp %d: srflx candidate starts Binding discovery", 275 comp_id)); 276 271 277 /* Start Binding resolution */ 272 278 status = pj_stun_sock_start(comp->stun_sock, … … 286 292 } 287 293 288 /* Add srflx candidate with pending status */294 /* Add srflx candidate with pending status. */ 289 295 cand = &comp->cand_list[comp->cand_cnt++]; 290 296 cand->type = PJ_ICE_CAND_TYPE_SRFLX; … … 297 303 pj_ice_calc_foundation(ice_st->pool, &cand->foundation, 298 304 cand->type, &cand->base_addr); 299 PJ_LOG(4,(ice_st->obj_name,300 "Comp %d: srflx candidate starts Binding discovery",301 comp_id));302 305 303 306 /* Set default candidate to srflx */ 304 307 comp->default_cand = cand - comp->cand_list; 308 305 309 } 306 310 … … 453 457 } 454 458 459 status = pj_lock_create_recursive_mutex(pool, ice_st->obj_name, 460 &ice_st->init_lock); 461 if (status != PJ_SUCCESS) { 462 destroy_ice_st(ice_st); 463 return status; 464 } 465 455 466 ice_st->comp_cnt = comp_cnt; 456 467 ice_st->comp = (pj_ice_strans_comp**) 457 468 pj_pool_calloc(pool, comp_cnt, sizeof(pj_ice_strans_comp*)); 458 469 470 /* Acquire initialization mutex to prevent callback to be 471 * called before we finish initialization. 472 */ 473 pj_lock_acquire(ice_st->init_lock); 474 459 475 for (i=0; i<comp_cnt; ++i) { 460 476 status = create_comp(ice_st, i+1); 461 477 if (status != PJ_SUCCESS) { 478 pj_lock_release(ice_st->init_lock); 462 479 destroy_ice_st(ice_st); 463 480 return status; 464 481 } 465 482 } 483 484 /* Done with initialization */ 485 pj_lock_release(ice_st->init_lock); 466 486 467 487 /* Check if all candidates are ready (this may call callback) */ … … 501 521 } 502 522 ice_st->comp_cnt = 0; 523 524 /* Destroy mutex */ 525 if (ice_st->init_lock) { 526 pj_lock_acquire(ice_st->init_lock); 527 pj_lock_release(ice_st->init_lock); 528 pj_lock_destroy(ice_st->init_lock); 529 ice_st->init_lock = NULL; 530 } 503 531 504 532 /* Destroy reference counter */ … … 1199 1227 unsigned i; 1200 1228 1229 pj_assert(status != PJ_EPENDING); 1230 1201 1231 comp = (pj_ice_strans_comp*) pj_stun_sock_get_user_data(stun_sock); 1202 1232 ice_st = comp->ice_st; 1203 1233 1204 1234 sess_add_ref(ice_st); 1235 1236 /* Wait until initialization completes */ 1237 pj_lock_acquire(ice_st->init_lock); 1205 1238 1206 1239 /* Find the srflx cancidate */ … … 1212 1245 } 1213 1246 1214 pj_assert(status != PJ_EPENDING); 1247 pj_lock_release(ice_st->init_lock); 1248 1249 /* It is possible that we don't have srflx candidate even though this 1250 * callback is called. This could happen when we cancel adding srflx 1251 * candidate due to initialization error. 1252 */ 1253 if (cand == NULL) { 1254 return sess_dec_ref(ice_st); 1255 } 1215 1256 1216 1257 switch (op) { … … 1364 1405 pj_turn_sock_get_info(turn_sock, &rel_info); 1365 1406 1407 /* Wait until initialization completes */ 1408 pj_lock_acquire(comp->ice_st->init_lock); 1409 1366 1410 /* Find relayed candidate in the component */ 1367 1411 for (i=0; i<comp->cand_cnt; ++i) { … … 1372 1416 } 1373 1417 pj_assert(cand != NULL); 1418 1419 pj_lock_release(comp->ice_st->init_lock); 1374 1420 1375 1421 /* Update candidate */
Note: See TracChangeset
for help on using the changeset viewer.