30 std::lock_guard<std::mutex> lock(
m);
76 "The ports are on different machines, unix socket not supported...");
96 return requireAckFlag;
106 if (header.
length() != headerSize) {
113 const char* target = headerCode;
115 for (
size_t i = 0; i < headerSize; i++) {
116 if (header.
get()[i] != target[i]) {
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 {
'\0',
'\0',
'\0',
'\0'};
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);
193bool UnixSocketCarrier::becomeUnixSocket(
ConnectionState& proto,
bool sender)
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"));
246 if (options.
check(
"ack")) {
248 requireAckFlag =
true;
256 for (
size_t i = 0; i < headerSize; i++) {
262 requireAckFlag =
true;
const yarp::os::LogComponent & UNIXSOCK_CARRIER()
A stream abstraction for unix socket communication.
bool open(bool sender=false)
void setLocalAddress(yarp::os::Contact &_localAddress)
void setRemoteAddress(yarp::os::Contact &_remoteAddress)
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.
UnixSocketCarrier()=default
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 mini-server for performing network communication in the background.
BufferedPort()
Constructor.
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.
OutputStream & os()
Shorthand for getOutputStream()
virtual std::string getSenderSpecifier() const =0
Extract a name for the sender, if the connection type supports that.
InputStream & is()
Shorthand for getInputStream()
virtual void takeStreams(TwoWayStream *streams)=0
Provide streams to be used with the connection.
virtual TwoWayStream & getStreams()=0
Access the streams associated with the connection.
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.
#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
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.