Commit e3fc5dce authored by Simon Morlat's avatar Simon Morlat

http test nearly working

parent 12f74f83
......@@ -32,6 +32,7 @@ static void belle_http_request_destroy(belle_http_request_t *req){
if (req->req_uri) belle_sip_object_unref(req->req_uri);
DESTROY_STRING(req,method)
belle_http_request_set_listener(req,NULL);
belle_sip_message("http request destroyed");
}
static void belle_http_request_clone(belle_http_request_t *obj, const belle_http_request_t *orig){
......@@ -79,10 +80,13 @@ belle_http_request_t *belle_http_request_create(const char *method, belle_generi
void belle_http_request_set_listener(belle_http_request_t *req, belle_http_request_listener_t *l){
if (req->listener){
belle_sip_object_weak_unref(req->listener,(belle_sip_object_destroy_notify_t)belle_http_request_listener_destroyed,req);
belle_sip_message("listener unset");
req->listener=NULL;
}
if (l)
if (l){
belle_sip_object_weak_ref(l,(belle_sip_object_destroy_notify_t)belle_http_request_listener_destroyed,req);
req->listener=l;
}
}
belle_http_request_listener_t * belle_http_request_get_listener(const belle_http_request_t *req){
......
......@@ -32,6 +32,7 @@ struct belle_http_channel_context{
};
struct belle_http_provider{
belle_sip_object_t base;
belle_sip_stack_t *stack;
char *bind_ip;
int ai_family;
......@@ -141,6 +142,7 @@ BELLE_SIP_INSTANCIATE_VPTR(belle_http_channel_context_t,belle_sip_object_t,belle
static void http_provider_uninit(belle_http_provider_t *obj){
belle_sip_message("http provider destroyed.");
belle_sip_free(obj->bind_ip);
belle_sip_list_for_each(obj->tcp_channels,(void (*)(void*))belle_sip_channel_force_close);
belle_sip_list_free_with_data(obj->tcp_channels,belle_sip_object_unref);
belle_sip_list_for_each(obj->tls_channels,(void (*)(void*))belle_sip_channel_force_close);
......@@ -186,6 +188,7 @@ static belle_sip_list_t **provider_get_channels(belle_http_provider_t *obj, cons
static void provider_remove_channel(belle_http_provider_t *obj, belle_sip_channel_t *chan){
belle_sip_list_t **channels=provider_get_channels(obj,belle_sip_channel_get_transport_name(chan));
*channels=belle_sip_list_remove(*channels,chan);
belle_sip_message("channel [%p] removed from http provider.",obj);
belle_sip_object_unref(chan);
}
......
......@@ -27,6 +27,16 @@ typedef struct http_counters{
int io_error_count;
}http_counters_t;
static int wait_for(belle_sip_stack_t*s1,int* counter,int value,int timeout) {
int retry=0;
#define SLEEP_TIME 100
while (*counter!=value && retry++ <(timeout/SLEEP_TIME)) {
if (s1) belle_sip_stack_sleep(s1,SLEEP_TIME);
}
if (*counter!=value) return FALSE;
else return TRUE;
}
static void process_response(void *data, const belle_http_response_event_t *event){
http_counters_t *counters=(http_counters_t*)data;
counters->response_count++;
......@@ -58,7 +68,7 @@ static void one_get(void){
cbs.process_io_error=process_io_error;
l=belle_http_request_listener_create_from_callbacks(&cbs,&counters);
belle_http_provider_send_request(prov,req,l);
belle_sip_stack_sleep(stack,5000);
wait_for(stack,&counters.response_count,1,3000);
CU_ASSERT_TRUE(counters.response_count==1);
CU_ASSERT_TRUE(counters.io_error_count==0);
......
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