...
This commit is contained in:
@@ -16,6 +16,17 @@ ABSTRACT DEVICE COMPONENTS LIBRARY
|
||||
namespace adc
|
||||
{
|
||||
|
||||
namespace traits
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
// from https://stackoverflow.com/questions/74383254/concept-that-models-only-the-stdchrono-duration-types
|
||||
concept adc_time_duration_c = requires {
|
||||
[]<class Rep, class Period>(std::type_identity<std::chrono::duration<Rep, Period>>) {}(std::type_identity<T>());
|
||||
};
|
||||
|
||||
} // namespace traits
|
||||
|
||||
|
||||
template <typename ImplT>
|
||||
class AdcNetService
|
||||
@@ -28,13 +39,7 @@ public:
|
||||
|
||||
using typename ImplT::endpoint_t;
|
||||
|
||||
using timeout_clock_t = std::chrono::steady_clock;
|
||||
using timeout_drtn_t = timeout_clock_t::duration;
|
||||
|
||||
static constexpr timeout_drtn_t defaultConnectTimeout = std::chrono::seconds(5);
|
||||
// static constexpr std::chrono::duration defaultConnectTimeout = std::chrono::seconds(5);
|
||||
static constexpr timeout_drtn_t defaultSendTimeout = std::chrono::seconds(5);
|
||||
static constexpr timeout_drtn_t defaultRecvTimeout = std::chrono::seconds(5);
|
||||
using typename ImplT::timeout_t;
|
||||
|
||||
template <typename... ImplCtorArgTs>
|
||||
AdcNetService(ImplCtorArgTs&&... ctor_args) : _impl(std::forward<ImplCtorArgTs>(ctor_args)...)
|
||||
@@ -49,22 +54,20 @@ public:
|
||||
|
||||
// open connection
|
||||
template <typename... ArgTs>
|
||||
auto asyncConnect(const endpoint_t& end_point,
|
||||
const timeout_drtn_t& timeout = defaultConnectTimeout,
|
||||
ArgTs&&... args)
|
||||
auto asyncConnect(const endpoint_t& end_point, const timeout_t& timeout, ArgTs&&... args)
|
||||
{
|
||||
return _impl.asyncConnect(end_point, timeout, std::forward<ArgTs>(args)...);
|
||||
}
|
||||
|
||||
|
||||
template <traits::adc_netmessage_c NetMessageT, typename... ArgTs>
|
||||
auto asyncSend(const NetMessageT& msg, const timeout_drtn_t& timeout = defaultSendTimeout, ArgTs&&... args)
|
||||
auto asyncSend(const NetMessageT& msg, const timeout_t& timeout, ArgTs&&... args)
|
||||
{
|
||||
return _impl.asyncSend(msg, timeout, std::forward<ArgTs>(args)...);
|
||||
}
|
||||
|
||||
template <traits::adc_netmessage_c NetMessageT, typename... ArgTs>
|
||||
auto asyncReceive(const timeout_drtn_t& timeout = defaultRecvTimeout, ArgTs&&... args)
|
||||
auto asyncReceive(const timeout_t& timeout, ArgTs&&... args)
|
||||
{
|
||||
return _impl.asyncReceive(timeout, std::forward<ArgTs>(args)...);
|
||||
}
|
||||
@@ -74,20 +77,20 @@ public:
|
||||
/* blocking operations */
|
||||
|
||||
template <typename... ArgTs>
|
||||
auto connect(const endpoint_t& endpoint, const timeout_drtn_t& timeout = defaultConnectTimeout, ArgTs&&... args)
|
||||
auto connect(const endpoint_t& endpoint, const timeout_t& timeout, ArgTs&&... args)
|
||||
{
|
||||
return _impl.connect(endpoint, timeout, std::forward<ArgTs>(args)...);
|
||||
}
|
||||
|
||||
template <traits::adc_netmessage_c NetMessageT, typename... ArgTs>
|
||||
auto send(const NetMessageT& msg, const timeout_drtn_t& timeout = defaultSendTimeout, ArgTs&&... args)
|
||||
auto send(const NetMessageT& msg, const timeout_t& timeout, ArgTs&&... args)
|
||||
{
|
||||
return _impl.send(msg, timeout, std::forward<ArgTs>(args)...);
|
||||
}
|
||||
|
||||
|
||||
template <traits::adc_netmessage_c NetMessageT, typename... ArgTs>
|
||||
NetMessageT receive(const timeout_drtn_t& timeout = defaultRecvTimeout, ArgTs&&... args)
|
||||
NetMessageT receive(const timeout_t& timeout, ArgTs&&... args)
|
||||
{
|
||||
return _impl.receive(timeout, std::forward<ArgTs>(args)...);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user