Commit bacc9aee authored by Pieter Hintjens's avatar Pieter Hintjens

Merge pull request #698 from hashstat/master

Add abstract namespace support for IPC sockets on Linux.
parents 23e58e30 f499c895
...@@ -20,6 +20,7 @@ Ben Gray <ben@benjamg.com> ...@@ -20,6 +20,7 @@ Ben Gray <ben@benjamg.com>
Bernd Prager <bernd@prager.ws> Bernd Prager <bernd@prager.ws>
Bernd Melchers <melchers@ZEDAT.FU-Berlin.DE> Bernd Melchers <melchers@ZEDAT.FU-Berlin.DE>
Bob Beaty <rbeaty@peak6.com> Bob Beaty <rbeaty@peak6.com>
Brandon Carpenter <hashstat@yahoo.com>
Brian Buchanan <bwb@holo.org> Brian Buchanan <bwb@holo.org>
Brett Cameron <Brett.Cameron@hp.com> Brett Cameron <Brett.Cameron@hp.com>
Burak Arslan <burak-github@arskom.com.tr> Burak Arslan <burak-github@arskom.com.tr>
......
...@@ -114,6 +114,7 @@ libzmq_dso_visibility="yes" ...@@ -114,6 +114,7 @@ libzmq_dso_visibility="yes"
# Platform specific checks # Platform specific checks
libzmq_on_mingw32="no" libzmq_on_mingw32="no"
libzmq_on_android="no" libzmq_on_android="no"
libzmq_on_linux="no"
# Set some default features required by 0MQ code. # Set some default features required by 0MQ code.
CPPFLAGS="-D_REENTRANT -D_THREAD_SAFE $CPPFLAGS" CPPFLAGS="-D_REENTRANT -D_THREAD_SAFE $CPPFLAGS"
...@@ -129,6 +130,7 @@ case "${host_os}" in ...@@ -129,6 +130,7 @@ case "${host_os}" in
CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS" CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS"
fi fi
AC_DEFINE(ZMQ_HAVE_LINUX, 1, [Have Linux OS]) AC_DEFINE(ZMQ_HAVE_LINUX, 1, [Have Linux OS])
libzmq_on_linux="yes"
case "${host_os}" in case "${host_os}" in
*android*) *android*)
...@@ -428,6 +430,7 @@ AC_LANG_POP([C++]) ...@@ -428,6 +430,7 @@ AC_LANG_POP([C++])
AM_CONDITIONAL(BUILD_PGM, test "x$libzmq_pgm_ext" = "xyes") AM_CONDITIONAL(BUILD_PGM, test "x$libzmq_pgm_ext" = "xyes")
AM_CONDITIONAL(ON_MINGW, test "x$libzmq_on_mingw32" = "xyes") AM_CONDITIONAL(ON_MINGW, test "x$libzmq_on_mingw32" = "xyes")
AM_CONDITIONAL(ON_ANDROID, test "x$libzmq_on_android" = "xyes") AM_CONDITIONAL(ON_ANDROID, test "x$libzmq_on_android" = "xyes")
AM_CONDITIONAL(ON_LINUX, test "x$libzmq_on_linux" = "xyes")
# Checks for library functions. # Checks for library functions.
AC_TYPE_SIGNAL AC_TYPE_SIGNAL
......
...@@ -54,6 +54,10 @@ int zmq::ipc_address_t::resolve (const char *path_) ...@@ -54,6 +54,10 @@ int zmq::ipc_address_t::resolve (const char *path_)
address.sun_family = AF_UNIX; address.sun_family = AF_UNIX;
strcpy (address.sun_path, path_); strcpy (address.sun_path, path_);
#if defined ZMQ_HAVE_LINUX
if (*path_ == '@')
*address.sun_path = '\0';
#endif
return 0; return 0;
} }
...@@ -65,7 +69,15 @@ int zmq::ipc_address_t::to_string (std::string &addr_) ...@@ -65,7 +69,15 @@ int zmq::ipc_address_t::to_string (std::string &addr_)
} }
std::stringstream s; std::stringstream s;
#if !defined ZMQ_HAVE_LINUX
s << "ipc://" << address.sun_path; 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 (); addr_ = s.str ();
return 0; return 0;
} }
......
...@@ -38,7 +38,8 @@ noinst_PROGRAMS = test_system \ ...@@ -38,7 +38,8 @@ noinst_PROGRAMS = test_system \
test_req_relaxed \ test_req_relaxed \
test_conflate \ test_conflate \
test_inproc_connect \ test_inproc_connect \
test_issue_566 test_issue_566 \
test_abstract_ipc
if !ON_MINGW if !ON_MINGW
noinst_PROGRAMS += test_shutdown_stress \ noinst_PROGRAMS += test_shutdown_stress \
...@@ -84,6 +85,7 @@ test_req_relaxed_SOURCES = test_req_relaxed.cpp ...@@ -84,6 +85,7 @@ test_req_relaxed_SOURCES = test_req_relaxed.cpp
test_conflate_SOURCES = test_conflate.cpp test_conflate_SOURCES = test_conflate.cpp
test_inproc_connect_SOURCES = test_inproc_connect.cpp test_inproc_connect_SOURCES = test_inproc_connect.cpp
test_issue_566_SOURCES = test_issue_566.cpp test_issue_566_SOURCES = test_issue_566.cpp
test_abstract_ipc_SOURCES = test_abstract_ipc.cpp
if !ON_MINGW if !ON_MINGW
test_shutdown_stress_SOURCES = test_shutdown_stress.cpp test_shutdown_stress_SOURCES = test_shutdown_stress.cpp
test_pair_ipc_SOURCES = test_pair_ipc.cpp testutil.hpp test_pair_ipc_SOURCES = test_pair_ipc.cpp testutil.hpp
...@@ -95,3 +97,7 @@ endif ...@@ -95,3 +97,7 @@ endif
# Run the test cases # Run the test cases
TESTS = $(noinst_PROGRAMS) TESTS = $(noinst_PROGRAMS)
XFAIL_TESTS = test_linger XFAIL_TESTS = test_linger
if !ON_LINUX
XFAIL_TESTS += test_abstract_ipc
endif
/*
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "testutil.hpp"
int main (void)
{
setup_test_environment();
void *ctx = zmq_ctx_new ();
assert (ctx);
void *sb = zmq_socket (ctx, ZMQ_PAIR);
assert (sb);
int rc = zmq_bind (sb, "ipc://@/tmp/tester");
assert (rc == 0);
char endpoint[200];
size_t size = sizeof(endpoint);
rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &size);
assert (rc == 0);
rc = strncmp(endpoint, "ipc://@/tmp/tester", size);
assert (rc == 0);
void *sc = zmq_socket (ctx, ZMQ_PAIR);
assert (sc);
rc = zmq_connect (sc, "ipc://@/tmp/tester");
assert (rc == 0);
bounce (sb, sc);
rc = zmq_close (sc);
assert (rc == 0);
rc = zmq_close (sb);
assert (rc == 0);
rc = zmq_ctx_term (ctx);
assert (rc == 0);
return 0 ;
}
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