27 std::string getYARPRuntimeDir()
30 std::lock_guard<std::mutex> lock(m);
32 static std::string yarp_runtime_dir;
36 if (!yarp_runtime_dir.empty()) {
37 return yarp_runtime_dir;
43 return yarp_runtime_dir;
50 return yarp_runtime_dir;
57 return yarp_runtime_dir;
76 "The ports are on different machines, unix socket not supported...");
96 return requireAckFlag;
106 if (header.
length() != headerSize) {
111 bool isUnix_ack =
true;
113 const char* target = headerCode;
114 const char* target_ack = headerCode_ack;
115 for (
size_t i = 0; i < headerSize; i++) {
116 if (header.
get()[i] != target[i]) {
119 if (header.
get()[i] != target_ack[i]) {
124 return (isUnix || isUnix_ack);
129 const char* target = requireAckFlag ? headerCode_ack : headerCode;
130 for (
size_t i = 0; i < headerSize && i < header.
length(); i++) {
131 header.
get()[i] = target[i];
152 if (requireAckFlag) {
153 const Bytes ack_bytes(
const_cast<char*
>(ack_string), ack_string_size);
161 if (requireAckFlag) {
162 std::array<char, ack_string_size> buf;
163 Bytes ack(buf.data(), buf.size());
165 if (
static_cast<size_t>(hdr) != ack.
length()) {
170 const char* target = ack_string;
171 for (
size_t i = 0; i < ack_string_size; i++) {
172 if (ack.
get()[i] != target[i]) {
184 return becomeUnixSocket(proto,
false);
190 return becomeUnixSocket(proto,
true);
193 bool UnixSocketCarrier::becomeUnixSocket(
ConnectionState& proto,
bool sender)
195 if (!isUnixSockSupported(proto)) {
204 std::string runtime_dir = getYARPRuntimeDir();
219 stream->setLocalAddress(local);
220 stream->setRemoteAddress(remote);
222 if (!stream->open(sender)) {
225 yCError(
UNIXSOCK_CARRIER,
"Failed to open stream on socket %s as %s", socketPath.c_str(), (sender ?
"sender" :
"receiver"));
232 yCDebug(
UNIXSOCK_CARRIER,
"Connected on socket %s as %s", socketPath.c_str(), (sender ?
"sender" :
"receiver"));
241 return configureFromProperty(options);
246 if (options.
check(
"ack")) {
248 requireAckFlag =
true;
255 const char* target_ack = headerCode_ack;
256 for (
size_t i = 0; i < headerSize; i++) {
257 if (header.
get()[i] != target_ack[i]) {
262 requireAckFlag =
true;
const yarp::os::LogComponent & UNIXSOCK_CARRIER()
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
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.
bool configure(yarp::os::ConnectionState &proto) override
Give carrier a shot at looking at how the connection is set up.
bool expectIndex(yarp::os::ConnectionState &proto) override
Expect a message header, if there is one for this carrier.
bool respondToHeader(yarp::os::ConnectionState &proto) override
Respond to the header.
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 simple abstraction for a block of bytes.
A base class for connection types (tcp, mcast, shmem, ...) which are called carriers in YARP.
The basic state of a connection - route, streams in use, etc.
virtual TwoWayStream & getStreams()=0
Access the streams associated with the connection.
virtual std::string getSenderSpecifier() const =0
Extract a name for the sender, if the connection type supports that.
virtual void takeStreams(TwoWayStream *streams)=0
Provide streams to be used with the connection.
InputStream & is()
Shorthand for getInputStream()
OutputStream & os()
Shorthand for getOutputStream()
virtual void write(char ch)
Write a single byte to the stream.
A class for storing options and configuration information.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Minimal requirements for an efficient Writer.
virtual const Contact & getLocalAddress() const =0
Get the address of the local side of the stream.
virtual const Contact & getRemoteAddress() const =0
Get the address of the remote side of the stream.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCDebug(component,...)
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
static constexpr value_type preferred_separator
std::string to_string(IntegerType x)
An interface to the operating system, including Port based communication.
int mkdir_p(const char *p, int ignoreLevels=0)
Create a directory and all parent directories needed.