Core Library 1.7.0.0 Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.

Public Member Functions | Private Types | Private Attributes | List of all members
core_lib::asio::tcp::TcpConnections Class Referencefinal

TCP connections class to manage the TcpConnection objects. More...

`#include <TcpConnections.h>`

## Public Member Functions
| TcpConnections ()=default
| Default constructor.
| ~TcpConnections ()=default
| Default desctructor.
| TcpConnections (const TcpConnections &)=delete
| Copy constructor - deleted.
TcpConnections & | operator= (const TcpConnections &)=delete
| Copy assignment operator - deleted.
| TcpConnections (TcpConnections &&)=delete
| Move constructor - deleted.
TcpConnections & | operator= (TcpConnections &&)=delete
| Move assignment operator - deleted.
void | Add (defs::tcp_conn_ptr_t const &connection)
| Add a connection. More...
void | Remove (defs::tcp_conn_ptr_t const &connection)
| Remove a connection. More...
size_t | Size () const
| Get the number of connections. More...
bool | Empty () const
| Is the connection map empty? More...
void | CloseConnections ()
| Close all connections.
bool | SendMessageAsync (const defs::connection_t &target, const defs::char_buffer_t &message) const
| Send an asynchronous message. More...
bool | SendMessageSync (const defs::connection_t &target, const defs::char_buffer_t &message) const
| Send a synchronous message. More...
bool | SendMessageToAll (const defs::char_buffer_t &message) const
| Send an asynchronous message to all connections. More...
defs::connection_t | GetLocalEndForRemoteEnd (const defs::connection_t &remoteEnd) const
| Get the connection details for one of the remote connections. More...
size_t | NumberOfUnsentAsyncMessages (const defs::connection_t &target) const
| Get number of unsent async messages. More...
bool | IsConnected (const defs::connection_t &client) const
| Tells if a given client is currently connected ot the server. More...

## Private Types
using | tcp_conn_map = std::map< defs::connection_t, defs::tcp_conn_ptr_t >
| Typedef to our connection map type.

## Private Attributes
std::mutex | m_mutex
| Access mutex for thread safety.
tcp_conn_map | m_connections {}
| The connections map.

## Detailed Description

TCP connections class to manage the TcpConnection objects.

This class is the one of the fundamental building blocks for the other TCP networking classes.

## Member Function Documentation

## ◆ Add()

void core_lib::asio::tcp::TcpConnections::Add | ( | defs::tcp_conn_ptr_t const & | connection | ) |

Add a connection.

Parameters

  [in] | connection | - Shared pointer to connection object.

## ◆ Empty()

bool core_lib::asio::tcp::TcpConnections::Empty | ( |  | ) | const

Is the connection map empty?

Returns
  True if empty, false otherwise.

## ◆ GetLocalEndForRemoteEnd()

auto core_lib::asio::tcp::TcpConnections::GetLocalEndForRemoteEnd | ( | const defs::connection_t & | remoteEnd | ) | const

Get the connection details for one of the remote connections.

Parameters

  [in] | remoteEnd | - Remote end's connection details.

Returns
  Connection details for remote end.

Throws std::invalid_argument if remoteEnd is not valid.

## ◆ IsConnected()

bool core_lib::asio::tcp::TcpConnections::IsConnected | ( | const defs::connection_t & | client | ) | const

Tells if a given client is currently connected ot the server.

Parameters

  [in] | target | - Target connection details.

Returns
  true if connected, false if not

## ◆ NumberOfUnsentAsyncMessages()

size_t core_lib::asio::tcp::TcpConnections::NumberOfUnsentAsyncMessages | ( | const defs::connection_t & | target | ) | const

Get number of unsent async messages.

Parameters

  [in] | target | - Target connection details.

Returns
  Number of unsent messages

## ◆ Remove()

void core_lib::asio::tcp::TcpConnections::Remove | ( | defs::tcp_conn_ptr_t const & | connection | ) |

Remove a connection.

Parameters

  [in] | connection | - Shared pointer to connection object.

## ◆ SendMessageAsync()

bool core_lib::asio::tcp::TcpConnections::SendMessageAsync | ( | const defs::connection_t & | target,
|  | const defs::char_buffer_t & | message
| ) |  | const

Send an asynchronous message.

Parameters

  [in] | target | - Target connection details.
  [in] | message | - Message buffer to send.

Returns
  True if sent successfully, false otherwise.

## ◆ SendMessageSync()

bool core_lib::asio::tcp::TcpConnections::SendMessageSync | ( | const defs::connection_t & | target,
|  | const defs::char_buffer_t & | message
| ) |  | const

Send a synchronous message.

Parameters

  [in] | target | - Target connection details.
  [in] | message | - Message buffer to send.

Returns
  True if sent successfully, false otherwise.

## ◆ SendMessageToAll()

bool core_lib::asio::tcp::TcpConnections::SendMessageToAll | ( | const defs::char_buffer_t & | message | ) | const

Send an asynchronous message to all connections.

Parameters

  [in] | message | - Message buffer to send.

Returns
  True if sent successfully, false otherwise.

## ◆ Size()

size_t core_lib::asio::tcp::TcpConnections::Size | ( |  | ) | const

Get the number of connections.

Returns
  Number of connections.

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

- D:/Projects/CoreLibrary/Include/Asio/TcpConnections.h
- D:/Projects/CoreLibrary/Source/Asio/TcpConnections.cpp