curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Reuse connection in half-closed state

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sat, 1 Apr 2017 00:34:27 +0200 (CEST)

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
https://curl.haxx.se/libcurl/c/http2-download.html.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2017-04-01