TrinityCore
Socket< T, Stream > Class Template Referenceabstract

#include <Socket.h>

+ Inheritance diagram for Socket< T, Stream >:

Public Member Functions

template<typename... Args>
 Socket (boost::asio::ip::tcp::socket &&socket, Args &&... args)
 
 Socket (Socket const &other)=delete
 
 Socket (Socket &&other)=delete
 
Socketoperator= (Socket const &other)=delete
 
Socketoperator= (Socket &&other)=delete
 
virtual ~Socket ()
 
virtual void Start ()=0
 
virtual bool Update ()
 
boost::asio::ip::address GetRemoteIpAddress () const
 
uint16 GetRemotePort () const
 
void AsyncRead ()
 
void AsyncReadWithCallback (void(T::*callback)(boost::system::error_code const &, std::size_t))
 
void QueuePacket (MessageBuffer &&buffer)
 
bool IsOpen () const
 
void CloseSocket ()
 
void DelayedCloseSocket ()
 Marks the socket for closing after write buffer becomes empty. More...
 
MessageBufferGetReadBuffer ()
 

Protected Member Functions

virtual void OnClose ()
 
virtual void ReadHandler ()=0
 
bool AsyncProcessQueue ()
 
void SetNoDelay (bool enable)
 
Stream & underlying_stream ()
 

Private Member Functions

void ReadHandlerInternal (boost::system::error_code const &error, size_t transferredBytes)
 
void WriteHandlerWrapper (boost::system::error_code const &, std::size_t)
 
bool HandleQueue ()
 

Private Attributes

Stream _socket
 
boost::asio::ip::address _remoteAddress
 
uint16 _remotePort
 
MessageBuffer _readBuffer
 
std::queue< MessageBuffer_writeQueue
 
std::atomic< bool > _closed
 
std::atomic< bool > _closing
 
bool _isWritingAsync
 

Detailed Description

template<class T, class Stream = boost::asio::ip::tcp::socket>
class Socket< T, Stream >

Base async socket implementation

Template Parameters
Tderived class type (CRTP)
Streamstream type used for operations on socket Stream must implement the following methods:

void close(boost::system::error_code& error);

void shutdown(boost::asio::socket_base::shutdown_type what, boost::system::error_code& shutdownError);

template<typename MutableBufferSequence, typename ReadHandlerType> void async_read_some(MutableBufferSequence const& buffers, ReadHandlerType&& handler);

template<typename ConstBufferSequence, typename WriteHandlerType> void async_write_some(ConstBufferSequence const& buffers, WriteHandlerType&& handler);

template<typename ConstBufferSequence> std::size_t write_some(ConstBufferSequence const& buffers, boost::system::error_code& error);

template<typename SettableSocketOption> void set_option(SettableSocketOption const& option, boost::system::error_code& error);

tcp::socket::endpoint_type remote_endpoint() const;

Definition at line 62 of file Socket.h.

Constructor & Destructor Documentation

◆ Socket() [1/3]

template<class T , class Stream = boost::asio::ip::tcp::socket>
template<typename... Args>
Socket< T, Stream >::Socket ( boost::asio::ip::tcp::socket &&  socket,
Args &&...  args 
)
inlineexplicit

Definition at line 66 of file Socket.h.

+ Here is the call graph for this function:

◆ Socket() [2/3]

template<class T , class Stream = boost::asio::ip::tcp::socket>
Socket< T, Stream >::Socket ( Socket< T, Stream > const &  other)
delete

◆ Socket() [3/3]

template<class T , class Stream = boost::asio::ip::tcp::socket>
Socket< T, Stream >::Socket ( Socket< T, Stream > &&  other)
delete

◆ ~Socket()

template<class T , class Stream = boost::asio::ip::tcp::socket>
virtual Socket< T, Stream >::~Socket ( )
inlinevirtual

Reimplemented in Trinity::Net::Http::Socket< Derived >.

Definition at line 78 of file Socket.h.

Member Function Documentation

◆ AsyncProcessQueue()

template<class T , class Stream = boost::asio::ip::tcp::socket>
bool Socket< T, Stream >::AsyncProcessQueue ( )
inlineprotected

Definition at line 176 of file Socket.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AsyncRead()

template<class T , class Stream = boost::asio::ip::tcp::socket>
void Socket< T, Stream >::AsyncRead ( )
inline

Definition at line 113 of file Socket.h.

+ Here is the call graph for this function:

◆ AsyncReadWithCallback()

template<class T , class Stream = boost::asio::ip::tcp::socket>
void Socket< T, Stream >::AsyncReadWithCallback ( void(T::*)(boost::system::error_code const &, std::size_t)  callback)
inline

Definition at line 127 of file Socket.h.

+ Here is the call graph for this function:

◆ CloseSocket()

template<class T , class Stream = boost::asio::ip::tcp::socket>
void Socket< T, Stream >::CloseSocket ( )
inline

Definition at line 152 of file Socket.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DelayedCloseSocket()

template<class T , class Stream = boost::asio::ip::tcp::socket>
void Socket< T, Stream >::DelayedCloseSocket ( )
inline

Marks the socket for closing after write buffer becomes empty.

Definition at line 167 of file Socket.h.

◆ GetReadBuffer()

template<class T , class Stream = boost::asio::ip::tcp::socket>
MessageBuffer & Socket< T, Stream >::GetReadBuffer ( )
inline

Definition at line 169 of file Socket.h.

◆ GetRemoteIpAddress()

template<class T , class Stream = boost::asio::ip::tcp::socket>
boost::asio::ip::address Socket< T, Stream >::GetRemoteIpAddress ( ) const
inline

Definition at line 103 of file Socket.h.

+ Here is the caller graph for this function:

◆ GetRemotePort()

template<class T , class Stream = boost::asio::ip::tcp::socket>
uint16 Socket< T, Stream >::GetRemotePort ( ) const
inline

Definition at line 108 of file Socket.h.

◆ HandleQueue()

template<class T , class Stream = boost::asio::ip::tcp::socket>
bool Socket< T, Stream >::HandleQueue ( )
inlineprivate

Definition at line 256 of file Socket.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsOpen()

template<class T , class Stream = boost::asio::ip::tcp::socket>
bool Socket< T, Stream >::IsOpen ( ) const
inline

Definition at line 150 of file Socket.h.

+ Here is the caller graph for this function:

◆ OnClose()

template<class T , class Stream = boost::asio::ip::tcp::socket>
virtual void Socket< T, Stream >::OnClose ( )
inlineprotectedvirtual

Reimplemented in WorldSocket.

Definition at line 172 of file Socket.h.

+ Here is the caller graph for this function:

◆ operator=() [1/2]

template<class T , class Stream = boost::asio::ip::tcp::socket>
Socket & Socket< T, Stream >::operator= ( Socket< T, Stream > &&  other)
delete

◆ operator=() [2/2]

template<class T , class Stream = boost::asio::ip::tcp::socket>
Socket & Socket< T, Stream >::operator= ( Socket< T, Stream > const &  other)
delete

◆ QueuePacket()

template<class T , class Stream = boost::asio::ip::tcp::socket>
void Socket< T, Stream >::QueuePacket ( MessageBuffer &&  buffer)
inline

Definition at line 141 of file Socket.h.

+ Here is the call graph for this function:

◆ ReadHandler()

template<class T , class Stream = boost::asio::ip::tcp::socket>
virtual void Socket< T, Stream >::ReadHandler ( )
protectedpure virtual

◆ ReadHandlerInternal()

template<class T , class Stream = boost::asio::ip::tcp::socket>
void Socket< T, Stream >::ReadHandlerInternal ( boost::system::error_code const &  error,
size_t  transferredBytes 
)
inlineprivate

Definition at line 216 of file Socket.h.

+ Here is the call graph for this function:

◆ SetNoDelay()

template<class T , class Stream = boost::asio::ip::tcp::socket>
void Socket< T, Stream >::SetNoDelay ( bool  enable)
inlineprotected

Definition at line 201 of file Socket.h.

+ Here is the call graph for this function:

◆ Start()

template<class T , class Stream = boost::asio::ip::tcp::socket>
virtual void Socket< T, Stream >::Start ( )
pure virtual

◆ underlying_stream()

template<class T , class Stream = boost::asio::ip::tcp::socket>
Stream & Socket< T, Stream >::underlying_stream ( )
inlineprotected

Definition at line 210 of file Socket.h.

◆ Update()

template<class T , class Stream = boost::asio::ip::tcp::socket>
virtual bool Socket< T, Stream >::Update ( )
inlinevirtual

◆ WriteHandlerWrapper()

template<class T , class Stream = boost::asio::ip::tcp::socket>
void Socket< T, Stream >::WriteHandlerWrapper ( boost::system::error_code const &  ,
std::size_t   
)
inlineprivate

Definition at line 250 of file Socket.h.

+ Here is the call graph for this function:

Member Data Documentation

◆ _closed

template<class T , class Stream = boost::asio::ip::tcp::socket>
std::atomic<bool> Socket< T, Stream >::_closed
private

Definition at line 307 of file Socket.h.

◆ _closing

template<class T , class Stream = boost::asio::ip::tcp::socket>
std::atomic<bool> Socket< T, Stream >::_closing
private

Definition at line 308 of file Socket.h.

◆ _isWritingAsync

template<class T , class Stream = boost::asio::ip::tcp::socket>
bool Socket< T, Stream >::_isWritingAsync
private

Definition at line 310 of file Socket.h.

◆ _readBuffer

template<class T , class Stream = boost::asio::ip::tcp::socket>
MessageBuffer Socket< T, Stream >::_readBuffer
private

Definition at line 304 of file Socket.h.

◆ _remoteAddress

template<class T , class Stream = boost::asio::ip::tcp::socket>
boost::asio::ip::address Socket< T, Stream >::_remoteAddress
private

Definition at line 301 of file Socket.h.

◆ _remotePort

template<class T , class Stream = boost::asio::ip::tcp::socket>
uint16 Socket< T, Stream >::_remotePort
private

Definition at line 302 of file Socket.h.

◆ _socket

template<class T , class Stream = boost::asio::ip::tcp::socket>
Stream Socket< T, Stream >::_socket
private

Definition at line 299 of file Socket.h.

◆ _writeQueue

template<class T , class Stream = boost::asio::ip::tcp::socket>
std::queue<MessageBuffer> Socket< T, Stream >::_writeQueue
private

Definition at line 305 of file Socket.h.


The documentation for this class was generated from the following file: