Add abstract namespace support for IPC sockets on Linux.

Converts an initial strudel or "at sign" (@) in the Unix socket path to
a NULL character ('\0') indicating that the socket uses the abstract
namespace instead of the filesystem namespace.  For instance, binding a
socket to 'ipc://@/tmp/tester' will not create a file associated with
the socket whereas binding to 'ipc:///tmp/tester' will create the file
/tmp/tester.  See issue 567 for more information.
This commit is contained in:
Brandon Carpenter 2013-10-03 16:21:42 -07:00
parent 23e58e30d5
commit 31cdbd2afa
2 changed files with 13 additions and 0 deletions

View File

@ -20,6 +20,7 @@ Ben Gray <ben@benjamg.com>
Bernd Prager <bernd@prager.ws>
Bernd Melchers <melchers@ZEDAT.FU-Berlin.DE>
Bob Beaty <rbeaty@peak6.com>
Brandon Carpenter <hashstat@yahoo.com>
Brian Buchanan <bwb@holo.org>
Brett Cameron <Brett.Cameron@hp.com>
Burak Arslan <burak-github@arskom.com.tr>

View File

@ -54,6 +54,10 @@ int zmq::ipc_address_t::resolve (const char *path_)
address.sun_family = AF_UNIX;
strcpy (address.sun_path, path_);
#if defined ZMQ_HAVE_LINUX
if (*path_ == '@')
*address.sun_path = '\0';
#endif
return 0;
}
@ -65,7 +69,15 @@ int zmq::ipc_address_t::to_string (std::string &addr_)
}
std::stringstream s;
#if !defined ZMQ_HAVE_LINUX
s << "ipc://" << address.sun_path;
#else
s << "ipc://";
if (*address.sun_path)
s << address.sun_path;
else
s << "@" << address.sun_path + 1;
#endif
addr_ = s.str ();
return 0;
}