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

QuerySingle is an ephemeral class representing a single NTP query. More...

#include <query_single.hpp>

Public Types

Aliases
using Callback = std::function< void(const asio::ip::udp::endpoint &, const asio::error_code &, const Packet &, const std::chrono::steady_clock::duration &)>
 Type of query callback.
 
using DefaultTimeout = internal::DefaultTimeout< QuerySingle, 3000 >
 Type of query timeout milliseconds holder.
 

Public Member Functions

 QuerySingle (asio::io_context &io, const std::chrono::milliseconds &timeout)
 Constructs a single NTP query on the given context that runs within the given timeout duration.
 
void cancel ()
 Cancels the query reporting asio::error::operation_aborted to the caller.
 

Static Public Member Functions

static std::weak_ptr< QuerySinglestart (asio::io_context &io, const asio::ip::udp::endpoint &server, Callback callback, const std::chrono::milliseconds &timeout=std::chrono::milliseconds(DefaultTimeout::ms))
 Starts querying the given endpoint. More...
 

Detailed Description

QuerySingle is an ephemeral class representing a single NTP query.

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

Member Function Documentation

◆ start()

static std::weak_ptr<QuerySingle> xclox::ntp::QuerySingle::start ( asio::io_context &  io,
const asio::ip::udp::endpoint &  server,
Callback  callback,
const std::chrono::milliseconds &  timeout = std::chrono::milliseconds(DefaultTimeout::ms) 
)
inlinestatic

Starts querying the given endpoint.

Parameters
ioa run context on which the operations of the query are executed.
servera server address to be queried.
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: