diff --git a/src/http_client.cpp b/src/http_client.cpp index a1bea098..28fdf0c8 100644 --- a/src/http_client.cpp +++ b/src/http_client.cpp @@ -275,12 +275,14 @@ size_t HttpClient::curl_write_async(char *buffer, size_t size, size_t nmemb, voi //LOG(INFO) << "curl_write_async response, res body size: " << req_res->res->body.size(); + // wait for previous chunk to finish (if any) + //LOG(INFO) << "Waiting on req_res " << req_res->res; + req_res->res->wait(); + async_req_res_t* async_req_res = new async_req_res_t(req_res->req, req_res->res, true); req_res->server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, async_req_res); // wait until response is sent - //LOG(INFO) << "Waiting on req_res " << req_res->res; - req_res->res->wait(); //LOG(INFO) << "Response sent"; return res_size; @@ -300,12 +302,13 @@ size_t HttpClient::curl_write_async_done(void *context, curl_socket_t item) { req_res->res->body = ""; req_res->res->final = true; + // wait until final response is flushed or response object will be destroyed by caller + //LOG(INFO) << "Waiting on req_res " << req_res->res; + req_res->res->wait(); + async_req_res_t* async_req_res = new async_req_res_t(req_res->req, req_res->res, true); req_res->server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, async_req_res); - // wait until final response is flushed or response object will be destroyed by caller - req_res->res->wait(); - // Close the socket as we've overridden the close socket handler! close(item);