Commit 2be6cb2c authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Initialize sockets and test for errors.

parent 13c6ca70
......@@ -208,7 +208,10 @@ unsigned long belle_sip_resolve(belle_sip_stack_t *stack, const char *name, int
ctx->ai = NULL;
if (family == 0) family = AF_UNSPEC;
ctx->family = family;
resolver_start_query(ctx, (belle_sip_source_func_t)resolver_process_a_data, DNS_T_A, belle_sip_stack_get_dns_timeout(stack));
if (resolver_start_query(ctx, (belle_sip_source_func_t)resolver_process_a_data, DNS_T_A, belle_sip_stack_get_dns_timeout(stack)) < 0) {
belle_sip_object_unref(ctx);
return 0;
}
/*the resolver context must never be removed manually from the main loop*/
belle_sip_main_loop_add_source(ml,(belle_sip_source_t*)ctx);
......
......@@ -44,7 +44,9 @@ static unsigned int wait_for(belle_sip_stack_t *stack, int *current_value, int
}
static endpoint_t* create_endpoint(void) {
endpoint_t* endpoint = belle_sip_new0(endpoint_t);
endpoint_t* endpoint;
if (belle_sip_init_sockets() < 0) return NULL;
endpoint = belle_sip_new0(endpoint_t);
endpoint->stack = belle_sip_stack_new(NULL);
return endpoint;
}
......@@ -52,6 +54,7 @@ static endpoint_t* create_endpoint(void) {
static void destroy_endpoint(endpoint_t* endpoint) {
belle_sip_object_unref(endpoint->stack);
belle_sip_free(endpoint);
belle_sip_uninit_sockets();
}
static void resolve_done(void *data, const char *name, struct addrinfo *res) {
......@@ -66,6 +69,7 @@ static void resolve(void) {
const char* peer_name = SIPDOMAIN;
int peer_port = SIPPORT;
endpoint_t* client = create_endpoint();
CU_ASSERT_PTR_NOT_NULL_FATAL(client);
client->resolver_id = belle_sip_resolve(client->stack, peer_name, peer_port, 0, resolve_done, client, belle_sip_stack_get_main_loop(client->stack));
CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, 2000));
CU_ASSERT_TRUE((client->resolve_successful == 1));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment