|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
10 #ifndef YARP_OS_IMPL_SOCKETTWOWAYSTREAM_H
11 #define YARP_OS_IMPL_SOCKETTWOWAYSTREAM_H
22 #ifdef YARP_HAS_ACE // For TCP_CORK definition
23 # include <ace/os_include/netinet/os_tcp.h>
29 # include <netinet/tcp.h>
48 haveWriteTimeout(false),
49 haveReadTimeout(false),
54 int open(
const Contact& address);
56 int open(yarp::os::impl::TcpAcceptor& acceptor);
88 stream.close_reader();
90 stream.close_writer();
110 if (haveReadTimeout) {
111 result = stream.recv_n(b.
get(), b.
length(), &readTimeout);
113 result = stream.recv_n(b.
get(), b.
length());
131 if (haveReadTimeout) {
132 result = stream.recv(b.
get(), b.
length(), &readTimeout);
134 result = stream.recv(b.
get(), b.
length());
153 if (haveWriteTimeout) {
154 result = stream.send_n(b.
get(), b.
length(), &writeTimeout);
156 result = stream.send_n(b.
get(), b.
length());
168 int sizeInt =
sizeof(int);
169 stream.get_option(IPPROTO_TCP, TCP_CORK, &status, &sizeInt);
173 stream.set_option(IPPROTO_TCP, TCP_CORK, &zero,
sizeof(
int));
176 stream.set_option(IPPROTO_TCP, TCP_CORK, &one,
sizeof(
int));
195 stream.set_option(IPPROTO_TCP, TCP_CORK, &one,
sizeof(
int));
204 stream.set_option(IPPROTO_TCP, TCP_CORK, &zero,
sizeof(
int));
210 if (timeout < 1e-12) {
211 haveWriteTimeout =
false;
214 haveWriteTimeout =
true;
221 if (timeout < 1e-12) {
222 haveReadTimeout =
false;
225 haveReadTimeout =
true;
230 bool setTypeOfService(
int tos)
override;
231 int getTypeOfService()
override;
234 yarp::os::impl::TcpStream stream;
235 bool haveWriteTimeout;
236 bool haveReadTimeout;
239 Contact localAddress, remoteAddress;
241 void updateAddresses();
248 #endif // YARP_OS_IMPL_SOCKETTWOWAYSTREAM_H
bool isOk() const override
Check if the stream is ok or in an error state.
bool setReadTimeout(double timeout) override
Set activity timeout.
A stream which can be asked to perform bidirectional communication.
const Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
#define YARP_DECLARE_LOG_COMPONENT(name)
virtual void write(char ch)
Write a single byte to the stream.
void beginPacket() override
Mark the beginning of a logical packet.
Simple specification of the minimum functions needed from output streams.
void write(const Bytes &b) override
Write a block of bytes to the stream.
bool setWriteTimeout(double timeout) override
Set activity timeout.
const Contact & getLocalAddress() const override
Get the address of the local side of the stream.
void interrupt() override
Interrupt the stream.
A stream abstraction for socket communication.
void endPacket() override
Mark the end of a logical packet (see beginPacket).
const yarp::os::LogComponent & SOCKETTWOWAYSTREAM()
InputStream & getInputStream() override
Get an InputStream to read from.
A simple abstraction for a block of bytes.
yarp::conf::ssize_t read(Bytes &b) override
Read a block of data from the stream.
void close() override
Terminate the stream.
#define yCDebug(component,...)
struct timeval YARP_timeval
void reset() override
Reset the stream.
The main, catch-all namespace for YARP.
~SocketTwoWayStream() override
void flush() override
Make sure all pending write operations are finished.
OutputStream & getOutputStream() override
Get an OutputStream to write to.
yarp::conf::ssize_t partialRead(Bytes &b) override
Like read, but solicit partial responses.