diff --git a/network/ConnectionProvider.hpp b/network/ConnectionProvider.hpp index a7884af0..bd33bd9f 100644 --- a/network/ConnectionProvider.hpp +++ b/network/ConnectionProvider.hpp @@ -36,6 +36,7 @@ public: typedef oatpp::async::Action Action; typedef oatpp::async::Action (oatpp::async::AbstractCoroutine::*AsyncCallback)(const std::shared_ptr&); public: + virtual ~ConnectionProvider() {} virtual std::shared_ptr getConnection() = 0; virtual Action getConnectionAsync(oatpp::async::AbstractCoroutine* parentCoroutine, AsyncCallback callback) = 0; diff --git a/network/server/SimpleTCPConnectionProvider.hpp b/network/server/SimpleTCPConnectionProvider.hpp index 56702341..76e1bd41 100644 --- a/network/server/SimpleTCPConnectionProvider.hpp +++ b/network/server/SimpleTCPConnectionProvider.hpp @@ -52,11 +52,21 @@ public: return std::shared_ptr(new SimpleTCPConnectionProvider(port, nonBlocking)); } + ~SimpleTCPConnectionProvider() { + oatpp::os::io::Library::handle_close(m_serverHandle); + } + std::shared_ptr getConnection() override; Action getConnectionAsync(oatpp::async::AbstractCoroutine* parentCoroutine, AsyncCallback callback) override { - throw std::runtime_error("oatpp::network::server::SimpleTCPConnectionProvider::getConnectionAsync not implemented"); + /** + * No need to implement this. + * For Asynchronous IO in oatpp it is considered to be a good practice + * to accept connections in a seperate thread with the blocking accept() + * and then process connections in Asynchronous manner with non-blocking read/write + */ + throw std::runtime_error("oatpp::network::server::SimpleTCPConnectionProvider::getConnectionAsync not implemented."); } };