Commit ba33fb74 authored by Ian Barber's avatar Ian Barber

Merge pull request #752 from ricnewton/master

Revert "Make FD_SETSIZE = ZMQ_MAX_SOCKETS_DFLT + 1 so there is room for ...
parents 51fa803d 5f8067cd
......@@ -269,7 +269,7 @@ if(MSVC)
-DWIN32
-DDLL_EXPORT
# NB: May require tweaking for highly connected applications.
-DFD_SETSIZE=1025
-DFD_SETSIZE=1024
-D_CRT_SECURE_NO_WARNINGS)
# Parallel make.
......
CC=gcc
CFLAGS=-Wall -Os -g -DDLL_EXPORT -DFD_SETSIZE=1025 -I.
CFLAGS=-Wall -Os -g -DDLL_EXPORT -DFD_SETSIZE=1024 -I.
LIBS=-lws2_32
OBJS = ctx.o reaper.o dist.o err.o \
......
......@@ -40,7 +40,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-DDLL_EXPORT -DFD_SETSIZE=1025 -D_CRT_SECURE_NO_WARNINGS"
AdditionalOptions="-DDLL_EXPORT -DFD_SETSIZE=1024 -D_CRT_SECURE_NO_WARNINGS"
Optimization="0"
PreprocessorDefinitions="NOMINMAX"
MinimalRebuild="true"
......@@ -114,7 +114,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-DDLL_EXPORT -DFD_SETSIZE=1025 -D_CRT_SECURE_NO_WARNINGS"
AdditionalOptions="-DDLL_EXPORT -DFD_SETSIZE=1024 -D_CRT_SECURE_NO_WARNINGS"
Optimization="2"
EnableIntrinsicFunctions="true"
RuntimeLibrary="2"
......@@ -188,7 +188,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-DZMQ_STATIC -DFD_SETSIZE=1025 -D_CRT_SECURE_NO_WARNINGS"
AdditionalOptions="-DZMQ_STATIC -DFD_SETSIZE=1024 -D_CRT_SECURE_NO_WARNINGS"
Optimization="0"
PreprocessorDefinitions="NOMINMAX"
MinimalRebuild="true"
......@@ -254,7 +254,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-DZMQ_STATIC -DFD_SETSIZE=1025 -D_CRT_SECURE_NO_WARNINGS"
AdditionalOptions="-DZMQ_STATIC -DFD_SETSIZE=1024 -D_CRT_SECURE_NO_WARNINGS"
Optimization="2"
EnableIntrinsicFunctions="true"
RuntimeLibrary="2"
......@@ -319,7 +319,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-DDLL_EXPORT -DFD_SETSIZE=1025 -D_CRT_SECURE_NO_WARNINGS"
AdditionalOptions="-DDLL_EXPORT -DFD_SETSIZE=1024 -D_CRT_SECURE_NO_WARNINGS"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../../../OpenPGM/include"
......
......@@ -13,7 +13,7 @@
<Command>copy ..\platform.hpp ..\..\..\src</Command>
</PreBuildEvent>
<ClCompile>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;DLL_EXPORT;FD_SETSIZE=1025;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;DLL_EXPORT;FD_SETSIZE=1024;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>Ws2_32.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
......
......@@ -13,7 +13,7 @@
<Command>copy ..\platform.hpp ..\..\..\src</Command>
</PreBuildEvent>
<ClCompile>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;ZMQ_STATIC;FD_SETSIZE=1025;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;ZMQ_STATIC;FD_SETSIZE=1024;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Lib>
<AdditionalDependencies>Ws2_32.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
......
......@@ -185,7 +185,7 @@ ZMQ_EXPORT const char *zmq_strerror (int errnum);
/* Default for new contexts */
#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 int zmq_ctx_term (void *context);
......
......@@ -21,32 +21,81 @@
#include <zmq.h>
#include <stdio.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();
zmq_ctx_set(ctx, ZMQ_MAX_SOCKETS, no_of_sockets);
void *sockets[no_of_sockets];
int sockets_created = 0;
std::vector<void*> sockets;
while (true)
{
void *socket = zmq_socket(ctx, ZMQ_PAIR);
if (!socket)
break;
sockets.push_back(socket);
}
assert((int)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);
if (sockets[i])
++sockets_created;
void *socket = zmq_socket(ctx, ZMQ_PAIR);
assert(socket == NULL);
}
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 )
if (sockets[i])
zmq_close (sockets[i]);
test_system_max ();
test_zmq_default_max ();
zmq_ctx_destroy (ctx);
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