C Collections

chttpclient · Section 3

chttpcli_set_request_timeout

chttpcli_set_request_timeout - set the total request timeout

C Collections (libccollections, -lccollections)

#include <ccollections/chttpclient.h>
 
ccol_retval chttpcli_set_request_timeout(chttpcli cli, uint64_t us);

This function sets the maximum time from the call to chttpcli_do
until the last byte of the response body arrives. 0 turns the timeout
off.
 
chttpcli_do returns ccol_timed_out when a request takes longer than
that.
 
Every tier checks the deadline before each read of the response. Once
the deadline has passed, the request ends with ccol_timed_out, even if
the rest of the response is already there and one more read would
finish it. A response that the client finished reading before the
deadline is a success. chttpcli_do, chttpcli_do_async,
chttpcli_do_pooled and their streaming forms all give the same
result for the same timeline.
 
A name lookup is a single blocking getaddrinfo() call, and the system
gives no way to cancel it. chttpcli_do makes that call on the
calling thread, so when the lookup alone takes longer than this
timeout, the call skips the connect and returns ccol_timed_out as soon
as the lookup returns. chttpcli_do_async and chttpcli_do_pooled
return ccol_timed_out at the deadline itself, and the lookup goes on in
the background with its result thrown away. A request to an address
literal or to a unix socket makes no lookup at all.
 
For chttpcli_do_async and chttpcli_do_pooled, an engine thread
watches the deadlines and wakes at the earliest deadline among the
requests in flight, so a request ends within a few milliseconds of its
deadline however short the timeout is.
 
That deadline holds even when the engine cannot run the request's work,
for example while its allocator fails. The request then ends with
ccol_timed_out at most about 100 ms after the deadline, and its
connection is closed in the background once the engine can run it
again. Until that happens, chttpcli_destroy of the client waits for
it.
 
Any value other than 0 is honoured as a limit however far away it is:
a value too large for the clock to reach, such as UINT64_MAX,
saturates to the latest deadline the clock can hold and never wraps
into the past.

cli   The client handle. It must not be CHTTPCLI_NULL.
us    The timeout in microseconds. 0 means no timeout.

ccol_success      The client has the new timeout.
ccol_invalid_args cli is CHTTPCLI_NULL, or a stale handle of a
                  client that has been destroyed.

chttpcli_set_connect_timeout(3), chttpcli_set_inactivity_timeout(3), chttpcli_set_max_response_body_size(3), chttpcli_do(3)