YARP
Yet Another Robot Platform
yarp::os::impl::SocketTwoWayStream Class Reference

A stream abstraction for socket communication. More...

#include <yarp/os/impl/SocketTwoWayStream.h>

+ Inheritance diagram for yarp::os::impl::SocketTwoWayStream:

Public Member Functions

 SocketTwoWayStream ()
 
int open (const Contact &address)
 
int open (yarp::os::impl::TcpAcceptor &acceptor)
 
 ~SocketTwoWayStream () override
 
InputStreamgetInputStream () override
 Get an InputStream to read from. More...
 
OutputStreamgetOutputStream () override
 Get an OutputStream to write to. More...
 
const ContactgetLocalAddress () const override
 Get the address of the local side of the stream. More...
 
const ContactgetRemoteAddress () const override
 Get the address of the remote side of the stream. More...
 
void interrupt () override
 Interrupt the stream. More...
 
void close () override
 Terminate the stream. More...
 
yarp::conf::ssize_t read (Bytes &b) override
 Read a block of data from the stream. More...
 
yarp::conf::ssize_t partialRead (Bytes &b) override
 Like read, but solicit partial responses. More...
 
void write (const Bytes &b) override
 Write a block of bytes to the stream. More...
 
void flush () override
 Make sure all pending write operations are finished. More...
 
bool isOk () const override
 Check if the stream is ok or in an error state. More...
 
void reset () override
 Reset the stream. More...
 
void beginPacket () override
 Mark the beginning of a logical packet. More...
 
void endPacket () override
 Mark the end of a logical packet (see beginPacket). More...
 
bool setWriteTimeout (double timeout) override
 Set activity timeout. More...
 
bool setReadTimeout (double timeout) override
 Set activity timeout. More...
 
bool setTypeOfService (int tos) override
 
int getTypeOfService () override
 
- Public Member Functions inherited from yarp::os::TwoWayStream
virtual ~TwoWayStream ()
 Destructor. More...
 
- Public Member Functions inherited from yarp::os::InputStream
 InputStream ()
 Constructor. More...
 
virtual ~InputStream ()
 Destructor. More...
 
virtual void check ()
 Perform maintenance actions, if needed. More...
 
virtual int read ()
 Read and return a single byte. More...
 
virtual yarp::conf::ssize_t read (Bytes &b, size_t offset, yarp::conf::ssize_t len)
 Read a block of data from the stream. More...
 
std::string readLine (const char terminal='\n', bool *success=nullptr)
 Read a block of text terminated with a specific marker (or EOF). More...
 
yarp::conf::ssize_t readFull (Bytes &b)
 Keep reading until buffer is full. More...
 
yarp::conf::ssize_t readDiscard (size_t len)
 Read and discard a fixed number of bytes. More...
 
virtual bool setReadEnvelopeCallback (readEnvelopeCallbackType callback, void *data)
 Install a callback that the InputStream will have to call when the envelope is read from a message in carriers that cannot be escaped. More...
 
- Public Member Functions inherited from yarp::os::OutputStream
virtual ~OutputStream ()
 Destructor. More...
 
virtual void write (char ch)
 Write a single byte to the stream. More...
 
virtual void write (const Bytes &b, int offset, int len)
 Write a block of bytes to the stream. More...
 
virtual void writeLine (const char *data, int len)
 Write some text followed by a line feed. More...
 

Additional Inherited Members

- Public Types inherited from yarp::os::InputStream
typedef void(* readEnvelopeCallbackType) (void *, const yarp::os::Bytes &envelope)
 Callback type for setting the envelope from a message in carriers that cannot be escaped. More...
 

Detailed Description

A stream abstraction for socket communication.

It supports TCP.

Definition at line 36 of file SocketTwoWayStream.h.

Constructor & Destructor Documentation

◆ SocketTwoWayStream()

yarp::os::impl::SocketTwoWayStream::SocketTwoWayStream ( )
inline

Definition at line 42 of file SocketTwoWayStream.h.

◆ ~SocketTwoWayStream()

yarp::os::impl::SocketTwoWayStream::~SocketTwoWayStream ( )
inlineoverride

Definition at line 53 of file SocketTwoWayStream.h.

Member Function Documentation

◆ beginPacket()

void yarp::os::impl::SocketTwoWayStream::beginPacket ( )
inlineoverridevirtual

Mark the beginning of a logical packet.

This is a unit that should be treated in an atomic fashion by YARP. If any part is corrupted, the whole should be dropped.

Implements yarp::os::TwoWayStream.

Definition at line 185 of file SocketTwoWayStream.h.

◆ close()

void yarp::os::impl::SocketTwoWayStream::close ( )
inlineoverridevirtual

Terminate the stream.

Implements yarp::os::InputStream.

Definition at line 92 of file SocketTwoWayStream.h.

◆ endPacket()

void yarp::os::impl::SocketTwoWayStream::endPacket ( )
inlineoverridevirtual

Mark the end of a logical packet (see beginPacket).

Implements yarp::os::TwoWayStream.

Definition at line 194 of file SocketTwoWayStream.h.

◆ flush()

void yarp::os::impl::SocketTwoWayStream::flush ( )
inlineoverridevirtual

Make sure all pending write operations are finished.

Reimplemented from yarp::os::OutputStream.

Definition at line 159 of file SocketTwoWayStream.h.

◆ getInputStream()

InputStream& yarp::os::impl::SocketTwoWayStream::getInputStream ( )
inlineoverridevirtual

Get an InputStream to read from.

Returns
the InputStream associated with this object.

Implements yarp::os::TwoWayStream.

Definition at line 58 of file SocketTwoWayStream.h.

◆ getLocalAddress()

const Contact& yarp::os::impl::SocketTwoWayStream::getLocalAddress ( ) const
inlineoverridevirtual

Get the address of the local side of the stream.

Returns
the address of the local side of the stream. The address will be tagged as invalid if the stream is not set up.

Implements yarp::os::TwoWayStream.

Definition at line 68 of file SocketTwoWayStream.h.

◆ getOutputStream()

OutputStream& yarp::os::impl::SocketTwoWayStream::getOutputStream ( )
inlineoverridevirtual

Get an OutputStream to write to.

Returns
the InputStream associated with this object.

Implements yarp::os::TwoWayStream.

Definition at line 63 of file SocketTwoWayStream.h.

◆ getRemoteAddress()

const Contact& yarp::os::impl::SocketTwoWayStream::getRemoteAddress ( ) const
inlineoverridevirtual

Get the address of the remote side of the stream.

Returns
the address of the remote side of the stream. The address will be tagged as invalid if the stream is not set up.

Implements yarp::os::TwoWayStream.

Definition at line 73 of file SocketTwoWayStream.h.

◆ getTypeOfService()

int SocketTwoWayStream::getTypeOfService ( )
overridevirtual

Reimplemented from yarp::os::OutputStream.

Definition at line 151 of file SocketTwoWayStream.cpp.

◆ interrupt()

void yarp::os::impl::SocketTwoWayStream::interrupt ( )
inlineoverridevirtual

Interrupt the stream.

If the stream is currently in a blocked state, it must be unblocked.

Reimplemented from yarp::os::InputStream.

Definition at line 78 of file SocketTwoWayStream.h.

◆ isOk()

bool yarp::os::impl::SocketTwoWayStream::isOk ( ) const
inlineoverridevirtual

Check if the stream is ok or in an error state.

Returns
true iff the stream is ok

Implements yarp::os::InputStream.

Definition at line 176 of file SocketTwoWayStream.h.

◆ open() [1/2]

int SocketTwoWayStream::open ( const Contact address)

Definition at line 32 of file SocketTwoWayStream.cpp.

◆ open() [2/2]

int SocketTwoWayStream::open ( yarp::os::impl::TcpAcceptor &  acceptor)

Definition at line 78 of file SocketTwoWayStream.cpp.

◆ partialRead()

yarp::conf::ssize_t yarp::os::impl::SocketTwoWayStream::partialRead ( Bytes b)
inlineoverridevirtual

Like read, but solicit partial responses.

Reimplemented from yarp::os::InputStream.

Definition at line 120 of file SocketTwoWayStream.h.

◆ read()

yarp::conf::ssize_t yarp::os::impl::SocketTwoWayStream::read ( Bytes b)
inlineoverridevirtual

Read a block of data from the stream.

Should block and wait for data.

Parameters
b[out]the block of data to read to
Returns
the number of bytes read, or -1 upon error

Implements yarp::os::InputStream.

Definition at line 99 of file SocketTwoWayStream.h.

◆ reset()

void yarp::os::impl::SocketTwoWayStream::reset ( )
inlineoverridevirtual

Reset the stream.

Implements yarp::os::TwoWayStream.

Definition at line 181 of file SocketTwoWayStream.h.

◆ setReadTimeout()

bool yarp::os::impl::SocketTwoWayStream::setReadTimeout ( double  timeout)
inlineoverridevirtual

Set activity timeout.

Support for this is optional. 0 = wait forever.

Returns
true iff timeout is supported.

Reimplemented from yarp::os::InputStream.

Definition at line 214 of file SocketTwoWayStream.h.

◆ setTypeOfService()

bool SocketTwoWayStream::setTypeOfService ( int  tos)
overridevirtual

Reimplemented from yarp::os::OutputStream.

Definition at line 145 of file SocketTwoWayStream.cpp.

◆ setWriteTimeout()

bool yarp::os::impl::SocketTwoWayStream::setWriteTimeout ( double  timeout)
inlineoverridevirtual

Set activity timeout.

Support for this is optional. 0 = wait forever.

Returns
true iff timeout is supported.

Reimplemented from yarp::os::OutputStream.

Definition at line 203 of file SocketTwoWayStream.h.

◆ write()

void yarp::os::impl::SocketTwoWayStream::write ( const Bytes b)
inlineoverridevirtual

Write a block of bytes to the stream.

Parameters
bthe bytes to write

Implements yarp::os::OutputStream.

Definition at line 142 of file SocketTwoWayStream.h.


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