/* * This function returns the addrinfo representation of the stun server address. * It is critical not to block for a long time if it can't be resolved, otherwise this stucks the main thread when making a call. * On the contrary, a fully asynchronous call initiation is complex to develop. * The compromise is then: * - have a cache of the stun server addrinfo * - this cached value is returned when it is non-null * - an asynchronous resolution is asked each time this function is called to ensure frequent refreshes of the cached value. * - if no cached value exists, block for a short time; this case must be unprobable because the resolution will be asked each time the stun server value is * changed. **/ const struct addrinfo *linphone_core_get_stun_server_addrinfo(LinphoneCore *lc){ const char *server=linphone_core_get_stun_server(lc); if (server){ int wait_ms=0; int wait_limit=1000; linphone_core_resolve_stun_server(lc); while (!lc->net_conf.stun_addrinfo && lc->net_conf.stun_res!=NULL && wait_ms<wait_limit){ sal_iterate(lc->sal); ms_usleep(50000); wait_ms+=50; } } return lc->net_conf.stun_addrinfo; }
const struct addrinfo * linphone_nat_policy_get_stun_server_addrinfo(LinphoneNatPolicy *policy) { /* * It is critical not to block for a long time if it can't be resolved, otherwise this stucks the main thread when making a call. * On the contrary, a fully asynchronous call initiation is complex to develop. * The compromise is then: * - have a cache of the stun server addrinfo * - this cached value is returned when it is non-null * - an asynchronous resolution is asked each time this function is called to ensure frequent refreshes of the cached value. * - if no cached value exists, block for a short time; this case must be unprobable because the resolution will be asked each * time the stun server value is changed. */ if (linphone_nat_policy_stun_server_activated(policy)) { int wait_ms = 0; int wait_limit = 1000; linphone_nat_policy_resolve_stun_server(policy); while ((policy->stun_addrinfo == NULL) && (policy->stun_resolver_context != NULL) && (wait_ms < wait_limit)) { sal_iterate(policy->lc->sal); ms_usleep(50000); wait_ms += 50; } } return policy->stun_addrinfo; }