static void stun_tsx_on_complete(pj_stun_client_tsx *tsx, pj_status_t status, const pj_stun_msg *response, const pj_sockaddr_t *src_addr, unsigned src_addr_len) { pj_stun_session *sess; pj_bool_t notify_user = PJ_TRUE; pj_stun_tx_data *tdata; tdata = (pj_stun_tx_data*) pj_stun_client_tsx_get_data(tsx); sess = tdata->sess; /* Lock the session and prevent user from destroying us in the callback */ pj_grp_lock_acquire(sess->grp_lock); if (sess->is_destroying) { pj_stun_msg_destroy_tdata(sess, tdata); pj_grp_lock_release(sess->grp_lock); return; } /* Handle authentication challenge */ handle_auth_challenge(sess, tdata, response, src_addr, src_addr_len, ¬ify_user); if (notify_user && sess->cb.on_request_complete) { (*sess->cb.on_request_complete)(sess, status, tdata->token, tdata, response, src_addr, src_addr_len); } /* Destroy the transmit data. This will remove the transaction * from the pending list too. */ if (status == PJNATH_ESTUNTIMEDOUT) destroy_tdata(tdata, PJ_TRUE); else destroy_tdata(tdata, PJ_FALSE); tdata = NULL; pj_grp_lock_release(sess->grp_lock); }
static void stun_sess_on_destroy(void *comp) { pj_stun_session *sess = (pj_stun_session*)comp; while (!pj_list_empty(&sess->pending_request_list)) { pj_stun_tx_data *tdata = sess->pending_request_list.next; destroy_tdata(tdata, PJ_TRUE); } while (!pj_list_empty(&sess->cached_response_list)) { pj_stun_tx_data *tdata = sess->cached_response_list.next; destroy_tdata(tdata, PJ_TRUE); } if (sess->rx_pool) { pj_pool_release(sess->rx_pool); sess->rx_pool = NULL; } pj_pool_release(sess->pool); TRACE_((THIS_FILE, "STUN session %p destroyed", sess)); }
PJ_DEF(pj_status_t) pj_stun_session_destroy(pj_stun_session *sess) { PJ_ASSERT_RETURN(sess, PJ_EINVAL); pj_lock_acquire(sess->lock); /* Can't destroy if we're in a callback */ sess->destroy_request = PJ_TRUE; if (pj_atomic_get(sess->busy)) { pj_lock_release(sess->lock); return PJ_EPENDING; } while (!pj_list_empty(&sess->pending_request_list)) { pj_stun_tx_data *tdata = sess->pending_request_list.next; destroy_tdata(tdata, PJ_TRUE); } while (!pj_list_empty(&sess->cached_response_list)) { pj_stun_tx_data *tdata = sess->cached_response_list.next; destroy_tdata(tdata, PJ_TRUE); } pj_lock_release(sess->lock); if (sess->delete_lock) { pj_lock_destroy(sess->lock); } if (sess->rx_pool) { pj_pool_release(sess->rx_pool); sess->rx_pool = NULL; } pj_pool_release(sess->pool); return PJ_SUCCESS; }
/* Timer callback to be called when it's time to destroy response cache */ static void on_cache_timeout(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry) { pj_stun_tx_data *tdata; PJ_UNUSED_ARG(timer_heap); entry->id = PJ_FALSE; tdata = (pj_stun_tx_data*) entry->user_data; PJ_LOG(5,(SNAME(tdata->sess), "Response cache deleted")); pj_list_erase(tdata); destroy_tdata(tdata, PJ_FALSE); }
void remunge_cleanup (tdata_t tdata) { /* Signal the main thread when the last worker thread is exiting. * Clean up resources held by the thread. */ if (--tdata->conf->num_running == 0) { if ((errno = pthread_cond_signal (&tdata->conf->cond_done)) != 0) { log_errno (EMUNGE_SNAFU, LOG_ERR, "Failed to signal condition"); } } if ((errno = pthread_mutex_unlock (&tdata->conf->mutex)) != 0) { log_errno (EMUNGE_SNAFU, LOG_ERR, "Failed to unlock mutex"); } destroy_tdata (tdata); return; }
/* * Destroy the transmit data. */ PJ_DEF(void) pj_stun_msg_destroy_tdata( pj_stun_session *sess, pj_stun_tx_data *tdata) { PJ_UNUSED_ARG(sess); destroy_tdata(tdata, PJ_FALSE); }