int nr_stun_client_failed(nr_stun_client_ctx *ctx) { nr_stun_client_cancel(ctx); ctx->state=NR_STUN_CLIENT_STATE_FAILED; nr_stun_client_fire_finished_cb(ctx); return(0); }
int nr_turn_client_cancel(nr_turn_client_ctx *ctx) { nr_turn_stun_ctx *stun = 0; if (ctx->state == NR_TURN_CLIENT_STATE_CANCELLED || ctx->state == NR_TURN_CLIENT_STATE_FAILED) return(0); if (ctx->label) r_log(NR_LOG_TURN, LOG_INFO, "TURN(%s): cancelling", ctx->label); /* Cancel the STUN client ctxs */ stun = STAILQ_FIRST(&ctx->stun_ctxs); while (stun) { nr_stun_client_cancel(stun->stun); stun = STAILQ_NEXT(stun, entry); } /* Cancel the timers, if not already cancelled */ NR_async_timer_cancel(ctx->connected_timer_handle); NR_async_timer_cancel(ctx->refresh_timer_handle); ctx->state = NR_TURN_CLIENT_STATE_CANCELLED; return(0); }
int nr_stun_client_wait(nr_stun_client_ctx *ctx) { nr_stun_client_cancel(ctx); ctx->state=NR_STUN_CLIENT_STATE_WAITING; ctx->request_ct = ctx->maximum_transmits; ctx->timeout_ms = ctx->maximum_transmits_timeout_ms; NR_ASYNC_TIMER_SET(ctx->timeout_ms, nr_stun_client_timer_expired_cb, ctx, &ctx->timer_handle); return(0); }
int nr_ice_candidate_pair_cancel(nr_ice_peer_ctx *pctx,nr_ice_cand_pair *pair) { if(pair->state != NR_ICE_PAIR_STATE_FAILED){ /* If it's already running we need to terminate the stun */ if(pair->state==NR_ICE_PAIR_STATE_IN_PROGRESS){ nr_stun_client_cancel(pair->stun_client); } nr_ice_candidate_pair_set_state(pctx,pair,NR_ICE_PAIR_STATE_CANCELLED); } return(0); }
int nr_turn_client_cancel(nr_turn_client_ctx *ctx) { int i; if (ctx->state == NR_TURN_CLIENT_STATE_RUNNING || ctx->state == NR_TURN_CLIENT_STATE_ALLOCATED) { for (i = 0; i < NUMBER_OF_STUN_CTX; ++i) { if (ctx->stun_ctx[i]) nr_stun_client_cancel(ctx->stun_ctx[i]); } } ctx->state=NR_TURN_CLIENT_STATE_CANCELLED; return(0); }
int nr_turn_client_cancel(nr_turn_client_ctx *ctx) { nr_turn_stun_ctx *stun = 0; if (ctx->state == NR_TURN_CLIENT_STATE_CANCELLED || ctx->state == NR_TURN_CLIENT_STATE_FAILED) return 0; if (ctx->label) r_log(NR_LOG_TURN, LOG_INFO, "TURN(%s): cancelling", ctx->label); /* If we are waiting for connect, we need to stop waiting for writability */ if (ctx->state == NR_TURN_CLIENT_STATE_INITTED || ctx->state == NR_TURN_CLIENT_STATE_ALLOCATION_WAIT) { NR_SOCKET fd; int r; r = nr_socket_getfd(ctx->sock, &fd); if (r) { /* We should be able to get the fd, but if we get an error, we shouldn't cancel. */ r_log(NR_LOG_TURN, LOG_ERR, "TURN: Couldn't get internal fd"); } else { NR_ASYNC_CANCEL(fd, NR_ASYNC_WAIT_WRITE); } } /* Cancel the STUN client ctxs */ stun = STAILQ_FIRST(&ctx->stun_ctxs); while (stun) { nr_stun_client_cancel(stun->stun); stun = STAILQ_NEXT(stun, entry); } /* Cancel the timers, if not already cancelled */ NR_async_timer_cancel(ctx->connected_timer_handle); NR_async_timer_cancel(ctx->refresh_timer_handle); ctx->state = NR_TURN_CLIENT_STATE_CANCELLED; return(0); }