7#ifndef YARP_OS_IMPL_SOCKETTWOWAYSTREAM_H
8#define YARP_OS_IMPL_SOCKETTWOWAYSTREAM_H
20# include <ace/os_include/netinet/os_tcp.h>
26# include <netinet/tcp.h>
43 haveWriteTimeout(
false),
44 haveReadTimeout(
false),
49 int open(
const Contact& address);
51 int open(yarp::os::impl::TcpAcceptor&
acceptor);
83 stream.close_reader();
85 stream.close_writer();
105 if (haveReadTimeout) {
106 result = stream.recv_n(b.
get(), b.
length(), &readTimeout);
108 result = stream.recv_n(b.
get(), b.
length());
126 if (haveReadTimeout) {
127 result = stream.recv(b.
get(), b.
length(), &readTimeout);
129 result = stream.recv(b.
get(), b.
length());
148 if (haveWriteTimeout) {
149 result = stream.send_n(b.
get(), b.
length(), &writeTimeout);
151 result = stream.send_n(b.
get(), b.
length());
205 if (timeout < 1
e-12) {
206 haveWriteTimeout =
false;
209 haveWriteTimeout =
true;
216 if (timeout < 1
e-12) {
217 haveReadTimeout =
false;
220 haveReadTimeout =
true;
225 bool setTypeOfService(
int tos)
override;
226 int getTypeOfService()
override;
229 yarp::os::impl::TcpStream stream;
230 bool haveWriteTimeout;
231 bool haveReadTimeout;
234 Contact localAddress, remoteAddress;
236 void updateAddresses();
const yarp::os::LogComponent & SOCKETTWOWAYSTREAM()
const yarp::os::LogComponent & SOCKETTWOWAYSTREAM()
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
A simple abstraction for a block of bytes.
Simple specification of the minimum functions needed from output streams.
virtual void write(char ch)
Write a single byte to the stream.
A stream which can be asked to perform bidirectional communication.
A stream abstraction for socket communication.
void endPacket() override
Mark the end of a logical packet (see beginPacket).
bool isOk() const override
Check if the stream is ok or in an error state.
void beginPacket() override
Mark the beginning of a logical packet.
yarp::conf::ssize_t read(Bytes &b) override
Read a block of data from the stream.
bool setWriteTimeout(double timeout) override
Set activity timeout.
~SocketTwoWayStream() override
yarp::conf::ssize_t partialRead(Bytes &b) override
Like read, but solicit partial responses.
bool setReadTimeout(double timeout) override
Set activity timeout.
InputStream & getInputStream() override
Get an InputStream to read from.
const Contact & getLocalAddress() const override
Get the address of the local side of the stream.
void close() override
Terminate the stream.
void flush() override
Make sure all pending write operations are finished.
void interrupt() override
Interrupt the stream.
void write(const Bytes &b) override
Write a block of bytes to the stream.
void reset() override
Reset the stream.
const Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
OutputStream & getOutputStream() override
Get an OutputStream to write to.
#define YARP_DECLARE_LOG_COMPONENT(name)
#define yCDebug(component,...)
The components from which ports and connections are built.