...
This commit is contained in:
@@ -183,7 +183,9 @@ public:
|
||||
|
||||
auto timer = netservice_t::getDeadlineTimer(_acceptor, timeout);
|
||||
|
||||
auto srv = std::make_unique<netservice_t>(_ioContext);
|
||||
// auto srv = std::make_unique<netservice_t>(_ioContext);
|
||||
auto srv = netservice_t::isTLS ? std::make_unique<netservice_t>(_ioContext, srv->_tlsContext)
|
||||
: std::make_unique<netservice_t>(_ioContext);
|
||||
|
||||
return asio::async_compose<TokenT, void(std::error_code, netservice_t)>(
|
||||
[timer = std::move(timer), srv = std::move(srv), state = sock_accept, this](
|
||||
@@ -254,6 +256,11 @@ public:
|
||||
return accept(timeout);
|
||||
}
|
||||
|
||||
void close(std::error_code& ec)
|
||||
{
|
||||
_acceptor.close(ec);
|
||||
}
|
||||
|
||||
private:
|
||||
asio::io_context& _ioContext;
|
||||
srv_acceptor_t _acceptor;
|
||||
@@ -273,14 +280,14 @@ public:
|
||||
}
|
||||
|
||||
|
||||
AdcBaseNetServiceASIO(socket_t socket)
|
||||
: SESSION_PROTOT(),
|
||||
_ioContext(static_cast<asio::io_context&>(socket.get_executor().context())),
|
||||
_socket(std::move(socket)),
|
||||
_receiveStrand(_ioContext),
|
||||
_receiveQueue()
|
||||
{
|
||||
}
|
||||
// AdcBaseNetServiceASIO(socket_t socket)
|
||||
// : SESSION_PROTOT(),
|
||||
// _ioContext(static_cast<asio::io_context&>(socket.get_executor().context())),
|
||||
// _socket(std::move(socket)),
|
||||
// _receiveStrand(_ioContext),
|
||||
// _receiveQueue()
|
||||
// {
|
||||
// }
|
||||
|
||||
#ifdef USE_OPENSSL_WITH_ASIO
|
||||
AdcBaseNetServiceASIO(asio::io_context& ctx,
|
||||
@@ -300,6 +307,7 @@ public:
|
||||
|
||||
|
||||
AdcBaseNetServiceASIO(AdcBaseNetServiceASIO&& other)
|
||||
requires(!isTLS)
|
||||
: _ioContext(other._ioContext),
|
||||
_receiveStrand(std::move(other._receiveStrand)),
|
||||
_socket(std::move(other._socket)),
|
||||
@@ -312,6 +320,23 @@ public:
|
||||
_streamBuffer.commit(bytes);
|
||||
}
|
||||
|
||||
#ifdef USE_OPENSSL_WITH_ASIO
|
||||
AdcBaseNetServiceASIO(AdcBaseNetServiceASIO&& other)
|
||||
requires isTLS
|
||||
: _ioContext(other._ioContext),
|
||||
_receiveStrand(std::move(other._receiveStrand)),
|
||||
_socket(std::move(other._socket)),
|
||||
_sessSocket(std::move(other._sessSocket)),
|
||||
_streamBuffer(),
|
||||
_receiveQueue(std::move(other._receiveQueue)),
|
||||
_tlsContext(std::move(other._tlsContext)),
|
||||
_tlsPeerVerifyMode(std::move(other._tlsPeerVerifyMode))
|
||||
|
||||
{
|
||||
auto bytes = asio::buffer_copy(_streamBuffer.prepare(other._streamBuffer.size()), other._streamBuffer.data());
|
||||
_streamBuffer.commit(bytes);
|
||||
}
|
||||
#endif
|
||||
|
||||
AdcBaseNetServiceASIO(const AdcBaseNetServiceASIO&) = delete; // no copy constructor!
|
||||
|
||||
@@ -321,6 +346,7 @@ public:
|
||||
AdcBaseNetServiceASIO& operator=(const AdcBaseNetServiceASIO&) = delete;
|
||||
|
||||
AdcBaseNetServiceASIO& operator=(AdcBaseNetServiceASIO&& other)
|
||||
requires(!isTLS)
|
||||
{
|
||||
_ioContext = other._ioContext;
|
||||
_receiveStrand = std::move(other._receiveStrand);
|
||||
@@ -335,7 +361,29 @@ public:
|
||||
return *this;
|
||||
};
|
||||
|
||||
#ifdef USE_OPENSSL_WITH_ASIO
|
||||
AdcBaseNetServiceASIO& operator=(AdcBaseNetServiceASIO&& other)
|
||||
requires isTLS
|
||||
{
|
||||
_ioContext = other._ioContext;
|
||||
_receiveStrand = std::move(other._receiveStrand);
|
||||
_receiveQueue = std::move(other._receiveQueue);
|
||||
_socket = std::move(other._socket);
|
||||
|
||||
_sessSocket = std::move(other._sessSocket);
|
||||
_tlsContext = std::move(other._tlsContext);
|
||||
_tlsPeerVerifyMode = std::move(other._tlsPeerVerifyMode);
|
||||
|
||||
|
||||
_streamBuffer.consume(_streamBuffer.size());
|
||||
|
||||
auto bytes = asio::buffer_copy(_streamBuffer.prepare(other._streamBuffer.size()), other._streamBuffer.data());
|
||||
_streamBuffer.commit(bytes);
|
||||
|
||||
return *this;
|
||||
};
|
||||
|
||||
#endif
|
||||
constexpr netservice_ident_t ident() const
|
||||
{
|
||||
return _ident;
|
||||
@@ -424,7 +472,7 @@ public:
|
||||
return _socket.async_send(buff_seq, std::move(self));
|
||||
} else if constexpr (std::derived_from<socket_t, asio::basic_seq_packet_socket<
|
||||
typename socket_t::protocol_type>>) {
|
||||
return _socket.async_send(buff_seq, std::move(self));
|
||||
return _socket.async_send(buff_seq, 0, std::move(self));
|
||||
} else {
|
||||
static_assert(false, "UNKNOWN ASIO-LIBRARY SOCKET TYPE!!!");
|
||||
}
|
||||
@@ -772,8 +820,12 @@ protected:
|
||||
std::chrono::steady_clock::time_point::max() - std::chrono::steady_clock::now() -
|
||||
std::chrono::seconds(1));
|
||||
|
||||
timer->expires_after(timeout < max_d ? timeout : max_d); // to avoid overflow!
|
||||
// timer->expires_after(timeout);
|
||||
if (timeout < max_d) {
|
||||
timer->expires_after(timeout);
|
||||
} else {
|
||||
timer->expires_after(max_d); // to avoid overflow!
|
||||
}
|
||||
|
||||
|
||||
timer->async_wait([&obj](const std::error_code& ec) mutable {
|
||||
if (!ec) {
|
||||
|
||||
Reference in New Issue
Block a user