Commit 283e5235 authored by Pieter Hintjens's avatar Pieter Hintjens

Merge pull request #700 from hashstat/master

Add documentation on Linux ipc abstract namespace support and a bug fix.
parents 1a202208 62e26b32
......@@ -69,6 +69,7 @@ tests/test_inproc_connect
tests/test_linger
tests/test_security_null
tests/test_security_plain
tests/test_abstract_ipc
tests/test*.log
tests/test*.trs
src/platform.hpp*
......
......@@ -48,6 +48,11 @@ NOTE: the endpoint pathname must be writable by the process. When the endpoint
starts with '/', e.g., `ipc:///pathname`, this will be an _absolute_ pathname.
If the endpoint specifies a directory that does not exist, the bind shall fail.
NOTE: on Linux only, when the endpoint pathname starts with `@`, the abstract
namespace shall be used. The abstract namespace is independent of the
filesystem and if a process attempts to bind an endpoint already bound by a
process, it will fail. See unix(7) for details.
Connecting a socket
~~~~~~~~~~~~~~~~~~~
When connecting a 'socket' to a peer address using _zmq_connect()_ with the
......
......@@ -51,11 +51,18 @@ int zmq::ipc_address_t::resolve (const char *path_)
errno = ENAMETOOLONG;
return -1;
}
#if defined ZMQ_HAVE_LINUX
if (path_[0] == '@' && !path_[1]) {
errno = EINVAL;
return -1;
}
#endif
address.sun_family = AF_UNIX;
strcpy (address.sun_path, path_);
#if defined ZMQ_HAVE_LINUX
if (*path_ == '@')
/* Abstract sockets on Linux start with '\0' */
if (path_[0] == '@')
*address.sun_path = '\0';
#endif
return 0;
......@@ -73,10 +80,10 @@ int zmq::ipc_address_t::to_string (std::string &addr_)
s << "ipc://" << address.sun_path;
#else
s << "ipc://";
if (*address.sun_path)
s << address.sun_path;
else
if (!address.sun_path[0] && address.sun_path[1])
s << "@" << address.sun_path + 1;
else
s << address.sun_path;
#endif
addr_ = s.str ();
return 0;
......@@ -89,6 +96,10 @@ const sockaddr *zmq::ipc_address_t::addr () const
socklen_t zmq::ipc_address_t::addrlen () const
{
#if defined ZMQ_HAVE_LINUX
if (!address.sun_path[0] && address.sun_path[1])
return (socklen_t) strlen(address.sun_path + 1) + sizeof (sa_family_t) + 1;
#endif
return (socklen_t) sizeof (address);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment