Commit b29b6335 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Use specific background task for HTTP transfers, otherwise the channel might...

Use specific background task for HTTP transfers, otherwise the channel might hang when an iOS app goes into background
parent 9976fc40
......@@ -613,6 +613,7 @@ struct belle_http_request{
belle_generic_uri_t *orig_uri;/*original uri before removing host and user/passwd*/
belle_http_response_t *response;
int auth_attempt_count;
int background_task_id;
};
void belle_http_request_set_listener(belle_http_request_t *req, belle_http_request_listener_t *l);
......
......@@ -169,6 +169,11 @@ static void http_channel_context_handle_response(belle_http_channel_context_t *c
ev.request=req;
ev.response=response;
BELLE_HTTP_REQUEST_INVOKE_LISTENER(req,process_response,&ev);
if( req->background_task_id ){
belle_sip_warning("HTTP request finished: ending bg task id=[%x]", req->background_task_id);
belle_sip_end_background_task(req->background_task_id);
req->background_task_id = 0;
}
}
belle_sip_object_unref(req);
}
......@@ -191,6 +196,11 @@ static void http_channel_context_handle_io_error(belle_http_channel_context_t *c
ev.port=chan->peer_port;
ev.transport=belle_sip_channel_get_transport_name(chan);
BELLE_HTTP_REQUEST_INVOKE_LISTENER(req,process_io_error,&ev);
if( req->background_task_id ){
belle_sip_warning("IO Error on HTTP request: ending bg task id=[%x]", req->background_task_id);
belle_sip_end_background_task(req->background_task_id);
req->background_task_id = 0;
}
}
}
......@@ -355,6 +365,15 @@ static void provider_remove_channel(belle_http_provider_t *obj, belle_sip_channe
belle_sip_object_unref(chan);
}
static void belle_http_end_background_task(void* data) {
belle_http_request_t *req = BELLE_HTTP_REQUEST(data);
belle_sip_warning("Ending unfinished HTTP transfer background task id=[%x]", req->background_task_id);
if( req->background_task_id ){
belle_sip_end_background_task(req->background_task_id);
req->background_task_id = 0;
}
}
int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_request_t *req, belle_http_request_listener_t *listener){
belle_sip_channel_t *chan;
belle_sip_hop_t *hop=belle_sip_hop_new_from_generic_uri(req->orig_uri ? req->orig_uri : req->req_uri);
......@@ -384,6 +403,11 @@ int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_requ
belle_sip_object_unref(hop);
split_request_url(req);
fix_request(req);
if( req->background_task_id != 0){
req->background_task_id = belle_sip_begin_background_task("http", belle_http_end_background_task, req);
}
belle_sip_channel_queue_message(chan,BELLE_SIP_MESSAGE(req));
return 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