Xclox
C++11 header-only cross-platform date and time library with an asynchronous NTP client
xclox::ntp::Query Class Reference

Query is an ephemeral class representing a NTP query from start to end. More...

#include <query.hpp>

Inheritance diagram for xclox::ntp::Query:
Collaboration diagram for xclox::ntp::Query:

Public Types

Enumerations & Aliases
enum class  Status : uint8_t {
  ResolveError = 1 , SendError = 2 , ReceiveError = 4 , TimeoutError = 8 ,
  Cancelled = 16 , Succeeded = 32
}
 Type of query status. More...
 
using Callback = std::function< void(const std::string &, const std::string &, Status, const Packet &, const std::chrono::steady_clock::duration &)>
 Type of query callback.
 
using DefaultTimeout = internal::DefaultTimeout< QuerySingle, 5000 >
 Type of query timeout milliseconds holder.
 

Public Member Functions

 Query (const std::string &server, Callback callback)
 Constructs a NTP query that targets server and uses callback for reporting back its result.
 
void cancel ()
 Cancels the query reporting Query::Status::Cancelled to the caller.
 

Static Public Member Functions

static std::weak_ptr< Querystart (asio::thread_pool &pool, const std::string &server, Callback callback, const std::chrono::milliseconds &timeout=std::chrono::milliseconds(DefaultTimeout::ms))
 Starts querying all resolved addresses of server one at a time until success. More...
 

Detailed Description

Query is an ephemeral class representing a NTP query from start to end.

See also
The unit tests in query.h for further details.

Member Enumeration Documentation

◆ Status

enum xclox::ntp::Query::Status : uint8_t
strong

Type of query status.

Enumerator
ResolveError 

The server domain name is not resolved.

SendError 

The client packet is not sent to the server.

ReceiveError 

The server packet is not received by the client.

TimeoutError 

The query timed out while waiting for the server's packet.

Cancelled 

The client cancelled the query.

Succeeded 

The client received the server's packet successfully.

Member Function Documentation

◆ start()

static std::weak_ptr<Query> xclox::ntp::Query::start ( asio::thread_pool &  pool,
const std::string &  server,
Callback  callback,
const std::chrono::milliseconds &  timeout = std::chrono::milliseconds(DefaultTimeout::ms) 
)
inlinestatic

Starts querying all resolved addresses of server one at a time until success.

Parameters
poola thread pool on which the operations of the query are executed.
servera server domain name or address to be resolved for querying.
callbacka callable to report the result of the query to the caller.
timeouta time duration after which the query is cancelled if it is not completed.
Returns
a weak reference to the query that helps in tracing it.

The documentation for this class was generated from the following file: