YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
UnixSocketCarrier.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6
7#ifndef YARP_UNIX_UNIXSOCKETCARRIER_H
8#define YARP_UNIX_UNIXSOCKETCARRIER_H
9
11
13
14// The compile pre-defines the "unix" macro, but we don't use it, and it
15// conflicts with the generated yarp_plugin_unix.cpp file
16#ifdef unix
17# undef unix
18#endif
19
26{
27public:
28 UnixSocketCarrier() = default;
33
34 ~UnixSocketCarrier() override = default;
35
36 yarp::os::Carrier* create() const override;
37
38 std::string getName() const override;
39
40 bool requireAck() const override;
41 bool isConnectionless() const override;
42
43 bool checkHeader(const yarp::os::Bytes& header) override;
44 void getHeader(yarp::os::Bytes& header) const override;
45
46 bool respondToHeader(yarp::os::ConnectionState& proto) override;
48
49 bool expectIndex(yarp::os::ConnectionState& proto) override;
50 bool sendIndex(yarp::os::ConnectionState& proto, yarp::os::SizedWriter& writer) override;
51
52 bool expectAck(yarp::os::ConnectionState& proto) override;
53 bool sendAck(yarp::os::ConnectionState& proto) override;
54
55 // The initiator reads the carrier parameters from the connection string (i.e. unix_stream+ack)
56 bool configure(yarp::os::ConnectionState& proto) override;
57 bool configureFromProperty(yarp::os::Property& options) override;
58
59 // The recipients must decipher the parameters from the first 8 bytes (i.e. UNIX_ACK)
60 void setParameters(const yarp::os::Bytes& header) override;
61
62private:
63 static constexpr const char* name = "unix_stream";
64 static constexpr int specifierCode = 11;
65 static constexpr const char* headerCode = "UNIX_STR";
66
67 static constexpr const char* name_ack = "unix_stream_ack";
68 static constexpr int specifierCode_ack = 12;
69 static constexpr const char* headerCode_ack = "UNIX_ACK";
70
71 static constexpr size_t headerSize = 8;
72
73 static constexpr const char* ack_string = "ACK";
74 static constexpr size_t ack_string_size = 4;
75
76 std::string socketPath;
77 bool requireAckFlag{false};
78 UnixSockTwoWayStream* stream{nullptr};
79
80 bool becomeUnixSocket(yarp::os::ConnectionState& proto, bool sender = false);
81};
82
83#endif // YARP_UNIX_UNIXSOCKETCARRIER_H
A stream abstraction for unix socket communication.
Communicating between two ports(IPC) via Unix Socket.
bool sendAck(yarp::os::ConnectionState &proto) override
Send an acknowledgement, if needed for this carrier.
bool sendIndex(yarp::os::ConnectionState &proto, yarp::os::SizedWriter &writer) override
UnixSocketCarrier & operator=(const UnixSocketCarrier &)=delete
void setParameters(const yarp::os::Bytes &header) override
Configure this carrier based on the first 8 bytes of the connection.
bool isConnectionless() const override
Check if this carrier is connectionless (like udp, mcast) or connection based (like tcp).
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
bool requireAck() const override
Check if carrier has flow control, requiring sent messages to be acknowledged by recipient.
bool expectAck(yarp::os::ConnectionState &proto) override
Receive an acknowledgement, if expected for this carrier.
UnixSocketCarrier(const UnixSocketCarrier &)=delete
~UnixSocketCarrier() override=default
bool configure(yarp::os::ConnectionState &proto) override
Give carrier a shot at looking at how the connection is set up.
UnixSocketCarrier()=default
bool expectIndex(yarp::os::ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
UnixSocketCarrier & operator=(UnixSocketCarrier &&)=delete
bool respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
UnixSocketCarrier(UnixSocketCarrier &&)=delete
bool expectReplyToHeader(yarp::os::ConnectionState &proto) override
Process reply to header, if one is expected for this carrier.
bool configureFromProperty(yarp::os::Property &options) override
yarp::os::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 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...
A starter class for implementing simple carriers.
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.
A class for storing options and configuration information.
Definition Property.h:33
Minimal requirements for an efficient Writer.
Definition SizedWriter.h:32