YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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 mini-server for performing network communication in the background.
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.
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.
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
TcpCarrier(bool requireAckFlag=true)
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
bool respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
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...
Carrier * create() const override
Factory method.
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...
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
virtual int getSpecifierCode() const
An interface to the operating system, including Port based communication.
#define YARP_UNUSED(var)
Definition api.h:162