helics  3.0.1
Public Types | Public Member Functions | Static Public Member Functions | List of all members
helics::tcp::TcpConnection Class Reference

#include <TcpHelperClasses.h>

+ Inheritance diagram for helics::tcp::TcpConnection:

Public Types

enum  connection_state_t {
  prestart = -1, waiting = 0, operating = 1, halted = 3,
  closed = 4
}
 
using pointer = std::shared_ptr< TcpConnection >
 

Public Member Functions

auto & socket ()
 
void startReceive ()
 
void cancel ()
 
void close ()
 
void closeNoWait ()
 
void waitOnClose ()
 
bool isReceiving () const
 
void setDataCall (std::function< size_t(TcpConnection::pointer, const char *, size_t)> dataFunc)
 
void setErrorCall (std::function< bool(TcpConnection::pointer, const std::error_code &)> errorFunc)
 
void setLoggingFunction (std::function< void(int loglevel, const std::string &logMessage)> logFunc)
 
size_t send (const void *buffer, size_t dataLength)
 
size_t send (const std::string &dataString)
 
size_t receive (void *buffer, size_t maxDataSize)
 
template<typename Process >
void send_async (const void *buffer, size_t dataLength, Process callback)
 
template<typename Process >
void async_receive (void *buffer, size_t dataLength, Process callback)
 
void async_receive (std::function< void(TcpConnection::pointer, const char *buffer, size_t dataLength, const std::error_code &error)> callback)
 
bool isConnected () const
 
bool waitUntilConnected (std::chrono::milliseconds timeOut)
 
int getIdentifier () const
 

Static Public Member Functions

static pointer create (asio::io_context &io_context, const std::string &connection, const std::string &port, size_t bufferSize=10192)
 
static pointer create (asio::io_context &io_context, size_t bufferSize)
 

Detailed Description

tcp socket generation for a receiving server

Member Enumeration Documentation

◆ connection_state_t

enum helics::tcp::TcpConnection::connection_state_t
strong

enumeration of the possible states of a connection

Member Function Documentation

◆ async_receive() [1/2]

void helics::tcp::TcpConnection::async_receive ( std::function< void(TcpConnection::pointer, const char *buffer, size_t dataLength, const std::error_code &error)>  callback)
inline

perform an asynchronous receive operation

Parameters
callbackthe callback function to execute when data has been received with signature void(TcpConnection::pointer, const char *buffer, size_t dataLength, const std::error_code &error)

◆ async_receive() [2/2]

template<typename Process >
void helics::tcp::TcpConnection::async_receive ( void *  buffer,
size_t  dataLength,
Process  callback 
)
inline

perform an asynchronous receive operation

Parameters
bufferthe data to send
dataLengththe length of the data
callbacka callback function of the form void handler( const std::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );

◆ cancel()

void helics::tcp::TcpConnection::cancel ( )
inline

cancel ongoing socket operations

◆ close()

void helics::tcp::TcpConnection::close ( )

close the socket

◆ closeNoWait()

void helics::tcp::TcpConnection::closeNoWait ( )

perform the close actions but don't wait for them to be processed

◆ create()

static pointer helics::tcp::TcpConnection::create ( asio::io_context &  io_context,
size_t  bufferSize 
)
inlinestatic

create an RxConnection object using the specified context and bufferSize

◆ getIdentifier()

int helics::tcp::TcpConnection::getIdentifier ( ) const
inline

get the id code for the socket

◆ isConnected()

bool helics::tcp::TcpConnection::isConnected ( ) const
inline

check if the socket has finished the connection process

Referenced by send(), and waitUntilConnected().

◆ isReceiving()

bool helics::tcp::TcpConnection::isReceiving ( ) const
inline

check if the connection is receiving data

◆ receive()

size_t helics::tcp::TcpConnection::receive ( void *  buffer,
size_t  maxDataSize 
)

do a blocking receive on the socket

Exceptions
std::system_erroron failure
Returns
the number of bytes received

◆ send() [1/2]

size_t helics::tcp::TcpConnection::send ( const std::string &  dataString)

send a string

Exceptions
std::system_erroron failure

References send().

◆ send() [2/2]

size_t helics::tcp::TcpConnection::send ( const void *  buffer,
size_t  dataLength 
)

send raw data

Exceptions
std::system_erroron failure

References isConnected(), and waitUntilConnected().

Referenced by send().

◆ send_async()

template<typename Process >
void helics::tcp::TcpConnection::send_async ( const void *  buffer,
size_t  dataLength,
Process  callback 
)
inline

perform an asynchronous send operation

Parameters
bufferthe data to send
dataLengththe length of the data
callbacka callback function of the form void handler( const std::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );

◆ setDataCall()

void helics::tcp::TcpConnection::setDataCall ( std::function< size_t(TcpConnection::pointer, const char *, size_t)>  dataFunc)

set the callback for the data object

◆ setErrorCall()

void helics::tcp::TcpConnection::setErrorCall ( std::function< bool(TcpConnection::pointer, const std::error_code &)>  errorFunc)

set the callback for an error

◆ setLoggingFunction()

void helics::tcp::TcpConnection::setLoggingFunction ( std::function< void(int loglevel, const std::string &logMessage)>  logFunc)

set a logging function

◆ socket()

auto& helics::tcp::TcpConnection::socket ( )
inline

get the underlying socket object

◆ startReceive()

void helics::tcp::TcpConnection::startReceive ( )

start the receiving loop

◆ waitOnClose()

void helics::tcp::TcpConnection::waitOnClose ( )

wait on the closing actions

◆ waitUntilConnected()

bool helics::tcp::TcpConnection::waitUntilConnected ( std::chrono::milliseconds  timeOut)

wait until the socket has finished the connection process

Parameters
timeOutthe number of ms to wait for the connection process to finish (<0) for no limit
Returns
true if connected, false if the timeout was reached

References isConnected().

Referenced by send().


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