o se llama a la devolución de llamada de escritura de @libcurl para enviar un mensaje http

Introducción

Estoy enviando una solicitud POST al servidor que responde con mensajes fragmentados. Así que estoy tratando de hacer que se llame a writecallback en cada mensaje http fragmentado recibido.

Códig
#include <iostream>
#include <string>
#include <curl/curl.h>

using namespace std;

size_t write_callback(char *d, size_t n, size_t l, void *userp)
{
    cerr << ""--- Called once" << endl;
    return n*l;
}

string xml_msg()
{
    return "<<some request data>>";
}

curl_slist* get_header(size_t content_length)
{
    auto list = curl_slist_append(nullptr, "<<protocol version>>");
    list = curl_slist_append(list, "Content-Type: text/xml");
    list = curl_slist_append(list, "Content-Length: " + content_length);
    return list;
}

void main()
{
    auto xml = xml_msg();

    curl_global_init(CURL_GLOBAL_ALL);

    auto curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, "<<server url>>");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0)");
    curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_easy_setopt(curl, CURLOPT_USERPWD, "<<user credentials>>");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, get_header(xml.size()));
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, xml.data());
    curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 0L);

    curl_easy_perform(curl);

    curl_easy_cleanup(curl);
    curl_global_cleanup();
}
Verbose log
* STATE: INIT => CONNECT handle 0x15c4de0; line 1422 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x15c4de0; line 1458 (connection #0)
*   Trying xxx.xxx.xxx.xxx...
* TCP_NODELAY set
* STATE: WAITRESOLVE => WAITCONNECT handle 0x15c4de0; line 1539 (connection #0)
* Connected to <<host>> (xxx.xxx.xxx.xxx) port 80 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x15c4de0; line 1591 (connection #0)
* Marked for [keep alive]: HTTP default
* STATE: SENDPROTOCONNECT => PROTOCONNECT handle 0x15c4de0; line 1605 (connection #0)
* STATE: PROTOCONNECT => DO handle 0x15c4de0; line 1626 (connection #0)
* Server auth using Basic with user '<<credentials>>'
> POST <<URL>>
Host: <<host>>
Authorization: Basic <<base64 credentials>>
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0)
Accept: */*
Content-Type: text/xml
Content-Length: 204

* upload completely sent off: 204 out of 204 bytes
* STATE: DO => DO_DONE handle 0x15c4de0; line 1688 (connection #0)
* STATE: DO_DONE => WAITPERFORM handle 0x15c4de0; line 1813 (connection #0)
* STATE: WAITPERFORM => PERFORM handle 0x15c4de0; line 1823 (connection #0)
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
< Date: Tue, 08 May 2018 12:29:49 GMT
* Server is not blacklisted
< Server: <<server>>
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Content-Language: en-US
< Cache-Control: no-cache, no-store
< Pragma: no-cache
< Content-Type: application/xml;charset=UTF-8
< Set-Cookie: <<cookie>>
< Transfer-Encoding: chunked
<
--- Called once
* STATE: PERFORM => DONE handle 0x15c4de0; line 1992 (connection #0)
* multi_done
* Connection #0 to <<server>> left intact
Problem

e ha llamado a @Writecallback cuando el servidor ha cerrado la conexión debido al tiempo de espera con el paquete FIN tcp en lugar del momento en que se ha recibido la respuesta http fragmentada.

Es un intervalo de aproximadamente 30 segundos entre estos eventos.

Pregunt

¿Qué estoy haciendo mal

Update 1

Server devuelve un segmento tcp con indicador PUSH y mensaje http con codificación de transferencia fragmentada que contiene XML. El mensaje termina con CLRF. Mientras tanto, el socket Win API no permite leerlo y select () devuelve 0, lo que significa que no hay nada que leer / escribir en este socket.

Después de 30 segundos de retraso antes de cerrar la conexión debido al tiempo de espera de los latidos (es decir, la implementación interna del servidor), el servidor envía un mensaje HTTP final con codificación de transferencia fragmentada, que contiene 0 y CLRF. Después de ese mensaje, select () muestra un nuevo estado de socket y las llamadas de libcurl escriben devolución de llamada con el contenido del mensaje fragmentad

Eso es lo que veo después de depurar libcurl. Necesito encontrar la manera de que libcurl devuelva el mensaje http fragmentado una vez que se recibe, no después de recibir el mensaje http final.

Respuestas a la pregunta(1)

Su respuesta a la pregunta