rohdeschwarz  0.2.0
TCPIP socket library for Rohde & Schwarz instrument control
Public Member Functions | List of all members
rohdeschwarz::busses::socket::Socket Class Reference

A class for managing synchronous TCP IP sockets. More...

#include <socket.hpp>

Inheritance diagram for rohdeschwarz::busses::socket::Socket:
rohdeschwarz::busses::Bus

Public Member Functions

 Socket (const char *host, int port=5025)
 Constructor. More...
 
 Socket (const std::string &host, int port=5025)
 Constructor. More...
 
virtual ~Socket ()
 Destructor. More...
 
std::string host () const
 returns the host or ip address More...
 
int port () const
 returns the port More...
 
virtual std::string endpoint () const
 Returns string '{host}:{port}'. More...
 
virtual int timeout_ms () const
 Get timeout, in ms. More...
 
virtual bool setTimeout (int timeout_ms)
 Set timeout, in ms. More...
 
virtual bool readData (unsigned char *buffer, std::size_t bufferSize, std::size_t *readSize=nullptr)
 read data into buffer More...
 
virtual bool writeData (const unsigned char *data, std::size_t dataSize, std::size_t *writeSize=nullptr)
 read data into buffer More...
 
virtual bool isError () const
 Checks socket state for error. More...
 
virtual std::string statusMessage () const
 human-readable bus status message More...
 
- Public Member Functions inherited from rohdeschwarz::busses::Bus
 Bus ()
 Constructor. More...
 
virtual ~Bus ()
 Destructor. More...
 
std::size_t bufferSize_B () const
 
void setBufferSize (std::size_t bytes)
 
std::vector< unsigned char > * buffer ()
 
const std::vector< unsigned char > * buffer () const
 
std::vector< unsigned char > takeData ()
 
bool readData (std::size_t *readSize=nullptr)
 

Detailed Description

A class for managing synchronous TCP IP sockets.

Definition at line 38 of file socket.hpp.

Constructor & Destructor Documentation

◆ Socket() [1/2]

Socket::Socket ( const char *  host,
int  port = 5025 
)

Constructor.

Constructs a socket object that is connected to server host, port

Parameters
[in]hosthost or ip address
[in]portport number
Returns
An object with an open socket
Exceptions
<tt>boost::system::system_error</tt>if connection fails

Definition at line 29 of file socket.cpp.

◆ Socket() [2/2]

Socket::Socket ( const std::string &  host,
int  port = 5025 
)

Constructor.

Constructs a socket object that is connected to server host, port

Parameters
[in]hosthost or ip address
[in]portport number
Returns
An object with an open socket
Exceptions
<tt>boost::system::system_error</tt>if connection fails

Definition at line 39 of file socket.cpp.

◆ ~Socket()

Socket::~Socket ( )
virtual

Destructor.

The destructor closes the socket if it is currently open

Definition at line 49 of file socket.cpp.

Member Function Documentation

◆ endpoint()

std::string Socket::endpoint ( ) const
virtual

Returns string '{host}:{port}'.

Implements rohdeschwarz::busses::Bus.

Definition at line 67 of file socket.cpp.

◆ host()

std::string Socket::host ( ) const

returns the host or ip address

Definition at line 55 of file socket.cpp.

◆ isError()

bool Socket::isError ( ) const
virtual

Checks socket state for error.

Returns
true if the connection is open; otherwise false otherwise.

Implements rohdeschwarz::busses::Bus.

Definition at line 175 of file socket.cpp.

◆ port()

int Socket::port ( ) const

returns the port

Definition at line 61 of file socket.cpp.

◆ readData()

bool Socket::readData ( unsigned char *  buffer,
std::size_t  bufferSize,
std::size_t *  readSize = nullptr 
)
virtual

read data into buffer

Parameters
[in]bufferBuffer for read
[in]bufferSizeSize of buffer
[out]readSizeReturns bytes read
Returns
true if read succeeded; false otherwise

Implements rohdeschwarz::busses::Bus.

Definition at line 119 of file socket.cpp.

◆ setTimeout()

bool Socket::setTimeout ( int  timeout_ms)
virtual

Set timeout, in ms.

Implements rohdeschwarz::busses::Bus.

Definition at line 90 of file socket.cpp.

◆ statusMessage()

std::string Socket::statusMessage ( ) const
virtual

human-readable bus status message

Returns
"connection is open" if connected; "warning: connection is closed" otherwise.

Implements rohdeschwarz::busses::Bus.

Definition at line 181 of file socket.cpp.

◆ timeout_ms()

int Socket::timeout_ms ( ) const
virtual

Get timeout, in ms.

Implements rohdeschwarz::busses::Bus.

Definition at line 75 of file socket.cpp.

◆ writeData()

bool Socket::writeData ( const unsigned char *  data,
std::size_t  dataSize,
std::size_t *  writeSize = nullptr 
)
virtual

read data into buffer

Parameters
[in]dataData to be written
[in]dataSizeSize of data to be written
[out]writeSizeReturns bytes written
Returns
true if write succeeded; false otherwise

Implements rohdeschwarz::busses::Bus.

Definition at line 147 of file socket.cpp.


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