Privacy
An open-source, flexible 3D physical simulation framework
mars::utils::TCPConnection Class Reference

#include <Socket.h>

Public Member Functions

 TCPConnection ()
 
 ~TCPConnection ()
 
SocketError connectToTCPServer (const std::string &host, unsigned short port)
 Connects to a given server on the given port. More...
 
void close ()
 Closes the connection. More...
 
bool isConnected () const
 Queries whether there is an established connection. More...
 
SocketError sendAll (const std::string &data)
 Sends the entire string. More...
 
SocketError sendAll (const char *data, size_t len)
 Sends the entire string. More...
 
size_t send (const char *data, size_t len)
 Send the data buffer over the connection. More...
 
SocketError recvAll (char *data, size_t len)
 Receives exactly len bytes and stores them in data. More...
 
size_t recv (char *data, size_t max)
 Receive at most max bytes and store them in data This does not guarantee that actually max bytes are received. More...
 
SocketError sendBinary (const void *data, size_t len)
 Convenience function to send len bytes of binary data. More...
 
SocketError recvBinary (void *data, size_t len)
 Convenience function to receive len bytes of binary data. More...
 
void setBlocking (bool blocking)
 Not Implemented Yet. More...
 
bool isBlocking () const
 Not Implemented Yet. More...
 
void setTimeout (double timeout)
 Not Implemented Yet. More...
 
double getTimeout () const
 Not Implemented Yet. More...
 
SocketError sendInt32 (int32_t val)
 Convenience function to send a 32-bit signed integer in a endian aware manner. More...
 
SocketError recvInt32 (int32_t *val)
 Convenience function to receive a 32-bit signed integer in a endian aware manner. More...
 
SocketError sendUInt32 (uint32_t val)
 Convenience function to send a 32-bit unsigned integer in a endian aware manner. More...
 
SocketError recvUInt32 (uint32_t *val)
 Convenience function to receive a 32-bit unsigned integer in a endian aware manner. More...
 
SocketError sendFloat (float val)
 Convenience function to send a single precision float in a endian aware manner. More...
 
SocketError recvFloat (float *val)
 Convenience function to receive a single precision float in a endian aware manner. More...
 
SocketError sendDouble (double val)
 Convenience function to send a double precision float in a endian aware manner. More...
 
SocketError recvDouble (double *val)
 Convenience function to receive a double precision float in a endian aware manner. More...
 

Private Member Functions

 TCPConnection (const TCPConnection &other)
 
TCPConnectionoperator= (const TCPConnection &other)
 

Private Attributes

TCPBaseSockets
 

Friends

SocketError TCPServer::acceptConnection (TCPConnection *c) const
 

Detailed Description

Definition at line 131 of file Socket.h.

Constructor & Destructor Documentation

◆ TCPConnection() [1/2]

mars::utils::TCPConnection::TCPConnection ( )

Definition at line 184 of file Socket.cpp.

◆ ~TCPConnection()

mars::utils::TCPConnection::~TCPConnection ( )

Definition at line 188 of file Socket.cpp.

◆ TCPConnection() [2/2]

mars::utils::TCPConnection::TCPConnection ( const TCPConnection other)
private

Definition at line 297 of file Socket.cpp.

Member Function Documentation

◆ close()

void mars::utils::TCPConnection::close ( )

Closes the connection.

It is safe to call this even if there is no connection established.

Definition at line 208 of file Socket.cpp.

◆ connectToTCPServer()

SocketError mars::utils::TCPConnection::connectToTCPServer ( const std::string &  host,
unsigned short  port 
)

Connects to a given server on the given port.

Definition at line 195 of file Socket.cpp.

◆ getTimeout()

double mars::utils::TCPConnection::getTimeout ( ) const

Not Implemented Yet.

Definition at line 293 of file Socket.cpp.

◆ isBlocking()

bool mars::utils::TCPConnection::isBlocking ( ) const

Not Implemented Yet.

Definition at line 287 of file Socket.cpp.

◆ isConnected()

bool mars::utils::TCPConnection::isConnected ( ) const

Queries whether there is an established connection.

Definition at line 211 of file Socket.cpp.

◆ operator=()

TCPConnection & mars::utils::TCPConnection::operator= ( const TCPConnection other)
private

Definition at line 301 of file Socket.cpp.

◆ recv()

size_t mars::utils::TCPConnection::recv ( char *  data,
size_t  max 
)

Receive at most max bytes and store them in data This does not guarantee that actually max bytes are received.

Parameters
dataA pointer to a buffer that can hold at least max bytes.
maxThe maximum of bytes to receive before returning.
See also
send, recvAll, recvBinary

Definition at line 251 of file Socket.cpp.

◆ recvAll()

SocketError mars::utils::TCPConnection::recvAll ( char *  data,
size_t  len 
)

Receives exactly len bytes and stores them in data.

Under the hood this repeatedly calls recv until len bytes are received.

Parameters
dataA pointer to a buffer that can hold at least len bytes.
lenThe number of bytes to receive before returning.
See also
sendAll, recv, recvBinary

Definition at line 238 of file Socket.cpp.

◆ recvBinary()

SocketError mars::utils::TCPConnection::recvBinary ( void *  data,
size_t  len 
)

Convenience function to receive len bytes of binary data.

This will receive len bytes convert them from Network-Byte-Order to Host-Byte-Order and store them in the buffer pointed to by data.

See also
sendBinary, recv, recvAll

Definition at line 271 of file Socket.cpp.

◆ recvDouble()

SocketError mars::utils::TCPConnection::recvDouble ( double *  val)
inline

Convenience function to receive a double precision float in a endian aware manner.

See also
sendBinary, recvBinary, sendInt32, recvInt32, sendUInt32, recvUInt32, sendFloat, recvFloat, sendDouble, recvDouble

Definition at line 270 of file Socket.h.

◆ recvFloat()

SocketError mars::utils::TCPConnection::recvFloat ( float *  val)
inline

Convenience function to receive a single precision float in a endian aware manner.

See also
sendBinary, recvBinary, sendInt32, recvInt32, sendUInt32, recvUInt32, sendFloat, recvFloat, sendDouble, recvDouble

Definition at line 256 of file Socket.h.

◆ recvInt32()

SocketError mars::utils::TCPConnection::recvInt32 ( int32_t *  val)
inline

Convenience function to receive a 32-bit signed integer in a endian aware manner.

See also
sendBinary, recvBinary, sendInt32, recvInt32, sendUInt32, recvUInt32, sendFloat, recvFloat, sendDouble, recvDouble

Definition at line 228 of file Socket.h.

◆ recvUInt32()

SocketError mars::utils::TCPConnection::recvUInt32 ( uint32_t *  val)
inline

Convenience function to receive a 32-bit unsigned integer in a endian aware manner.

See also
sendBinary, recvBinary, sendInt32, recvInt32, sendUInt32, recvUInt32, sendFloat, recvFloat, sendDouble, recvDouble

Definition at line 242 of file Socket.h.

◆ send()

size_t mars::utils::TCPConnection::send ( const char *  data,
size_t  len 
)

Send the data buffer over the connection.

This does not guarantee that the entire data buffer is transferred.

Parameters
dataThe data buffer to be sent over the connection.
lenThe length of the data buffer.
Returns
The number of bytes actually trnsferred.
See also
recv, sendAll, sendBinary

Definition at line 231 of file Socket.cpp.

◆ sendAll() [1/2]

SocketError mars::utils::TCPConnection::sendAll ( const std::string &  data)

Sends the entire string.

Under the hood this repeatedly calls send until the entire string is transferred.

See also
recvAll, send, sendBinary

Definition at line 214 of file Socket.cpp.

◆ sendAll() [2/2]

SocketError mars::utils::TCPConnection::sendAll ( const char *  data,
size_t  len 
)

Sends the entire string.

Under the hood this repeatedly calls send until the entire string is transferred.

See also
recvAll, send, sendBinary

Definition at line 217 of file Socket.cpp.

◆ sendBinary()

SocketError mars::utils::TCPConnection::sendBinary ( const void *  data,
size_t  len 
)

Convenience function to send len bytes of binary data.

This will transmit the len bytes pointed to by data in Network-Byte-Order.

See also
recvBinary, send, sendAll

Definition at line 257 of file Socket.cpp.

◆ sendDouble()

SocketError mars::utils::TCPConnection::sendDouble ( double  val)
inline

Convenience function to send a double precision float in a endian aware manner.

See also
sendBinary, recvBinary, sendInt32, recvInt32, sendUInt32, recvUInt32, sendFloat, recvFloat, sendDouble, recvDouble

Definition at line 263 of file Socket.h.

◆ sendFloat()

SocketError mars::utils::TCPConnection::sendFloat ( float  val)
inline

Convenience function to send a single precision float in a endian aware manner.

See also
sendBinary, recvBinary, sendInt32, recvInt32, sendUInt32, recvUInt32, sendFloat, recvFloat, sendDouble, recvDouble

Definition at line 249 of file Socket.h.

◆ sendInt32()

SocketError mars::utils::TCPConnection::sendInt32 ( int32_t  val)
inline

Convenience function to send a 32-bit signed integer in a endian aware manner.

See also
sendBinary, recvBinary, sendInt32, recvInt32, sendUInt32, recvUInt32, sendFloat, recvFloat, sendDouble, recvDouble

Definition at line 221 of file Socket.h.

◆ sendUInt32()

SocketError mars::utils::TCPConnection::sendUInt32 ( uint32_t  val)
inline

Convenience function to send a 32-bit unsigned integer in a endian aware manner.

See also
sendBinary, recvBinary, sendInt32, recvInt32, sendUInt32, recvUInt32, sendFloat, recvFloat, sendDouble, recvDouble

Definition at line 235 of file Socket.h.

◆ setBlocking()

void mars::utils::TCPConnection::setBlocking ( bool  blocking)

Not Implemented Yet.

Definition at line 285 of file Socket.cpp.

◆ setTimeout()

void mars::utils::TCPConnection::setTimeout ( double  timeout)

Not Implemented Yet.

Definition at line 290 of file Socket.cpp.

Friends And Related Function Documentation

◆ TCPServer::acceptConnection

Member Data Documentation

◆ s

TCPBaseSocket* mars::utils::TCPConnection::s
private

Definition at line 277 of file Socket.h.


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