28 #ifndef TCPTYPEDCLIENT 29 #define TCPTYPEDCLIENT 83 size_t minAmountToRead,
87 size_t maxAllowedUnsentAsyncMessages = MAX_UNSENT_ASYNC_MSG_COUNT)
93 messageReceivedHandler,
95 maxAllowedUnsentAsyncMessages}
120 size_t maxAllowedUnsentAsyncMessages = MAX_UNSENT_ASYNC_MSG_COUNT)
124 checkBytesLeftToRead,
125 messageReceivedHandler,
127 maxAllowedUnsentAsyncMessages}
282 template <
typename T,
typename A = serialize::archives::out_port_bin_t>
290 auto const& messageBuffer = messages::BuildMessage<T, A, MsgBldr>(
310 template <
typename T,
typename A = serialize::archives::out_port_bin_t>
318 auto const& messageBuffer = messages::BuildMessage<T, A, MsgBldr>(
382 #endif // TCPTYPEDCLIENT A bi-directional TCP client.
Definition: TcpClient.h:52
bool SendMessageToServerAsync(int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
Send a header-only message to the server asynchronously.
Definition: TcpTypedClient.h:182
size_t NumberOfUnsentAsyncMessages() const
Get number of unsent async messages.
Definition: TcpTypedClient.h:364
~TcpTypedClient()=default
Default destructor.
size_t NumberOfUnsentAsyncMessages() const
Get number of unsent async messages.
Definition: TcpClient.cpp:117
void CloseConnection()
Manually close the connection.
Definition: TcpTypedClient.h:171
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
File containing TCP client class declaration.
bool SendMessageToServerAsync(const defs::char_buffer_t &message)
Send a message buffer to the server asynchronously.
Definition: TcpClient.cpp:97
std::function< void(const char_buffer_t &)> message_received_handler_t
Typedef to message received handler function object.
Definition: AsioDefines.h:290
defs::connection_t ServerConnection() const
Retrieve server connection details.
Definition: TcpTypedClient.h:144
bool CheckAndCreateConnection()
Check connection and create if required.
Definition: TcpClient.cpp:146
bool SendMessageToServerSync(int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
Send a header-only message to the server synchronously.
Definition: TcpTypedClient.h:207
bool SendMessageToServerSync(const defs::char_buffer_t &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
Send a header plus message buffer to the server synchronously.
Definition: TcpTypedClient.h:257
The core_lib namespace.
Definition: AsioDefines.h:59
A generic bi-directional TCP client.
Definition: TcpTypedClient.h:57
bool Connected() const
Check if the client is connected to the server.
Definition: TcpTypedClient.h:152
eSendOption
Enumeration to control nagle algorithm.
Definition: AsioDefines.h:82
bool SendMessageToServerSync(const T &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
Send a full message to the server synchronously.
Definition: TcpTypedClient.h:311
bool SendMessageToServerSync(const defs::char_buffer_t &message)
Send a message buffer to the server synchronously.
Definition: TcpClient.cpp:107
bool SendMessageToServerSync(const defs::char_buffer_t &message)
Send a message buffer to the server synchronously.
Definition: TcpTypedClient.h:349
nagleOn - Send when possible.
defs::connection_t GetClientDetailsForServer()
Retrieve this client's connection details.
Definition: TcpTypedClient.h:162
std::pair< std::string, uint16_t > connection_t
Typedef describing a network connection as (address, port).
Definition: AsioDefines.h:152
TcpTypedClient & operator=(const TcpTypedClient &)=delete
Copy assignment operator - deleted.
bool Connected() const
Check if the client is connected to the server.
Definition: TcpClient.cpp:82
bool SendMessageToServerAsync(const defs::char_buffer_t &message)
Send a message buffer to the server asynchronously.
Definition: TcpTypedClient.h:332
TcpClient m_tcpClient
General purpose TCP client object.
Definition: TcpTypedClient.h:375
void CloseConnection()
Manually close the connection.
Definition: TcpClient.cpp:92
boost_asio::io_context boost_iocontext_t
Boost IO context convenience typedef.
Definition: AsioDefines.h:46
bool SendMessageToServerAsync(const T &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
Send a full message to the server asynchronously.
Definition: TcpTypedClient.h:283
std::mutex m_sendMutex
Send message mutex.
Definition: TcpTypedClient.h:371
defs::connection_t ServerConnection() const
Retrieve server connection details.
Definition: TcpClient.cpp:77
bool SendMessageToServerAsync(const defs::char_buffer_t &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
Send a header plus message buffer to the server asynchronously.
Definition: TcpTypedClient.h:231
File containing message utils declaration.
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
TcpTypedClient()=delete
Default constructor - deleted.
std::vector< char > char_buffer_t
Typedef to generic char buffer based on s std::vector<char>.
Definition: AsioDefines.h:239
TcpTypedClient(boost_iocontext_t &ioContext, const defs::connection_t &server, 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: TcpTypedClient.h:82
defs::connection_t GetClientDetailsForServer() const
Retrieve this client's connection details.
Definition: TcpClient.cpp:87
const connection_t NULL_CONNECTION
Constant defining a null network connection as ("0.0.0.0", 0).
TcpTypedClient(const defs::connection_t &server, 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: TcpTypedClient.h:116
const MsgBldr & m_messageBuilder
Referece to our message builder object.
Definition: TcpTypedClient.h:373