Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
7c514294
Commit
7c514294
authored
Nov 11, 2013
by
Richard Newton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce default maximum number of sockets by 1 so there is room for the reaper socket.
parent
f77b96e4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
16 deletions
+65
-16
zmq.h
include/zmq.h
+1
-1
test_many_sockets.cpp
tests/test_many_sockets.cpp
+64
-15
No files found.
include/zmq.h
View file @
7c514294
...
...
@@ -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 102
4
#define ZMQ_MAX_SOCKETS_DFLT 102
3
ZMQ_EXPORT
void
*
zmq_ctx_new
(
void
);
ZMQ_EXPORT
int
zmq_ctx_term
(
void
*
context
);
...
...
tests/test_many_sockets.cpp
View file @
7c514294
...
...
@@ -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
(
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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment