mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-22 20:57:46 +00:00
Added asio as submodule, some initial network changes
This commit is contained in:
parent
990a656a72
commit
a9ee2a7ebc
7 changed files with 52 additions and 33 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "deps/asio"]
|
||||
path = deps/asio
|
||||
url = https://github.com/chriskohlhoff/asio.git
|
1
deps/asio
vendored
Submodule
1
deps/asio
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 28d9b8d6df708024af5227c551673fdb2519f5bf
|
|
@ -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/")
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,26 +1,43 @@
|
|||
#ifndef ACCEPTOR_H_
|
||||
#define ACCEPTOR_H_
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <asio.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <atomic>
|
||||
#include "Forwards.h"
|
||||
#include <system_error>
|
||||
#include <asio/defer.hpp>
|
||||
#include <asio/executor.hpp>
|
||||
#include <asio/post.hpp>
|
||||
#include <asio/strand.hpp>
|
||||
#include <asio/system_executor.hpp>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <typeinfo>
|
||||
#include <vector>
|
||||
|
||||
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();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <boost/bind.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/interprocess/detail/atomic.hpp>
|
||||
#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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef HIVE_H_
|
||||
#define HIVE_H_
|
||||
|
||||
#include <asio.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue