|
Core Library
1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
|
TCP connection class. More...
#include <TcpConnection.h>
Public Member Functions | |
| TcpConnection ()=delete | |
| Default constructor - deleted. | |
| TcpConnection (boost_iocontext_t &ioContext, TcpConnections &connections, size_t minAmountToRead, const defs::check_bytes_left_to_read_t &checkBytesLeftToRead, const defs::message_received_handler_t &messageReceivedHandler, eSendOption sendOption=eSendOption::nagleOn, size_t maxAllowedUnsentAsyncMessages=MAX_UNSENT_ASYNC_MSG_COUNT) | |
| Initialisation constructor. More... | |
| TcpConnection (const TcpConnection &)=delete | |
| Copy constructor deleted. | |
| TcpConnection & | operator= (const TcpConnection &)=delete |
| Copy assignment operator - deleted. | |
| TcpConnection (TcpConnection &&)=delete | |
| Move constructor deleted. | |
| TcpConnection & | operator= (TcpConnection &&)=delete |
| Move assignment operator - deleted. | |
| virtual | ~TcpConnection ()=default |
| Default virtual destructor. | |
| boost_tcp_t::socket & | Socket () |
| Get mutable reference to the socket object. More... | |
| const boost_tcp_t::socket & | Socket () const |
| Get a const reference to the socket object. More... | |
| void | Connect (const defs::connection_t &endPoint) |
| Connect to an endpoint. More... | |
| void | CloseConnection () |
| Close this connection. | |
| void | StartAsyncRead () |
| Start aysnchronously reading data when available. | |
| bool | SendMessageAsync (const defs::char_buffer_t &message) |
| Send an asynchronous message. More... | |
| bool | SendMessageSync (const defs::char_buffer_t &message) |
| Send a synchronous message. More... | |
| size_t | NumberOfUnsentAsyncMessages () const |
| Get number of unsent async messages. More... | |
Private Member Functions | |
| void | SetClosing (bool closing) |
| Set closing flag. More... | |
| bool | IsClosing () const |
| Is the connection closing? More... | |
| void | ProcessCloseSocket () |
| Process closing of socket. | |
| void | DestroySelf () |
| Self destruct this object. | |
| void | AsyncReadFromSocket (size_t amountToRead) |
| Asynchronously read an amount. More... | |
| void | ReadComplete (const boost_sys::error_code &error, size_t bytesReceived, size_t bytesExpected) |
| Read completion handler. More... | |
| void | AsyncWriteToSocket (defs::char_buffer_t const &message) |
| Asynchronously write to the socket. More... | |
| bool | IncrementUnsentAsyncCounter () |
| Increment unsent async message counter. More... | |
| void | DecrementUnsentAsyncCounter () |
| Decrement unsent async message counter. | |
Private Attributes | |
| std::mutex | m_mutex |
| Access mutex for thread safety. | |
| threads::SyncEvent | m_closedEvent {} |
| Connection close event. | |
| bool | m_closing {false} |
| Closing connection flag. | |
| boost_iocontext_t::strand | m_strand |
| I/O context strand. | |
| TcpConnections & | m_connections |
| Reference to TCP connections object. | |
| size_t | m_minAmountToRead {0} |
| Minimum amount to read from socket. | |
| defs::check_bytes_left_to_read_t | m_checkBytesLeftToRead {} |
| Check bytes left to read callback. | |
| defs::message_received_handler_t | m_messageReceivedHandler {} |
| Message received handler callback. | |
| eSendOption | m_sendOption {eSendOption::nagleOn} |
| Socket send option. | |
| defs::char_buffer_t | m_receiveBuffer {} |
| Socket receive buffer. | |
| defs::char_buffer_t | m_messageBuffer {} |
| Message buffer. | |
| size_t | m_maxAllowedUnsentAsyncMessages {MAX_UNSENT_ASYNC_MSG_COUNT} |
| Max allowed unsent async message counter. | |
| size_t | m_numUnsentAsyncMessages {0} |
| Unsent async message counter. | |
| boost_tcp_t::socket | m_socket |
| TCP socket. | |
TCP connection class.
This class is the one of the fundamental building blocks for the other TCP networking classes.
| core_lib::asio::tcp::TcpConnection::TcpConnection | ( | boost_iocontext_t & | ioContext, |
| TcpConnections & | connections, | ||
| size_t | minAmountToRead, | ||
| const defs::check_bytes_left_to_read_t & | checkBytesLeftToRead, | ||
| const defs::message_received_handler_t & | messageReceivedHandler, | ||
| eSendOption | sendOption = eSendOption::nagleOn, |
||
| size_t | maxAllowedUnsentAsyncMessages = MAX_UNSENT_ASYNC_MSG_COUNT |
||
| ) |
Initialisation constructor.
| [in] | ioContext | - Reference to I/O context. |
| [in] | connections | - Reference to TCP connections object. |
| [in] | minAmountToRead | - Minimum amount to read. |
| [in] | checkBytesLeftToRead | - Check bytes left to read callback. |
| [in] | messageReceivedHandler | - Message received handler callback. |
| [in] | sendOption | - Socket send option. |
| [in] | maxAllowedUnsentAsyncMessages | - Maximum allowed number of unsent async messages. |
|
private |
Asynchronously read an amount.
| [in] | amountToRead | - Number of bytes to read from socket. |
|
private |
Asynchronously write to the socket.
| [in] | message | - Message buffer to write. |
| void core_lib::asio::tcp::TcpConnection::Connect | ( | const defs::connection_t & | endPoint | ) |
Connect to an endpoint.
| [in] | endPoint | - Connection details of some endpoint. |
|
private |
Increment unsent async message counter.
|
private |
Is the connection closing?
| size_t core_lib::asio::tcp::TcpConnection::NumberOfUnsentAsyncMessages | ( | ) | const |
Get number of unsent async messages.
|
private |
Read completion handler.
| [in] | error | - Error flag if fault occurred. |
| [in] | bytesReceived | - Number of bytes received. |
| [in] | bytesExpected | - Number of bytes expected. |
| bool core_lib::asio::tcp::TcpConnection::SendMessageAsync | ( | const defs::char_buffer_t & | message | ) |
Send an asynchronous message.
| [in] | message | - Message buffer to send. |
| bool core_lib::asio::tcp::TcpConnection::SendMessageSync | ( | const defs::char_buffer_t & | message | ) |
Send a synchronous message.
| [in] | message | - Message buffer to send. |
|
private |
Set closing flag.
| [in] | closing | - Closing state flag. |
| boost_tcp_t::socket & core_lib::asio::tcp::TcpConnection::Socket | ( | ) |
Get mutable reference to the socket object.
| const boost_tcp_t::socket & core_lib::asio::tcp::TcpConnection::Socket | ( | ) | const |
Get a const reference to the socket object.