diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..d1faa1ae --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/asio"] + path = deps/asio + url = https://github.com/chriskohlhoff/asio.git diff --git a/deps/asio b/deps/asio new file mode 160000 index 00000000..28d9b8d6 --- /dev/null +++ b/deps/asio @@ -0,0 +1 @@ +Subproject commit 28d9b8d6df708024af5227c551673fdb2519f5bf diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 01e031f7..4cb72410 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -46,5 +46,6 @@ target_include_directories( common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/" PRIVATE - "${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/" ) + "${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/" + "${CMAKE_CURRENT_SOURCE_DIR}/../../deps/asio/include/") diff --git a/src/common/Network/Acceptor.cpp b/src/common/Network/Acceptor.cpp index 2b04cc43..d89cc35b 100644 --- a/src/common/Network/Acceptor.cpp +++ b/src/common/Network/Acceptor.cpp @@ -8,8 +8,7 @@ namespace Network { //----------------------------------------------------------------------------- -Acceptor::Acceptor( HivePtr hive ) - : +Acceptor::Acceptor( HivePtr hive ) : m_hive( hive ), m_acceptor( hive->GetService() ), m_io_strand( hive->GetService() ), @@ -27,13 +26,13 @@ bool Acceptor::OnAccept( ConnectionPtr connection, const std::string& host, uint return true; } -void Acceptor::OnError( const boost::system::error_code& error ) +void Acceptor::OnError( const asio::error_code& error ) { } -void Acceptor::StartError( const boost::system::error_code& error ) +void Acceptor::StartError( const asio::error_code& error ) { uint32_t v1 = 1; uint32_t v2 = 0; @@ -55,7 +54,7 @@ void Acceptor::DispatchAccept( ConnectionPtr connection ) connection ) ) ); } -void Acceptor::HandleAccept( const boost::system::error_code& error, ConnectionPtr connection ) +void Acceptor::HandleAccept( const asio::error_code& error, ConnectionPtr connection ) { if( error || HasError() || m_hive->HasStopped() ) { @@ -95,14 +94,14 @@ void Acceptor::Listen( const std::string& host, const uint16_t& port ) { try { - boost::asio::ip::tcp::resolver resolver( m_hive->GetService() ); - boost::asio::ip::tcp::resolver::query query( host, std::to_string( port ) ); - boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve( query ); + asio::ip::tcp::resolver resolver( m_hive->GetService() ); + asio::ip::tcp::resolver::query query( host, std::to_string( port ) ); + asio::ip::tcp::endpoint endpoint = *resolver.resolve( query ); m_acceptor.open( endpoint.protocol() ); - m_acceptor.set_option( boost::asio::ip::tcp::acceptor::reuse_address( false ) ); + m_acceptor.set_option( asio::ip::tcp::acceptor::reuse_address( false ) ); m_acceptor.bind( endpoint ); - m_acceptor.listen( boost::asio::socket_base::max_connections ); + m_acceptor.listen( asio::socket_base::max_connections ); } catch( ... ) { @@ -117,7 +116,7 @@ HivePtr Acceptor::GetHive() return m_hive; } -boost::asio::ip::tcp::acceptor& Acceptor::GetAcceptor() +asio::ip::tcp::acceptor& Acceptor::GetAcceptor() { return m_acceptor; } diff --git a/src/common/Network/Acceptor.h b/src/common/Network/Acceptor.h index e73114ab..fe0cd9eb 100644 --- a/src/common/Network/Acceptor.h +++ b/src/common/Network/Acceptor.h @@ -1,26 +1,43 @@ #ifndef ACCEPTOR_H_ #define ACCEPTOR_H_ -#include +#include #include #include #include #include "Forwards.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using asio::defer; +using asio::executor; +using asio::post; +using asio::strand; +using asio::system_executor; namespace Core { namespace Network { class Connection; -class Acceptor : - public boost::enable_shared_from_this< Acceptor > +class Acceptor : public boost::enable_shared_from_this< Acceptor > { friend class Hive; private: HivePtr m_hive; - boost::asio::ip::tcp::acceptor m_acceptor; - boost::asio::strand m_io_strand; + asio::ip::tcp::acceptor m_acceptor; + asio::strand m_io_strand; std::atomic< uint32_t > m_error_state; private: @@ -28,11 +45,11 @@ private: Acceptor& operator=( const Acceptor& rhs ); - void StartError( const boost::system::error_code& error ); + void StartError( const asio::error_code& error ); void DispatchAccept( ConnectionPtr connection ); - void HandleAccept( const boost::system::error_code& error, ConnectionPtr connection ); + void HandleAccept( const asio::error_code& error, ConnectionPtr connection ); private: // Called when a connection has connected to the server. This function @@ -45,7 +62,7 @@ private: // Called when an error is encountered. Most typically, this is when the // acceptor is being closed via the Stop function or if the Listen is // called on an address that is not available. - virtual void OnError( const boost::system::error_code& error ); + virtual void OnError( const asio::error_code& error ); public: Acceptor( HivePtr hive ); @@ -56,10 +73,10 @@ public: HivePtr GetHive(); // Returns the acceptor object. - boost::asio::ip::tcp::acceptor& GetAcceptor(); + asio::ip::tcp::acceptor& GetAcceptor(); // Returns the strand object. - boost::asio::strand& GetStrand(); + asio::strand< executor >& GetStrand(); // Returns true if this object has an error associated with it. bool HasError(); diff --git a/src/common/Network/Hive.cpp b/src/common/Network/Hive.cpp index 772cfa40..b8cca600 100644 --- a/src/common/Network/Hive.cpp +++ b/src/common/Network/Hive.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "Hive.h" namespace Core { @@ -8,9 +7,8 @@ namespace Network { //----------------------------------------------------------------------------- -Hive::Hive() - : - m_work_ptr( new boost::asio::io_service::work( m_io_service ) ), +Hive::Hive() : + m_work_ptr( new asio::io_service::work( m_io_service ) ), m_shutdown( 0 ) { } @@ -19,7 +17,7 @@ Hive::~Hive() { } -boost::asio::io_service& Hive::GetService() +asio::io_service& Hive::GetService() { return m_io_service; } @@ -60,7 +58,7 @@ void Hive::Reset() if( m_shutdown.compare_exchange_strong( v1, v2 ) ) { m_io_service.reset(); - m_work_ptr.reset( new boost::asio::io_service::work( m_io_service ) ); + m_work_ptr.reset( new asio::io_service::work( m_io_service ) ); } } diff --git a/src/common/Network/Hive.h b/src/common/Network/Hive.h index 41ed1d88..61d50717 100644 --- a/src/common/Network/Hive.h +++ b/src/common/Network/Hive.h @@ -1,6 +1,7 @@ #ifndef HIVE_H_ #define HIVE_H_ +#include #include #include @@ -9,12 +10,11 @@ namespace Core { namespace Network { -class Hive : - public boost::enable_shared_from_this< Hive > +class Hive : public boost::enable_shared_from_this< Hive > { private: - boost::asio::io_service m_io_service; - boost::shared_ptr< boost::asio::io_service::work > m_work_ptr; + asio::io_service m_io_service; + boost::shared_ptr< asio::io_service::work > m_work_ptr; std::atomic< uint32_t > m_shutdown; private: @@ -28,7 +28,7 @@ public: virtual ~Hive(); // Returns the io_service of this object. - boost::asio::io_service& GetService(); + asio::io_service& GetService(); // Returns true if the Stop function has been called. bool HasStopped();