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>
45 haveWriteTimeout(false),
46 haveReadTimeout(false),
51 int open(
const Contact& address);
53 int open(yarp::os::impl::TcpAcceptor& acceptor);
85 stream.close_reader();
87 stream.close_writer();
107 if (haveReadTimeout) {
108 result = stream.recv_n(b.
get(), b.
length(), &readTimeout);
110 result = stream.recv_n(b.
get(), b.
length());
128 if (haveReadTimeout) {
129 result = stream.recv(b.
get(), b.
length(), &readTimeout);
131 result = stream.recv(b.
get(), b.
length());
150 if (haveWriteTimeout) {
151 result = stream.send_n(b.
get(), b.
length(), &writeTimeout);
153 result = stream.send_n(b.
get(), b.
length());
165 int sizeInt =
sizeof(int);
166 stream.get_option(IPPROTO_TCP, TCP_CORK, &status, &sizeInt);
170 stream.set_option(IPPROTO_TCP, TCP_CORK, &zero,
sizeof(
int));
173 stream.set_option(IPPROTO_TCP, TCP_CORK, &one,
sizeof(
int));
192 stream.set_option(IPPROTO_TCP, TCP_CORK, &one,
sizeof(
int));
201 stream.set_option(IPPROTO_TCP, TCP_CORK, &zero,
sizeof(
int));
207 if (timeout < 1e-12) {
208 haveWriteTimeout =
false;
211 haveWriteTimeout =
true;
218 if (timeout < 1e-12) {
219 haveReadTimeout =
false;
222 haveReadTimeout =
true;
227 bool setTypeOfService(
int tos)
override;
228 int getTypeOfService()
override;
231 yarp::os::impl::TcpStream stream;
232 bool haveWriteTimeout;
233 bool haveReadTimeout;
236 Contact localAddress, remoteAddress;
238 void updateAddresses();
const yarp::os::LogComponent & SOCKETTWOWAYSTREAM()
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.
const Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
bool setReadTimeout(double timeout) override
Set activity timeout.
OutputStream & getOutputStream() override
Get an OutputStream to write to.
InputStream & getInputStream() override
Get an InputStream to read from.
void close() override
Terminate the stream.
void flush() override
Make sure all pending write operations are finished.
const Contact & getLocalAddress() const override
Get the address of the local side of the stream.
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.
#define YARP_DECLARE_LOG_COMPONENT(name)
#define yCDebug(component,...)
struct timeval YARP_timeval
The main, catch-all namespace for YARP.