YARP
Yet Another Robot Platform
TcpCarrier.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
8
11
12#include <string>
13
14using namespace yarp::os;
15
16
18{
19 this->requireAckFlag = requireAckFlag;
20}
21
23{
24 return new TcpCarrier(requireAckFlag);
25}
26
28{
29 return requireAckFlag ? "tcp" : "fast_tcp";
30}
31
33{
34 return 3;
35}
36
38{
39 int spec = getSpecifier(header);
40 if (spec % 16 == getSpecifierCode()) {
41 if (((spec & 128) != 0) == requireAckFlag) {
42 return true;
43 }
44 }
45 return false;
46}
47
49{
50 createStandardHeader(getSpecifierCode() + (requireAckFlag ? 128 : 0), header);
51}
52
54{
55 YARP_UNUSED(header);
56 //int specifier = getSpecifier(header);
57 //requireAckFlag = (specifier&128)!=0;
58 // Now prefilter by ack flag
59}
60
62{
63 return requireAckFlag;
64}
65
67{
68 return false;
69}
70
72{
73 int cport = proto.getStreams().getLocalAddress().getPort();
74 writeYarpInt(cport, proto);
75 return proto.checkStreams();
76}
77
79{
80 readYarpInt(proto); // ignore result
81 return proto.checkStreams();
82}
A simple abstraction for a block of bytes.
Definition: Bytes.h:24
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
Definition: Carrier.h:44
The basic state of a connection - route, streams in use, etc.
virtual bool checkStreams() const =0
Check whether streams are in a good state.
virtual TwoWayStream & getStreams()=0
Access the streams associated with the connection.
int getPort() const
Get the port number associated with this Contact for socket communication.
Definition: Contact.cpp:239
virtual const Contact & getLocalAddress() const =0
Get the address of the local side of the stream.
Communicating between two ports via TCP.
Definition: TcpCarrier.h:19
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
Definition: TcpCarrier.cpp:61
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: TcpCarrier.cpp:27
TcpCarrier(bool requireAckFlag=true)
Definition: TcpCarrier.cpp:17
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
Definition: TcpCarrier.cpp:78
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
Definition: TcpCarrier.cpp:53
bool respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
Definition: TcpCarrier.cpp:71
bool checkHeader(const yarp::os::Bytes &header) override
Given the first 8 bytes received on a connection, decide if this is the right carrier type to use for...
Definition: TcpCarrier.cpp:37
Carrier * create() const override
Factory method.
Definition: TcpCarrier.cpp:22
void getHeader(yarp::os::Bytes &header) const override
Provide 8 bytes describing this connection sufficiently to allow the other side of a connection to se...
Definition: TcpCarrier.cpp:48
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
Definition: TcpCarrier.cpp:66
virtual int getSpecifierCode() const
Definition: TcpCarrier.cpp:32
An interface to the operating system, including Port based communication.
#define YARP_UNUSED(var)
Definition: api.h:162