diff --git a/CMakeLists.txt b/CMakeLists.txt index 141bad3a..3a33117c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -620,6 +620,7 @@ set(tests test_issue_566 test_shutdown_stress test_timeo + test_many_sockets ) if(NOT WIN32) list(APPEND tests diff --git a/tests/Makefile.am b/tests/Makefile.am index f2de7775..93a1ee0e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -42,7 +42,8 @@ noinst_PROGRAMS = test_system \ test_inproc_connect \ test_issue_566 \ test_proxy \ - test_abstract_ipc + test_abstract_ipc \ + test_many_sockets if !ON_MINGW noinst_PROGRAMS += test_shutdown_stress \ @@ -103,6 +104,7 @@ test_inproc_connect_SOURCES = test_inproc_connect.cpp 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 if !ON_MINGW test_shutdown_stress_SOURCES = test_shutdown_stress.cpp test_pair_ipc_SOURCES = test_pair_ipc.cpp testutil.hpp diff --git a/tests/test_many_sockets.cpp b/tests/test_many_sockets.cpp new file mode 100644 index 00000000..d7d85d7e --- /dev/null +++ b/tests/test_many_sockets.cpp @@ -0,0 +1,51 @@ +/* + 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" +#include +#include +#include + +const int no_of_sockets = 5000; + +int main(void) +{ + setup_test_environment(); + + void *ctx = zmq_ctx_new(); + void *sockets[no_of_sockets]; + + int sockets_created = 0; + + for ( int i = 0; i < no_of_sockets; ++i ) + { + sockets[i] = zmq_socket(ctx, ZMQ_PAIR); + if (sockets[i]) + ++sockets_created; + } + + assert(sockets_created < no_of_sockets); + + for ( int i = 0; i < no_of_sockets; ++i ) + if (sockets[i]) + zmq_close (sockets[i]); + + zmq_ctx_destroy (ctx); + return 0; +}