Commit 7c514294 authored by Richard Newton's avatar Richard Newton

Reduce default maximum number of sockets by 1 so there is room for the reaper socket.

parent f77b96e4
...@@ -185,7 +185,7 @@ ZMQ_EXPORT const char *zmq_strerror (int errnum); ...@@ -185,7 +185,7 @@ ZMQ_EXPORT const char *zmq_strerror (int errnum);
/* Default for new contexts */ /* Default for new contexts */
#define ZMQ_IO_THREADS_DFLT 1 #define ZMQ_IO_THREADS_DFLT 1
#define ZMQ_MAX_SOCKETS_DFLT 1024 #define ZMQ_MAX_SOCKETS_DFLT 1023
ZMQ_EXPORT void *zmq_ctx_new (void); ZMQ_EXPORT void *zmq_ctx_new (void);
ZMQ_EXPORT int zmq_ctx_term (void *context); ZMQ_EXPORT int zmq_ctx_term (void *context);
......
...@@ -21,32 +21,81 @@ ...@@ -21,32 +21,81 @@
#include <zmq.h> #include <zmq.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <vector>
const int no_of_sockets = 2 * 65536;
int main(void) void test_system_max ()
{ {
setup_test_environment(); // Keep allocating sockets until we run out of system resources
const int no_of_sockets = 2 * 65536;
void *ctx = zmq_ctx_new(); void *ctx = zmq_ctx_new();
zmq_ctx_set(ctx, ZMQ_MAX_SOCKETS, no_of_sockets); zmq_ctx_set(ctx, ZMQ_MAX_SOCKETS, no_of_sockets);
void *sockets[no_of_sockets]; std::vector<void*> sockets;
int sockets_created = 0; while (true)
{
void *socket = zmq_socket(ctx, ZMQ_PAIR);
if (!socket)
break;
sockets.push_back(socket);
}
assert(sockets.size() < no_of_sockets);
// System is out of resources, further calls to zmq_socket should return NULL.
for (unsigned int i = 0; i < 10; ++i)
{
void *socket = zmq_socket(ctx, ZMQ_PAIR);
assert(socket == NULL);
}
// Clean up.
for (unsigned int i = 0; i < sockets.size(); ++i)
zmq_close(sockets[i]);
zmq_ctx_destroy(ctx);
}
void test_zmq_default_max ()
{
// Keep allocating sockets until we hit the default zeromq limit
void *ctx = zmq_ctx_new();
std::vector<void*> sockets;
while (true)
{
void *socket = zmq_socket(ctx, ZMQ_PAIR);
if (!socket)
break;
sockets.push_back(socket);
}
for ( int i = 0; i < no_of_sockets; ++i ) assert(sockets.size() == ZMQ_MAX_SOCKETS_DFLT);
// At zeromq max, further calls to zmq_socket should return NULL.
for (unsigned int i = 0; i < 10; ++i)
{ {
sockets[i] = zmq_socket(ctx, ZMQ_PAIR); void *socket = zmq_socket(ctx, ZMQ_PAIR);
if (sockets[i]) assert(socket == NULL);
++sockets_created;
} }
assert(sockets_created < no_of_sockets); // Clean up.
for (unsigned int i = 0; i < sockets.size(); ++i)
zmq_close(sockets[i]);
zmq_ctx_destroy(ctx);
}
int main(void)
{
setup_test_environment();
for ( int i = 0; i < no_of_sockets; ++i ) test_system_max ();
if (sockets[i]) test_zmq_default_max ();
zmq_close (sockets[i]);
zmq_ctx_destroy (ctx);
return 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