28 #ifndef TCPTYPEDSERVER 29 #define TCPTYPEDSERVER 84 size_t maxAllowedUnsentAsyncMessages = MAX_UNSENT_ASYNC_MSG_COUNT)
90 messageReceivedHandler,
92 maxAllowedUnsentAsyncMessages}
117 size_t maxAllowedUnsentAsyncMessages = MAX_UNSENT_ASYNC_MSG_COUNT)
121 checkBytesLeftToRead,
122 messageReceivedHandler,
124 maxAllowedUnsentAsyncMessages}
247 auto const& messageBuffer =
338 auto const& messageBuffer =
363 template <
typename T,
typename A = serialize::archives::out_port_bin_t>
372 auto const& messageBuffer =
373 messages::BuildMessage<T, A, MsgBldr>(message,
397 template <
typename T,
typename A = serialize::archives::out_port_bin_t>
406 auto const& messageBuffer =
407 messages::BuildMessage<T, A, MsgBldr>(message,
429 template <
typename T,
typename A = serialize::archives::out_port_bin_t>
438 auto const& messageBuffer = messages::BuildMessage<T, A, MsgBldr>(
541 #endif // TCPTYPEDCLIENT TcpTypedServer()=delete
Default constructor - deleted.
bool SendMessageToClientAsync(const defs::connection_t &client, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) const
Send a header-only message to a client asynchronously.
Definition: TcpTypedServer.h:187
bool SendMessageToClientSync(const T &message, const defs::connection_t &client, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) const
Send a full message to a client synchronously.
Definition: TcpTypedServer.h:399
bool SendMessageToClientSync(const defs::connection_t &client, const defs::char_buffer_t &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) const
Send a header plus message buffer to a client synchronously.
Definition: TcpTypedServer.h:302
const MsgBldr & m_messageBuilder
Referece to our message builder object.
Definition: TcpTypedServer.h:532
bool SendMessageToClientSync(const defs::connection_t &client, const defs::char_buffer_t &message) const
Send a message buffer to a client synchronously.
Definition: TcpServer.cpp:126
TcpServer m_tcpServer
General purpose TCP server object.
Definition: TcpTypedServer.h:534
void CloseAcceptor()
Manually close the acceptor.
Definition: TcpServer.cpp:97
std::function< size_t(const char_buffer_t &)> check_bytes_left_to_read_t
Typedef to bytes left to reading checking utility function object.
Definition: AsioDefines.h:288
bool SendMessageToAllClients(int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) const
Send a header-only message to all clients asynchronously.
Definition: TcpTypedServer.h:240
bool SendMessageToClientSync(const defs::connection_t &client, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) const
Send a header-only message to a client synchronously.
Definition: TcpTypedServer.h:215
bool SendMessageToClientAsync(const defs::connection_t &client, const defs::char_buffer_t &message) const
Send a message buffer to a client asynchronously.
Definition: TcpTypedServer.h:460
bool IsConnected(const defs::connection_t &client) const
Tells if a given client is currently connected to the server.
Definition: TcpTypedServer.h:523
bool SendMessageToClientSync(const defs::connection_t &client, const defs::char_buffer_t &message) const
Send a message buffer to a client synchronously.
Definition: TcpTypedServer.h:479
size_t NumberOfClients() const
Retrieve this server's number of clients.
Definition: TcpServer.cpp:92
std::function< void(const char_buffer_t &)> message_received_handler_t
Typedef to message received handler function object.
Definition: AsioDefines.h:290
void CloseAcceptor()
Manually close the acceptor.
Definition: TcpTypedServer.h:170
size_t NumberOfUnsentAsyncMessages(const defs::connection_t &client) const
Get number of unsent async messages.
Definition: TcpServer.cpp:137
bool SendMessageToAllClients(const defs::char_buffer_t &message) const
Send a message buffer to all clients asynchronously.
Definition: TcpServer.cpp:132
The core_lib namespace.
Definition: AsioDefines.h:59
bool SendMessageToClientAsync(const defs::connection_t &client, const defs::char_buffer_t &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) const
Send a header plus message buffer to a client asynchronously.
Definition: TcpTypedServer.h:270
eSendOption
Enumeration to control nagle algorithm.
Definition: AsioDefines.h:82
A generic bi-directional TCP server.
Definition: TcpTypedServer.h:56
defs::connection_t GetServerDetailsForClient(const defs::connection_t &client) const
Retrieve this server's connection details for a given client.
Definition: TcpServer.cpp:80
bool IsConnected(const defs::connection_t &client) const
Tells if a given client is currently connected to the server.
Definition: TcpServer.cpp:142
nagleOn - Send when possible.
std::pair< std::string, uint16_t > connection_t
Typedef describing a network connection as (address, port).
Definition: AsioDefines.h:152
bool SendMessageToAllClients(const defs::char_buffer_t &message) const
Send a message buffer to all clients asynchronously.
Definition: TcpTypedServer.h:496
TcpTypedServer(boost_iocontext_t &ioContext, uint16_t listenPort, size_t minAmountToRead, const defs::check_bytes_left_to_read_t &checkBytesLeftToRead, const defs::message_received_handler_t &messageReceivedHandler, const MsgBldr &messageBuilder, eSendOption sendOption=eSendOption::nagleOn, size_t maxAllowedUnsentAsyncMessages=MAX_UNSENT_ASYNC_MSG_COUNT)
Initialisation constructor.
Definition: TcpTypedServer.h:80
A bi-directional TCP server.
Definition: TcpServer.h:53
~TcpTypedServer()=default
Default destructor.
TcpTypedServer(uint16_t listenPort, size_t minAmountToRead, const defs::check_bytes_left_to_read_t &checkBytesLeftToRead, const defs::message_received_handler_t &messageReceivedHandler, const MsgBldr &messageBuilder, eSendOption sendOption=eSendOption::nagleOn, size_t maxAllowedUnsentAsyncMessages=MAX_UNSENT_ASYNC_MSG_COUNT)
Initialisation constructor.
Definition: TcpTypedServer.h:113
bool SendMessageToAllClients(int32_t messageId, const defs::char_buffer_t &message, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) const
Send a header plus message buffer to all clients asynchronously.
Definition: TcpTypedServer.h:331
boost_asio::io_context boost_iocontext_t
Boost IO context convenience typedef.
Definition: AsioDefines.h:46
void OpenAcceptor()
Manually open the acceptor.
Definition: TcpServer.cpp:108
TcpTypedServer & operator=(const TcpTypedServer &)=delete
Copy assignment operator - deleted.
size_t NumberOfUnsentAsyncMessages(const defs::connection_t &client) const
Get number of unsent async messages.
Definition: TcpTypedServer.h:513
std::mutex m_sendMutex
Send message mutex.
Definition: TcpTypedServer.h:530
File containing message utils declaration.
void OpenAcceptor()
Manually open the acceptor.
Definition: TcpTypedServer.h:175
size_t NumberOfClients() const
Retrieve this server's number of clients.
Definition: TcpTypedServer.h:162
uint16_t ListenPort() const
Retrieve this server's listen port.
Definition: TcpServer.cpp:87
defs::char_buffer_t const & BuildMessage(int32_t messageId, const defs::connection_t &responseAddress, const defs::connection_t &fallbackResponseAddress, const MsgBldr &messageBuilder)
Message builder wrapper function for header only messages.
Definition: MessageUtils.h:412
defs::connection_t GetServerDetailsForClient(const defs::connection_t &client) const
Retrieve this server's connection details for a given client.
Definition: TcpTypedServer.h:146
bool SendMessageToClientAsync(const T &message, const defs::connection_t &client, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) const
Send a full message to a client asynchronously.
Definition: TcpTypedServer.h:364
File containing TCP server class declaration.
uint16_t ListenPort() const
Retrieve this server's listen port.
Definition: TcpTypedServer.h:154
std::vector< char > char_buffer_t
Typedef to generic char buffer based on s std::vector<char>.
Definition: AsioDefines.h:239
bool SendMessageToClientAsync(const defs::connection_t &client, const defs::char_buffer_t &message) const
Send a message buffer to a client asynchronously.
Definition: TcpServer.cpp:120
const connection_t NULL_CONNECTION
Constant defining a null network connection as ("0.0.0.0", 0).
bool SendMessageToAllClients(const T &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION) const
Send a full message to all clients asynchronously.
Definition: TcpTypedServer.h:431