MeVisLab Toolbox Reference
asio::TcpSocket Class Reference

A TCP socket class implementing the asio::Socket interface. More...

#include <TcpSocket.h>

Inheritance diagram for asio::TcpSocket:
asio::Socket asio::TlsSocket

Public Member Functions

 TcpSocket (std::shared_ptr< Context > context)
 
 ~TcpSocket () override
 
template<typename ConnectCompletionHandler >
void async_connect (const std::string &host, const unsigned short port, ConnectCompletionHandler &&handler)
 
bool is_open () const
 
bool is_valid () const override
 
void async_read (void *buffer, const std::size_t buffer_size, const CompletionHandler &handler) override
 
void async_write (const void *buffer, const std::size_t buffer_size, const CompletionHandler &handler) override
 
void close () override
 
 TcpSocket (const TcpSocket &)=delete
 
TcpSocketoperator= (const TcpSocket &)=delete
 
- Public Member Functions inherited from asio::Socket
virtual ~Socket ()=default
 

Protected Attributes

std::shared_ptr< Contextcontext
 
boost::asio::ip::tcp::socket socket
 

Friends

class TcpAcceptor
 

Additional Inherited Members

- Public Types inherited from asio::Socket
using CompletionHandler = std::function< void(const ErrorCode &, const std::size_t)>
 

Detailed Description

A TCP socket class implementing the asio::Socket interface.

Synopsis:

auto context = std::make_shared<asio::Context>();
socket.async_connect("127.0.0.1", 8080, [] (const asio::ErrorCode& ec) {
if (!ec) {
// connection established!
}
});
context->run(); // this blocks (as usual) and normally done somewhere else.
A TCP socket class implementing the asio::Socket interface.
Definition: TcpSocket.h:36
std::shared_ptr< Context > context
Definition: TcpSocket.h:95
boost::asio::ip::tcp::socket socket
Definition: TcpSocket.h:97
boost::system::error_code ErrorCode
Definition: ErrorCodes.h:13

Definition at line 35 of file TcpSocket.h.

Constructor & Destructor Documentation

◆ TcpSocket() [1/2]

asio::TcpSocket::TcpSocket ( std::shared_ptr< Context context)

◆ ~TcpSocket()

asio::TcpSocket::~TcpSocket ( )
override

◆ TcpSocket() [2/2]

asio::TcpSocket::TcpSocket ( const TcpSocket )
delete

Member Function Documentation

◆ async_connect()

template<typename ConnectCompletionHandler >
void asio::TcpSocket::async_connect ( const std::string &  host,
const unsigned short  port,
ConnectCompletionHandler &&  handler 
)
inline

Definition at line 44 of file TcpSocket.h.

◆ async_read()

void asio::TcpSocket::async_read ( void *  buffer,
const std::size_t  buffer_size,
const CompletionHandler handler 
)
overridevirtual

Implements asio::Socket.

Reimplemented in asio::TlsSocket.

◆ async_write()

void asio::TcpSocket::async_write ( const void *  buffer,
const std::size_t  buffer_size,
const CompletionHandler handler 
)
overridevirtual

Implements asio::Socket.

Reimplemented in asio::TlsSocket.

◆ close()

void asio::TcpSocket::close ( )
overridevirtual

Implements asio::Socket.

Reimplemented in asio::TlsSocket.

◆ is_open()

bool asio::TcpSocket::is_open ( ) const

◆ is_valid()

bool asio::TcpSocket::is_valid ( ) const
overridevirtual

Implements asio::Socket.

Reimplemented in asio::TlsSocket.

◆ operator=()

TcpSocket& asio::TcpSocket::operator= ( const TcpSocket )
delete

Friends And Related Function Documentation

◆ TcpAcceptor

friend class TcpAcceptor
friend

Definition at line 93 of file TcpSocket.h.

Member Data Documentation

◆ context

std::shared_ptr<Context> asio::TcpSocket::context
protected

Definition at line 95 of file TcpSocket.h.

◆ socket

boost::asio::ip::tcp::socket asio::TcpSocket::socket
protected

Definition at line 97 of file TcpSocket.h.

Referenced by asio::TcpAcceptor::async_accept().


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