Re: how to capture http response number?
Date: Tue, 17 May 2016 15:02:30 -0400
On 5/17/2016 10:11 AM, Kman Devnull wrote:
> Now, I see that if the server was slow to respond to a http-post, it
> appears that my whole code seems to wait on the call-back function
> My embedded system, speaks to various sensors - now because of the
> above delay, it affects the real-time processing/receiving of the
> sensor data. How would you propose for me to proceed?
> Is there a way I could make the receiving of server-response
> -parallel-(as in another thread etc.) to sending of the http_post?
Please don't top post it makes the conversation harder to follow. I've
omitted the rest of the conversation but I'll sum it up that you are
looking to get the server response status code to a POST.
You can't use the same handle from more than one thread , so you
wouldn't be able to perform a POST from one thread and then wait for the
server to reply from another. I suggest in your main thread you write to
a queue the data to be handled asynchronously in a worker thread using
libcurl. If you need to evaluate the status code in the main thread
before continuing you'll have to wait and there's very little libcurl
can do about that except wait.
Exception: It is possible (but not recommended) to terminate the
connection immediately after receiving the status code. This is bad
because usually you'd want to leave the connection open so you can keep
sending data. I would only suggest this if you are in a rare
circumstance where the server sends the status code immediately, but for
whatever reason does not send headers or body without some delay. In
that specific case you could try returning error as soon as the header
callback is called and then call CURLINFO_RESPONSE_CODE  to get the
code. If you allow location based redirects you'd have to account for
that in the header callback (ie don't terminate in that case). And if
you are using a proxy tunnel it's much harder because proxy tunnel
returns its own response code which IIRC is temporarily stored as the
http response code until a server response code is actually received.
See other tricks that may help at .
List admin: https://cool.haxx.se/list/listinfo/curl-library
Received on 2016-05-17