curl / Mailing Lists / curl-library / Single Mail


Re: Reuse connection in half-closed state

From: Reese Grimsley <>
Date: Mon, 3 Apr 2017 14:59:29 -0500

Yes, when I call curl_easy_perform, it sits and waits for more to come.
After the connection times out, it goes ahead and attempts to call a POST

The GET request is supposed to open a connection that should time out after
60 minutes or more, but is only there to wait for directives. According to
documentation, this connection is to stay open server side and half closed
client side for the life of the connection, and it is mentioned that there
may be long periods of time where no directives are sent at all.

It looks like I will need to try to use the multi interface. So just to
check if I am understanding this correctly, I could have a number of easy
handles under a single multi handle, and use these separate but related (by
multi) easy handles to send different requests asynchronously on the same
connection? The documentation specifies using the existing connection for
sending the GET message to also send a POST message shortly after, as well
as pinging the servers on a 5 minute interval. Thanks for the help.

On Fri, Mar 31, 2017 at 5:34 PM, Daniel Stenberg <> wrote:

> On Fri, 31 Mar 2017, Reese Grimsley wrote:
> I am using a GET request from C to establish a downchannel stream (for
>> Amazon Alexa), and I need to establish a stream to a different path at the
>> same base url on the existing connection. When I run my function to be
>> used for sending the GET request, VERBOSE returns 200, and the terminal is
>> idle, not proceeding further.
> I assume you mean that your curl_easy_perform() (or similar) doesn't
> return at this point but sits waiting for something more to come?
> If that's the case, it is because the HTTP response hasn't signalled the
> end of the response or it hasn't sent enough data to the client yet.
> You can opt to use the multi interface to easier be able to do multiple
> things while waiting for a response, or perhaps wait for other
> communications etc.
> If I wait long enough, I assume it times out, as it says unexpected EOF,
>> closing connection 0 and returns error code 56 (failure to receive data).
> So the server never sends a response to the GET? Error 56 means it sent
> *nothing*, not even a single header, which usually implies something is
> totally broken or you connected to something that isn't a HTTP server.
> I was expecting the program to return from that function and call the next,
>> which is supposed to send a POST request, but it never seems to make it
>> that far.
> It would, as soon as the transfer ended. Which in your case seemed to have
> taken a while and resulted in error code 56. But then it certainly
> continued and you could call the POST operation?
> Can I use the same CURL easy handle for both the GET and POST requests?
> Yes, it is even encouraged to reuse handles as much as you can for
> performance reasons.
> Should I maybe be using separate threads for doing these things, use the
>> multi api rather than easy, or a combination?
> You can do any of that. But if the server doesn't respond to the GET, it
> doesn't matter if you fire up other things in parallel. Get GET will still
> not finish until it times out.
> The connection established by the GET request seems to be there for the
>> purpose of waiting for directives from Amazon (half-closed client side,
>> open server side, documentation mentions there can be long pauses between
>> directives). My question is how to reuse this same initial connection for
>> a different stream, whether this means using a multi handle or using more
>> than one easy handle.
> "Streams" implies HTTP/2, right? Then you should use the multi interface
> and setup two (or more) transfers. An example that shows how to do that is
> --
> /
> -------------------------------------------------------------------
> Unsubscribe:
> Etiquette:

Received on 2017-04-03