Public Types | Public Member Functions | Private Attributes | List of all members
visionary::TcpSocket Class Reference

#include <TcpSocket.h>

Inheritance diagram for visionary::TcpSocket:
Inheritance graph
[legend]

Public Types

using ByteBuffer = std::vector< std::uint8_t >
 
- Public Types inherited from visionary::ITransport
using ByteBuffer = std::vector< std::uint8_t >
 
using recv_return_t = ssize_t
 
using send_return_t = ssize_t
 

Public Member Functions

int connect (const std::string &ipaddr, std::uint16_t port, std::uint32_t timeoutMs=5000)
 
int getLastError () override
 
recv_return_t read (ByteBuffer &buffer, std::size_t nBytesToReceive) override
 
recv_return_t recv (ByteBuffer &buffer, std::size_t maxBytesToReceive) override
 
send_return_t send (const char *pData, size_t size) override
 
virtual send_return_t send (const char *pData, size_t size)=0
 
template<typename T >
send_return_t send (const std::vector< T > &buffer)
 
int shutdown () override
 
 TcpSocket ()
 
virtual ~TcpSocket ()
 
- Public Member Functions inherited from visionary::ITransport
template<typename T >
send_return_t send (const std::vector< T > &buffer)
 
virtual ~ITransport ()=default
 

Private Attributes

std::unique_ptr< SockRecordm_pSockRecord
 

Additional Inherited Members

Detailed Description

Definition at line 19 of file TcpSocket.h.

Member Typedef Documentation

◆ ByteBuffer

using visionary::TcpSocket::ByteBuffer = std::vector<std::uint8_t>

Definition at line 22 of file TcpSocket.h.

Constructor & Destructor Documentation

◆ TcpSocket()

visionary::TcpSocket::TcpSocket ( )

Definition at line 24 of file TcpSocket.cpp.

◆ ~TcpSocket()

visionary::TcpSocket::~TcpSocket ( )
virtual

Definition at line 28 of file TcpSocket.cpp.

Member Function Documentation

◆ connect()

int visionary::TcpSocket::connect ( const std::string &  ipaddr,
std::uint16_t  port,
std::uint32_t  timeoutMs = 5000 
)

connect to a peer via TCP

Parameters
[in]ipaddrstring representation of the device ip address ("xx.xx.xx.xx")
[in]portnumber of the device port to connect to (in host byte order)
Return values
0connect successful
-1connect failed (the socket could be created, the ip address format is invalid or the device cannot be contacted)

Definition at line 36 of file TcpSocket.cpp.

◆ getLastError()

int visionary::TcpSocket::getLastError ( )
overridevirtual

Implements visionary::ITransport.

Definition at line 301 of file TcpSocket.cpp.

◆ read()

ITransport::recv_return_t visionary::TcpSocket::read ( ByteBuffer buffer,
std::size_t  nBytesToReceive 
)
overridevirtual

Read a number of bytes

Contrary to recv this method reads precisely nBytesToReceive bytes.

Parameters
[in]bufferbuffer containing the bytes that shall be sent.
[in]nBytesToReceivemaximum number of bytes to receive.
Returns
number of received bytes or (-1) on error

Implements visionary::ITransport.

Definition at line 255 of file TcpSocket.cpp.

◆ recv()

ITransport::recv_return_t visionary::TcpSocket::recv ( ByteBuffer buffer,
std::size_t  maxBytesToReceive 
)
overridevirtual

Receive data on socket to device

Receive at most maxBytesToReceive bytes.

Parameters
[in]bufferbuffer containing the bytes that shall be sent.
[in]maxBytesToReceivemaximum number of bytes to receive.
Returns
number of received bytes or (-1) on error

Implements visionary::ITransport.

Definition at line 237 of file TcpSocket.cpp.

◆ send() [1/3]

ITransport::send_return_t visionary::TcpSocket::send ( const char *  pData,
size_t  size 
)
overridevirtual

Implements visionary::ITransport.

Definition at line 230 of file TcpSocket.cpp.

◆ send() [2/3]

virtual send_return_t visionary::ITransport::send

◆ send() [3/3]

template<typename T >
send_return_t visionary::ITransport::send ( typename T  )
inline

Send data on socket to device

All bytes are sent on the socket. It is regarded as error if this is not possible.

Parameters
[in]bufferbuffer containing the bytes that shall be sent.
Returns
Number of bytes sent or (-1) on error

Definition at line 45 of file ITransport.h.

◆ shutdown()

int visionary::TcpSocket::shutdown ( )
overridevirtual

Implements visionary::ITransport.

Definition at line 217 of file TcpSocket.cpp.

Member Data Documentation

◆ m_pSockRecord

std::unique_ptr<SockRecord> visionary::TcpSocket::m_pSockRecord
private

Definition at line 44 of file TcpSocket.h.


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


sick_visionary_ros
Author(s): SICK AG TechSupport 3D Snapshot
autogenerated on Thu Feb 8 2024 04:38:18