mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-09 15:26:04 +00:00
Fixed issue #500
This commit is contained in:
parent
309740e197
commit
8ab3c4a1bf
3
.gitignore
vendored
3
.gitignore
vendored
@ -45,6 +45,7 @@ tests/test_router_mandatory
|
|||||||
tests/test_disconnect_inproc
|
tests/test_disconnect_inproc
|
||||||
tests/test_raw_sock
|
tests/test_raw_sock
|
||||||
tests/test_disconnect_inproc
|
tests/test_disconnect_inproc
|
||||||
|
tests/test_ctx_options
|
||||||
src/platform.hpp*
|
src/platform.hpp*
|
||||||
src/stamp-h1
|
src/stamp-h1
|
||||||
perf/local_lat
|
perf/local_lat
|
||||||
@ -73,3 +74,5 @@ foreign/openpgm/*
|
|||||||
!foreign/openpgm/Makefile.am
|
!foreign/openpgm/Makefile.am
|
||||||
zeromq-*.tar.gz
|
zeromq-*.tar.gz
|
||||||
zeromq-*.zip
|
zeromq-*.zip
|
||||||
|
core
|
||||||
|
|
||||||
|
@ -26,11 +26,15 @@ ZMQ_IO_THREADS: Get number of I/O threads
|
|||||||
The 'ZMQ_IO_THREADS' argument returns the size of the 0MQ thread pool
|
The 'ZMQ_IO_THREADS' argument returns the size of the 0MQ thread pool
|
||||||
for this context.
|
for this context.
|
||||||
|
|
||||||
ZMQ_MAX_SOCKETS: Set maximum number of sockets
|
ZMQ_MAX_SOCKETS: Get maximum number of sockets
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
The 'ZMQ_MAX_SOCKETS' argument returns the maximum number of sockets
|
The 'ZMQ_MAX_SOCKETS' argument returns the maximum number of sockets
|
||||||
allowed for this context.
|
allowed for this context.
|
||||||
|
|
||||||
|
ZMQ_IPV6: Set IPv6 option
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
The 'ZMQ_IPV6' argument returns the IPv6 option for the context.
|
||||||
|
|
||||||
|
|
||||||
RETURN VALUE
|
RETURN VALUE
|
||||||
------------
|
------------
|
||||||
|
@ -40,6 +40,17 @@ on the context.
|
|||||||
[horizontal]
|
[horizontal]
|
||||||
Default value:: 1024
|
Default value:: 1024
|
||||||
|
|
||||||
|
ZMQ_IPV6: Set IPv6 option
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
The 'ZMQ_IPV6' argument sets the IPv6 value for all sockets created in
|
||||||
|
the context from this point onwards. A value of `1` means IPv6 is
|
||||||
|
enabled, while `0` means the socket will use only IPv4. When IPv6 is
|
||||||
|
enabled, a socket will connect to, or accept connections from, both
|
||||||
|
IPv4 and IPv6 hosts.
|
||||||
|
|
||||||
|
[horizontal]
|
||||||
|
Default value:: 0
|
||||||
|
|
||||||
|
|
||||||
RETURN VALUE
|
RETURN VALUE
|
||||||
------------
|
------------
|
||||||
|
20
src/ctx.cpp
20
src/ctx.cpp
@ -45,7 +45,8 @@ zmq::ctx_t::ctx_t () :
|
|||||||
slot_count (0),
|
slot_count (0),
|
||||||
slots (NULL),
|
slots (NULL),
|
||||||
max_sockets (ZMQ_MAX_SOCKETS_DFLT),
|
max_sockets (ZMQ_MAX_SOCKETS_DFLT),
|
||||||
io_thread_count (ZMQ_IO_THREADS_DFLT)
|
io_thread_count (ZMQ_IO_THREADS_DFLT),
|
||||||
|
ipv6 (false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +140,12 @@ int zmq::ctx_t::set (int option_, int optval_)
|
|||||||
io_thread_count = optval_;
|
io_thread_count = optval_;
|
||||||
opt_sync.unlock ();
|
opt_sync.unlock ();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
if (option_ == ZMQ_IPV6 && optval_ >= 0) {
|
||||||
|
opt_sync.lock ();
|
||||||
|
ipv6 = optval_;
|
||||||
|
opt_sync.unlock ();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
rc = -1;
|
rc = -1;
|
||||||
@ -154,6 +161,9 @@ int zmq::ctx_t::get (int option_)
|
|||||||
else
|
else
|
||||||
if (option_ == ZMQ_IO_THREADS)
|
if (option_ == ZMQ_IO_THREADS)
|
||||||
rc = io_thread_count;
|
rc = io_thread_count;
|
||||||
|
else
|
||||||
|
if (option_ == ZMQ_IPV6)
|
||||||
|
rc = ipv6;
|
||||||
else {
|
else {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
rc = -1;
|
rc = -1;
|
||||||
@ -168,7 +178,7 @@ zmq::socket_base_t *zmq::ctx_t::create_socket (int type_)
|
|||||||
|
|
||||||
starting = false;
|
starting = false;
|
||||||
// Initialise the array of mailboxes. Additional three slots are for
|
// Initialise the array of mailboxes. Additional three slots are for
|
||||||
// zmq_term thread and reaper thread.
|
// zmq_ctx_term thread and reaper thread.
|
||||||
opt_sync.lock ();
|
opt_sync.lock ();
|
||||||
int mazmq = max_sockets;
|
int mazmq = max_sockets;
|
||||||
int ios = io_thread_count;
|
int ios = io_thread_count;
|
||||||
@ -177,7 +187,7 @@ zmq::socket_base_t *zmq::ctx_t::create_socket (int type_)
|
|||||||
slots = (mailbox_t**) malloc (sizeof (mailbox_t*) * slot_count);
|
slots = (mailbox_t**) malloc (sizeof (mailbox_t*) * slot_count);
|
||||||
alloc_assert (slots);
|
alloc_assert (slots);
|
||||||
|
|
||||||
// Initialise the infrastructure for zmq_term thread.
|
// Initialise the infrastructure for zmq_ctx_term thread.
|
||||||
slots [term_tid] = &term_mailbox;
|
slots [term_tid] = &term_mailbox;
|
||||||
|
|
||||||
// Create the reaper thread.
|
// Create the reaper thread.
|
||||||
@ -203,7 +213,7 @@ zmq::socket_base_t *zmq::ctx_t::create_socket (int type_)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Once zmq_term() was called, we can't create new sockets.
|
// Once zmq_ctx_term() was called, we can't create new sockets.
|
||||||
if (terminating) {
|
if (terminating) {
|
||||||
slot_sync.unlock ();
|
slot_sync.unlock ();
|
||||||
errno = ETERM;
|
errno = ETERM;
|
||||||
@ -250,7 +260,7 @@ void zmq::ctx_t::destroy_socket (class socket_base_t *socket_)
|
|||||||
// Remove the socket from the list of sockets.
|
// Remove the socket from the list of sockets.
|
||||||
sockets.erase (socket_);
|
sockets.erase (socket_);
|
||||||
|
|
||||||
// If zmq_term() was already called and there are no more socket
|
// If zmq_ctx_term() was already called and there are no more socket
|
||||||
// we can ask reaper thread to terminate.
|
// we can ask reaper thread to terminate.
|
||||||
if (terminating && sockets.empty ())
|
if (terminating && sockets.empty ())
|
||||||
reaper->stop ();
|
reaper->stop ();
|
||||||
|
@ -161,6 +161,9 @@ namespace zmq
|
|||||||
// Number of I/O threads to launch.
|
// Number of I/O threads to launch.
|
||||||
int io_thread_count;
|
int io_thread_count;
|
||||||
|
|
||||||
|
// Is IPv6 enabled on this context?
|
||||||
|
bool ipv6;
|
||||||
|
|
||||||
// Synchronisation of access to context options.
|
// Synchronisation of access to context options.
|
||||||
mutex_t opt_sync;
|
mutex_t opt_sync;
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
|
|
||||||
namespace zmq
|
namespace zmq
|
||||||
{
|
{
|
||||||
|
|
||||||
struct options_t
|
struct options_t
|
||||||
{
|
{
|
||||||
options_t ();
|
options_t ();
|
||||||
|
@ -135,6 +135,7 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_, uint32_t tid_, int sid_) :
|
|||||||
monitor_events (0)
|
monitor_events (0)
|
||||||
{
|
{
|
||||||
options.socket_id = sid_;
|
options.socket_id = sid_;
|
||||||
|
options.ipv6 = parent_->get (ZMQ_IPV6);
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq::socket_base_t::~socket_base_t ()
|
zmq::socket_base_t::~socket_base_t ()
|
||||||
|
@ -19,8 +19,8 @@ noinst_PROGRAMS = test_pair_inproc \
|
|||||||
test_monitor \
|
test_monitor \
|
||||||
test_router_mandatory \
|
test_router_mandatory \
|
||||||
test_raw_sock \
|
test_raw_sock \
|
||||||
test_disconnect_inproc
|
test_disconnect_inproc \
|
||||||
|
test_ctx_options
|
||||||
|
|
||||||
if !ON_MINGW
|
if !ON_MINGW
|
||||||
noinst_PROGRAMS += test_shutdown_stress \
|
noinst_PROGRAMS += test_shutdown_stress \
|
||||||
@ -46,7 +46,7 @@ test_monitor_SOURCES = test_monitor.cpp
|
|||||||
test_router_mandatory_SOURCES = test_router_mandatory.cpp
|
test_router_mandatory_SOURCES = test_router_mandatory.cpp
|
||||||
test_raw_sock_SOURCES = test_raw_sock.cpp
|
test_raw_sock_SOURCES = test_raw_sock.cpp
|
||||||
test_disconnect_inproc_SOURCES = test_disconnect_inproc.cpp
|
test_disconnect_inproc_SOURCES = test_disconnect_inproc.cpp
|
||||||
|
test_ctx_set_SOURCES = test_ctx_options.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
|
||||||
|
56
tests/test_ctx_options.cpp
Normal file
56
tests/test_ctx_options.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2007-2013 iMatix Corporation
|
||||||
|
Copyright (c) 2007-2012 Other 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 "../include/zmq.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#undef NDEBUG
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
// Set up our context and sockets
|
||||||
|
void *ctx = zmq_ctx_new ();
|
||||||
|
assert (ctx);
|
||||||
|
|
||||||
|
assert (zmq_ctx_get (ctx, ZMQ_MAX_SOCKETS) == ZMQ_MAX_SOCKETS_DFLT);
|
||||||
|
assert (zmq_ctx_get (ctx, ZMQ_IO_THREADS) == ZMQ_IO_THREADS_DFLT);
|
||||||
|
assert (zmq_ctx_get (ctx, ZMQ_IPV6) == 0);
|
||||||
|
|
||||||
|
rc = zmq_ctx_set (ctx, ZMQ_IPV6, true);
|
||||||
|
assert (zmq_ctx_get (ctx, ZMQ_IPV6) == true);
|
||||||
|
|
||||||
|
void *router = zmq_socket (ctx, ZMQ_ROUTER);
|
||||||
|
int ipv6;
|
||||||
|
size_t optsize = sizeof (int);
|
||||||
|
rc = zmq_getsockopt (router, ZMQ_IPV6, &ipv6, &optsize);
|
||||||
|
assert (rc == 0);
|
||||||
|
assert (ipv6);
|
||||||
|
|
||||||
|
rc = zmq_close (router);
|
||||||
|
assert (rc == 0);
|
||||||
|
|
||||||
|
rc = zmq_ctx_term (ctx);
|
||||||
|
assert (rc == 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user