Commit d065a2d4 authored by jehan's avatar jehan
Browse files

make sure dns tiemout is reported

parent 5c4514cf
......@@ -394,13 +394,15 @@ void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){
if (revents!=0 || (s->timeout>=0 && cur>=s->expire_ms)){
char *objdesc=belle_sip_object_to_string((belle_sip_object_t*)s);
s->expired=TRUE;
if (revents==0)
revents=BELLE_SIP_EVENT_TIMEOUT;
if (s->timeout>0)/*to avoid too many traces*/ belle_sip_debug("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout);
belle_sip_free(objdesc);
ret=s->notify(s->data,revents);
if (ret==BELLE_SIP_STOP || s->oneshot){
/*this source needs to be removed*/
belle_sip_main_loop_remove_source(ml,s);
}else if (revents==0){
}else if (revents==BELLE_SIP_EVENT_TIMEOUT){
/*timeout needs to be started again */
s->expire_ms+=s->timeout;
s->expired=FALSE;
......
......@@ -102,6 +102,7 @@ static int resolver_process_a_data(belle_sip_resolver_context_t *ctx, unsigned i
if (revents & BELLE_SIP_EVENT_TIMEOUT) {
belle_sip_error("%s timed-out", __FUNCTION__);
ctx->cb(ctx->cb_data, ctx->name, NULL);
return BELLE_SIP_STOP;
}
if (ctx->cancelled) {
......
......@@ -138,7 +138,7 @@ int belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents
belle_sip_header_content_length_t* content_length_header;
int content_length;
if (revents) {
if (revents & BELLE_SIP_EVENT_READ) {
if (obj->recv_error>0) {
num=belle_sip_channel_recv(obj,obj->input_stream.write_ptr,belle_sip_channel_input_stream_get_buff_length(&obj->input_stream)-1);
/*write ptr is only incremented if data were acquired from the transport*/
......@@ -148,10 +148,12 @@ int belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents
} else {
num=obj->recv_error;
}
}
else
} else if (!revents) {
num=obj->input_stream.write_ptr-obj->input_stream.read_ptr;
} else {
belle_sip_error("Unexpected event [%i] on channel [%p]",revents,obj);
num=-1; /*to trigger an error*/
}
if (num>0){
......
......@@ -35,6 +35,7 @@ typedef struct endpoint {
belle_sip_stack_t* stack;
long unsigned int resolver_id;
int resolve_done;
int resolve_ko;
struct addrinfo *result;
} endpoint_t;
......@@ -61,6 +62,7 @@ static endpoint_t* create_endpoint(void) {
static void reset_endpoint(endpoint_t *endpoint) {
endpoint->resolver_id = 0;
endpoint->resolve_done = 0;
endpoint->resolve_ko = 0;
if (endpoint->result) {
freeaddrinfo(endpoint->result);
endpoint->result = NULL;
......@@ -80,7 +82,9 @@ static void resolve_done(void *data, const char *name, struct addrinfo *res) {
client->resolve_done = 1;
if (res) {
client->result = res;
}
client->resolve_done = 1;
} else
client->resolve_ko = 1;
}
/* Successful IPv4 A query */
......@@ -137,18 +141,16 @@ static void ipv4_a_query_send_failure(void) {
/* IPv4 A query timeout */
static void ipv4_a_query_timeout(void) {
int timeout = 500;
int timeout = 1;
endpoint_t *client = create_endpoint();
CU_ASSERT_PTR_NOT_NULL_FATAL(client);
belle_sip_stack_set_dns_timeout(client->stack, timeout);
belle_sip_stack_set_resolver_tx_delay(client->stack, timeout * 4);
client->resolver_id = belle_sip_resolve(client->stack, IPV4_SIP_DOMAIN, SIP_PORT, AF_INET, resolve_done, client, belle_sip_stack_get_main_loop(client->stack));
client->resolver_id = belle_sip_resolve(client->stack, "toto.com", SIP_PORT, AF_INET, resolve_done, client, belle_sip_stack_get_main_loop(client->stack));
CU_ASSERT_NOT_EQUAL(client->resolver_id, 0);
CU_ASSERT_FALSE(wait_for(client->stack, &client->resolve_done, 1, timeout * 2));
CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout * 200));
CU_ASSERT_PTR_EQUAL(client->result, NULL);
belle_sip_stack_set_resolver_tx_delay(client->stack, 0);
CU_ASSERT_EQUAL(client->resolve_ko,1);
destroy_endpoint(client);
}
......
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