30 std::string getYARPRuntimeDir()
33 std::lock_guard<std::mutex> lock(m);
35 static std::string yarp_runtime_dir;
39 if (!yarp_runtime_dir.empty()) {
40 return yarp_runtime_dir;
46 return yarp_runtime_dir;
53 return yarp_runtime_dir;
60 return yarp_runtime_dir;
79 "The ports are on different machines, unix socket not supported...");
99 return requireAckFlag;
109 if (header.
length() != headerSize) {
114 bool isUnix_ack =
true;
116 const char* target = headerCode;
117 const char* target_ack = headerCode_ack;
118 for (
size_t i = 0; i < headerSize; i++) {
119 if (header.
get()[i] != target[i]) {
122 if (header.
get()[i] != target_ack[i]) {
127 return (isUnix || isUnix_ack);
132 const char* target = requireAckFlag ? headerCode_ack : headerCode;
133 for (
size_t i = 0; i < headerSize && i < header.
length(); i++) {
134 header.
get()[i] = target[i];
155 if (requireAckFlag) {
156 const Bytes ack_bytes(
const_cast<char*
>(ack_string), ack_string_size);
164 if (requireAckFlag) {
165 std::array<char, ack_string_size> buf;
166 Bytes ack(buf.data(), buf.size());
168 if (
static_cast<size_t>(hdr) != ack.
length()) {
173 const char* target = ack_string;
174 for (
size_t i = 0; i < ack_string_size; i++) {
175 if (ack.
get()[i] != target[i]) {
187 return becomeUnixSocket(proto,
false);
193 return becomeUnixSocket(proto,
true);
196 bool UnixSocketCarrier::becomeUnixSocket(
ConnectionState& proto,
bool sender)
198 if (!isUnixSockSupported(proto)) {
207 std::string runtime_dir = getYARPRuntimeDir();
222 stream->setLocalAddress(local);
223 stream->setRemoteAddress(remote);
225 if (!stream->open(sender)) {
228 yCError(
UNIXSOCK_CARRIER,
"Failed to open stream on socket %s as %s", socketPath.c_str(), (sender ?
"sender" :
"receiver"));
235 yCDebug(
UNIXSOCK_CARRIER,
"Connected on socket %s as %s", socketPath.c_str(), (sender ?
"sender" :
"receiver"));
244 return configureFromProperty(options);
249 if (options.
check(
"ack")) {
251 requireAckFlag =
true;
258 const char* target_ack = headerCode_ack;
259 for (
size_t i = 0; i < headerSize; i++) {
260 if (header.
get()[i] != target_ack[i]) {
265 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 getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
static constexpr value_type preferred_separator
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.