C Collections

chttpclient · Section 3

chttpcli_set_connect_timeout

chttpcli_set_connect_timeout - set the TCP connect timeout

C Collections (libccollections, -lccollections)

#include <ccollections/chttpclient.h>
 
ccol_retval chttpcli_set_connect_timeout(chttpcli cli, uint64_t us);
 
#define CHTTPCLI_DEFAULT_CONNECT_TIMEOUT_US ((uint64_t)30000000)

This function sets the maximum time that the TCP connect phase may
take, and for HTTPS that phase includes the TLS handshake. 0 turns the
timeout off. The default is CHTTPCLI_DEFAULT_CONNECT_TIMEOUT_US, 30 s.
Any other value 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.
 
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.

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_request_timeout(3), chttpcli_set_inactivity_timeout(3)