...
This commit is contained in:
parent
8b2e8fcaaa
commit
986758430e
@ -37,9 +37,8 @@ public:
|
|||||||
virtual ~AdcNetServiceASIOStream() = default;
|
virtual ~AdcNetServiceASIOStream() = default;
|
||||||
|
|
||||||
|
|
||||||
template <typename TimeoutT, typename CompletionTokenT>
|
template <typename TimeoutT, asio::completion_token_for<void(std::error_code)> CompletionTokenT>
|
||||||
auto asynSend(const NetMessageT& msg, const TimeoutT& timeout, CompletionTokenT&& token)
|
auto asynSend(const NetMessageT& msg, const TimeoutT& timeout, CompletionTokenT&& token)
|
||||||
requires std::derived_from<socket_t, asio::basic_stream_socket<typename socket_t::protocol_type>>
|
|
||||||
{
|
{
|
||||||
using namespace asio::experimental::awaitable_operators;
|
using namespace asio::experimental::awaitable_operators;
|
||||||
|
|
||||||
@ -47,32 +46,41 @@ public:
|
|||||||
|
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
|
|
||||||
co_await (asio::async_write(_socket, msg.bytes(), asio::use_awaitable) && watchdog(deadline, ec));
|
co_await (asyncSendImpl(msg) && watchdog(deadline, ec));
|
||||||
|
|
||||||
std::forward<CompletionTokenT>(token)(ec);
|
std::forward<CompletionTokenT>(token)(ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename CompletionTokenT>
|
template <typename TimeoutT, typename CompletionTokenT>
|
||||||
auto asynSend(const NetMessageT& msg, CompletionTokenT&& token)
|
auto asyncReceive(const TimeoutT& timeout, CompletionTokenT&& token)
|
||||||
requires std::derived_from<socket_t, asio::basic_datagram_socket<typename socket_t::protocol_type>>
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename CompletionTokenT>
|
|
||||||
auto asynSend(const NetMessageT& msg, CompletionTokenT&& token)
|
|
||||||
requires std::derived_from<socket_t, asio::basic_seq_packet_socket<typename socket_t::protocol_type>>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
socket_t& _socket;
|
socket_t& _socket;
|
||||||
|
|
||||||
asio::streambuf _streamBuffer;
|
asio::streambuf _streamBuffer;
|
||||||
|
|
||||||
|
asio::awaitable<void> asyncSendImpl(const NetMessageT& msg)
|
||||||
|
{
|
||||||
|
// for (const auto& buff : msg.bytesView()) {
|
||||||
|
if constexpr (std::derived_from<socket_t, asio::basic_stream_socket<typename socket_t::protocol_type>>) {
|
||||||
|
// asio::async_write(_socket, buff, asio::use_awaitable);
|
||||||
|
co_await asio::async_write(_socket, msg.bytesView(), asio::use_awaitable);
|
||||||
|
} else if constexpr (std::derived_from<socket_t,
|
||||||
|
asio::basic_datagram_socket<typename socket_t::protocol_type>>) {
|
||||||
|
co_await _socket.async_send(msg.bytesView(), asio::use_awaitable);
|
||||||
|
} else if constexpr (std::derived_from<socket_t,
|
||||||
|
asio::basic_seq_packet_socket<typename socket_t::protocol_type>>) {
|
||||||
|
co_await _socket.async_send(msg.bytesView(), asio::use_awaitable);
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNKNOWN ASIO-LIBRARY SOCKET TYPE!!!");
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
template <typename TimepointT>
|
template <typename TimepointT>
|
||||||
asio::awaitable<void> watchdog(TimepointT& deadline, std::error_code& ec)
|
asio::awaitable<void> watchdog(TimepointT& deadline, std::error_code& ec)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user