Chops Net IP
Loading...
Searching...
No Matches
tcp_connector_timeout.hpp File Reference

Classes that implement a connect timeout function object interface for the tcp_connector detail class. More...

#include <cstddef>
#include <cmath>
#include <chrono>
#include <optional>
#include <functional>
Include dependency graph for tcp_connector_timeout.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  chops::net::simple_timeout
 
struct  chops::net::counted_timeout
 
struct  chops::net::backoff_timeout
 
struct  chops::net::exponential_backoff_timeout
 

Typedefs

using chops::net::optional_millis = std::optional<std::chrono::milliseconds>
 
using chops::net::tcp_connector_timeout_func = std::function< optional_millis (std::size_t) >
 

Detailed Description

Classes that implement a connect timeout function object interface for the tcp_connector detail class.

Author
Nathan Deutsch

All classes implement a functor with the following interface:

std::optional<std::chrono::milliseconds> operator()(std::size_t connect_attempts);

The return value is the number of milliseconds for the TCP connector timeout, if present. If the value is not present, no further TCP connects are attempted.

The connect_attempts parameter is the number of connect attempts made by the TCP connector. It will always be greater than zero.

The following use cases are supported: 1) always return the same timeout (i.e. no scale factor, no backoff); 2) scale the timeout by a multiplier or exponential factor for each connect attempt, cap the timeout at a max timeout value; 3) stop after N connect attempts.

Other use cases can be implemented by applications providing a function object or lambda in the make_tcp_connector method call.

The TCP connector uses a copy of the initial timeout function object when connection attempts are started. In other words, if a TCP connection is brought down due to a network error and the "re-connect on error" flag is set true in the make_tcp_connector call, then the timeout function object will start in the initial state (as supplied). This may make a difference for function objects that need to modify state. None of the functor classes in this header modify state.

Copyright (c) 2019 by Cliff Green, Nathan Deutsch

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)