mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-25 05:57:45 +00:00
Boost asio no longer used
This commit is contained in:
parent
a9ee2a7ebc
commit
d5f59a72f0
6 changed files with 33 additions and 45 deletions
|
@ -47,5 +47,5 @@ target_include_directories( common
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/"
|
||||
PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../deps/asio/include/")
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../deps/asio/asio/include/")
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ void Acceptor::StartError( const asio::error_code& error )
|
|||
uint32_t v2 = 0;
|
||||
if( m_error_state.compare_exchange_strong( v1, v2 ) )
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
asio::error_code ec;
|
||||
m_acceptor.cancel( ec );
|
||||
m_acceptor.close( ec );
|
||||
OnError( error );
|
||||
|
|
|
@ -7,11 +7,6 @@
|
|||
#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>
|
||||
|
@ -19,11 +14,6 @@
|
|||
#include <typeinfo>
|
||||
#include <vector>
|
||||
|
||||
using asio::defer;
|
||||
using asio::executor;
|
||||
using asio::post;
|
||||
using asio::strand;
|
||||
using asio::system_executor;
|
||||
|
||||
namespace Core {
|
||||
namespace Network {
|
||||
|
@ -76,7 +66,7 @@ public:
|
|||
asio::ip::tcp::acceptor& GetAcceptor();
|
||||
|
||||
// Returns the strand object.
|
||||
asio::strand< executor >& GetStrand();
|
||||
asio::strand& GetStrand();
|
||||
|
||||
// Returns true if this object has an error associated with it.
|
||||
bool HasError();
|
||||
|
|
|
@ -23,9 +23,9 @@ Connection::~Connection()
|
|||
|
||||
void Connection::Bind( const std::string& ip, uint16_t port )
|
||||
{
|
||||
boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string( ip ), port );
|
||||
asio::ip::tcp::endpoint endpoint( asio::ip::address::from_string( ip ), port );
|
||||
m_socket.open( endpoint.protocol() );
|
||||
m_socket.set_option( boost::asio::ip::tcp::acceptor::reuse_address( false ) );
|
||||
m_socket.set_option( asio::ip::tcp::acceptor::reuse_address( false ) );
|
||||
m_socket.bind( endpoint );
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,11 @@ void Connection::StartSend()
|
|||
{
|
||||
if( !m_pending_sends.empty() )
|
||||
{
|
||||
boost::asio::async_write( m_socket,
|
||||
boost::asio::buffer( m_pending_sends.front() ),
|
||||
asio::async_write( m_socket,
|
||||
asio::buffer( m_pending_sends.front() ),
|
||||
m_io_strand.wrap( boost::bind( &Connection::HandleSend,
|
||||
shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
asio::placeholders::error,
|
||||
m_pending_sends.begin() ) ) );
|
||||
}
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ void Connection::StartRecv( int32_t total_bytes )
|
|||
if( total_bytes > 0 )
|
||||
{
|
||||
m_recv_buffer.resize( total_bytes );
|
||||
boost::asio::async_read( m_socket,
|
||||
boost::asio::buffer( m_recv_buffer ),
|
||||
asio::async_read( m_socket,
|
||||
asio::buffer( m_recv_buffer ),
|
||||
m_io_strand.wrap( boost::bind( &Connection::HandleRecv,
|
||||
shared_from_this(),
|
||||
_1,
|
||||
|
@ -57,7 +57,7 @@ void Connection::StartRecv( int32_t total_bytes )
|
|||
else
|
||||
{
|
||||
m_recv_buffer.resize( m_receive_buffer_size );
|
||||
m_socket.async_read_some( boost::asio::buffer( m_recv_buffer ),
|
||||
m_socket.async_read_some( asio::buffer( m_recv_buffer ),
|
||||
m_io_strand.wrap( boost::bind( &Connection::HandleRecv,
|
||||
shared_from_this(),
|
||||
_1,
|
||||
|
@ -65,20 +65,20 @@ void Connection::StartRecv( int32_t total_bytes )
|
|||
}
|
||||
}
|
||||
|
||||
void Connection::StartError( const boost::system::error_code& error )
|
||||
void Connection::StartError( const asio::error_code& error )
|
||||
{
|
||||
uint32_t v1 = 1;
|
||||
uint32_t v2 = 0;
|
||||
if( !m_error_state.compare_exchange_strong( v1, v2 ) )
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
m_socket.shutdown( boost::asio::ip::tcp::socket::shutdown_both, ec );
|
||||
asio::error_code ec;
|
||||
m_socket.shutdown( asio::ip::tcp::socket::shutdown_both, ec );
|
||||
m_socket.close( ec );
|
||||
OnError( error );
|
||||
}
|
||||
}
|
||||
|
||||
void Connection::HandleConnect( const boost::system::error_code& error )
|
||||
void Connection::HandleConnect( const asio::error_code& error )
|
||||
{
|
||||
if( error || HasError() || m_hive->HasStopped() )
|
||||
{
|
||||
|
@ -99,7 +99,7 @@ void Connection::HandleConnect( const boost::system::error_code& error )
|
|||
}
|
||||
|
||||
void
|
||||
Connection::HandleSend( const boost::system::error_code& error, std::list< std::vector< uint8_t > >::iterator itr )
|
||||
Connection::HandleSend( const asio::error_code& error, std::list< std::vector< uint8_t > >::iterator itr )
|
||||
{
|
||||
if( error || HasError() || m_hive->HasStopped() )
|
||||
{
|
||||
|
@ -113,7 +113,7 @@ Connection::HandleSend( const boost::system::error_code& error, std::list< std::
|
|||
}
|
||||
}
|
||||
|
||||
void Connection::HandleRecv( const boost::system::error_code& error, int32_t actual_bytes )
|
||||
void Connection::HandleRecv( const asio::error_code& error, int32_t actual_bytes )
|
||||
{
|
||||
if( error || HasError() || m_hive->HasStopped() )
|
||||
{
|
||||
|
@ -155,9 +155,9 @@ void Connection::DispatchRecv( int32_t total_bytes )
|
|||
|
||||
void Connection::Connect( const std::string& host, uint16_t port )
|
||||
{
|
||||
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::resolver::iterator iterator = 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::resolver::iterator iterator = resolver.resolve( query );
|
||||
m_socket.async_connect( *iterator,
|
||||
m_io_strand.wrap( boost::bind( &Connection::HandleConnect, shared_from_this(), _1 ) ) );
|
||||
|
||||
|
@ -179,12 +179,12 @@ void Connection::Send( const std::vector< uint8_t >& buffer )
|
|||
m_io_strand.post( boost::bind( &Connection::DispatchSend, shared_from_this(), buffer ) );
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::socket& Connection::GetSocket()
|
||||
asio::ip::tcp::socket& Connection::GetSocket()
|
||||
{
|
||||
return m_socket;
|
||||
}
|
||||
|
||||
boost::asio::strand& Connection::GetStrand()
|
||||
asio::strand& Connection::GetStrand()
|
||||
{
|
||||
return m_io_strand;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <asio.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
@ -26,8 +26,7 @@ class Connection;
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class Connection :
|
||||
public boost::enable_shared_from_this< Connection >
|
||||
class Connection : public boost::enable_shared_from_this< Connection >
|
||||
{
|
||||
friend class Acceptor;
|
||||
|
||||
|
@ -35,8 +34,8 @@ class Connection :
|
|||
|
||||
protected:
|
||||
HivePtr m_hive;
|
||||
boost::asio::ip::tcp::socket m_socket;
|
||||
boost::asio::strand m_io_strand;
|
||||
asio::ip::tcp::socket m_socket;
|
||||
asio::strand m_io_strand;
|
||||
std::vector< uint8_t > m_recv_buffer;
|
||||
std::list< int32_t > m_pending_recvs;
|
||||
std::list< std::vector< uint8_t > > m_pending_sends;
|
||||
|
@ -57,17 +56,17 @@ private:
|
|||
|
||||
void StartRecv( int32_t total_bytes );
|
||||
|
||||
void StartError( const boost::system::error_code& error );
|
||||
void StartError( const asio::error_code& error );
|
||||
|
||||
void DispatchSend( std::vector< uint8_t > buffer );
|
||||
|
||||
void DispatchRecv( int32_t total_bytes );
|
||||
|
||||
void HandleConnect( const boost::system::error_code& error );
|
||||
void HandleConnect( const asio::error_code& error );
|
||||
|
||||
void HandleSend( const boost::system::error_code& error, std::list< std::vector< uint8_t > >::iterator itr );
|
||||
void HandleSend( const asio::error_code& error, std::list< std::vector< uint8_t > >::iterator itr );
|
||||
|
||||
void HandleRecv( const boost::system::error_code& error, int32_t actual_bytes );
|
||||
void HandleRecv( const asio::error_code& error, int32_t actual_bytes );
|
||||
|
||||
|
||||
private:
|
||||
|
@ -92,7 +91,7 @@ private:
|
|||
};
|
||||
|
||||
// Called when an error is encountered.
|
||||
virtual void OnError( const boost::system::error_code& error )
|
||||
virtual void OnError( const asio::error_code& error )
|
||||
{
|
||||
};
|
||||
|
||||
|
@ -106,10 +105,10 @@ public:
|
|||
HivePtr GetHive();
|
||||
|
||||
// Returns the socket object.
|
||||
boost::asio::ip::tcp::socket& GetSocket();
|
||||
asio::ip::tcp::socket& GetSocket();
|
||||
|
||||
// Returns the strand object.
|
||||
boost::asio::strand& GetStrand();
|
||||
asio::strand& GetStrand();
|
||||
|
||||
// Sets the application specific receive buffer size used. For stream
|
||||
// based protocols such as HTTP, you want this to be pretty large, like
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define HIVE_H_
|
||||
|
||||
#include <asio.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <atomic>
|
||||
|
|
Loading…
Add table
Reference in a new issue