From bf3702395ca0dfd6a279f96b3a702fd09f17950c Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Fri, 20 Dec 2013 14:28:54 +0100 Subject: [PATCH] Fixed wildcard IPC endpoint and added test case --- .gitignore | 2 ++ src/ipc_listener.cpp | 4 ++- tests/Makefile.am | 2 ++ tests/test_ipc_wildcard.cpp | 55 +++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/test_ipc_wildcard.cpp diff --git a/.gitignore b/.gitignore index 43ec4e2b..266852e6 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,8 @@ autom4te.cache .*~ tools/curve_keygen.o tools/curve_keygen +tests/test_resource +tests/test_ipc_wildcard tests/test_stream_empty tests/test_issue_566 tests/test_ctx_destroy diff --git a/src/ipc_listener.cpp b/src/ipc_listener.cpp index aa45ae68..b9d782d1 100644 --- a/src/ipc_listener.cpp +++ b/src/ipc_listener.cpp @@ -133,9 +133,11 @@ int zmq::ipc_listener_t::set_address (const char *addr_) // Allow wildcard file if (addr [0] == '*') { char buffer [12] = "2134XXXXXX"; - if (mkstemp (buffer) == -1) + int fd = mkstemp (buffer); + if (fd == -1) return -1; addr.assign (buffer); + ::close (fd); } // Get rid of the file associated with the UNIX domain socket that diff --git a/tests/Makefile.am b/tests/Makefile.am index 708f71fa..42ee17aa 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -44,6 +44,7 @@ noinst_PROGRAMS = test_system \ test_proxy \ test_abstract_ipc \ test_many_sockets \ + test_ipc_wildcard \ test_diffserv if !ON_MINGW @@ -108,6 +109,7 @@ test_issue_566_SOURCES = test_issue_566.cpp test_proxy_SOURCES = test_proxy.cpp test_abstract_ipc_SOURCES = test_abstract_ipc.cpp test_many_sockets_SOURCES = test_many_sockets.cpp +test_ipc_wildcard_SOURCES = test_ipc_wildcard.cpp test_diffserv_SOURCES = test_diffserv.cpp if !ON_MINGW test_shutdown_stress_SOURCES = test_shutdown_stress.cpp diff --git a/tests/test_ipc_wildcard.cpp b/tests/test_ipc_wildcard.cpp new file mode 100644 index 00000000..a49e92ca --- /dev/null +++ b/tests/test_ipc_wildcard.cpp @@ -0,0 +1,55 @@ +/* + 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 . +*/ + +#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://*"); + assert (rc == 0); + + char endpoint [200]; + size_t size = sizeof (endpoint); + rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, endpoint, &size); + assert (rc == 0); + + void *sc = zmq_socket (ctx, ZMQ_PAIR); + assert (sc); + rc = zmq_connect (sc, endpoint); + 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 ; +}