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