Skip to content

Commit 5ba328d

Browse files
committed
Problem: there is no test for setsockopt ZMQ_TCP_SEND/RECV_BUFFER
Solution: add test case
1 parent f80faec commit 5ba328d

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ test_server_drop_more
114114
test_thread_safe
115115
test_thread_safe_polling
116116
test_getsockopt_memset
117+
test_setsockopt
117118
test_stream_exceeds_buffer
118119
test_poller
119120
tests/test*.log

Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ test_apps = \
351351
tests/test_proxy_single_socket \
352352
tests/test_proxy_terminate \
353353
tests/test_getsockopt_memset \
354+
tests/test_setsockopt \
354355
tests/test_many_sockets \
355356
tests/test_ipc_wildcard \
356357
tests/test_diffserv \
@@ -566,6 +567,9 @@ tests_test_thread_safe_LDADD = src/libzmq.la
566567
tests_test_socketopt_hwm_SOURCES = tests/test_sockopt_hwm.cpp
567568
tests_test_socketopt_hwm_LDADD = src/libzmq.la
568569

570+
tests_test_setsockopt_SOURCES = tests/test_setsockopt.cpp
571+
tests_test_setsockopt_LDADD = src/libzmq.la
572+
569573
tests_test_heartbeats_SOURCES = tests/test_heartbeats.cpp
570574
tests_test_heartbeats_LDADD = src/libzmq.la
571575

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ set(tests
5050
test_pub_invert_matching
5151
test_thread_safe
5252
test_client_server
53+
test_setsockopt
5354
test_sockopt_hwm
5455
test_heartbeats
5556
test_poller

tests/test_setsockopt.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include "testutil.hpp"
2+
3+
void test_setsockopt_tcp_recv_buffer()
4+
{
5+
int rc;
6+
void *ctx = zmq_ctx_new();
7+
void *socket = zmq_socket(ctx, ZMQ_PUSH);
8+
9+
int val = 0;
10+
size_t placeholder = sizeof(val);
11+
12+
rc = zmq_getsockopt(socket, ZMQ_TCP_RECV_BUFFER, &val, &placeholder);
13+
assert(rc == 0);
14+
assert(val == 8192);
15+
16+
rc = zmq_setsockopt(socket, ZMQ_TCP_RECV_BUFFER, &val, sizeof(val));
17+
assert(rc == 0);
18+
assert(val == 8192);
19+
20+
rc = zmq_getsockopt(socket, ZMQ_TCP_RECV_BUFFER, &val, &placeholder);
21+
assert(rc == 0);
22+
assert(val == 8192);
23+
24+
val = 16384;
25+
26+
rc = zmq_setsockopt(socket, ZMQ_TCP_RECV_BUFFER, &val, sizeof(val));
27+
assert(rc == 0);
28+
assert(val == 16384);
29+
30+
rc = zmq_getsockopt(socket, ZMQ_TCP_RECV_BUFFER, &val, &placeholder);
31+
assert(rc == 0);
32+
assert(val == 16384);
33+
34+
zmq_close(socket);
35+
zmq_ctx_term(ctx);
36+
}
37+
38+
void test_setsockopt_tcp_send_buffer()
39+
{
40+
int rc;
41+
void *ctx = zmq_ctx_new();
42+
void *socket = zmq_socket(ctx, ZMQ_PUSH);
43+
44+
int val = 0;
45+
size_t placeholder = sizeof(val);
46+
47+
rc = zmq_getsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, &placeholder);
48+
assert(rc == 0);
49+
assert(val == 8192);
50+
51+
rc = zmq_setsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, sizeof(val));
52+
assert(rc == 0);
53+
assert(val == 8192);
54+
55+
rc = zmq_getsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, &placeholder);
56+
assert(rc == 0);
57+
assert(val == 8192);
58+
59+
val = 16384;
60+
61+
rc = zmq_setsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, sizeof(val));
62+
assert(rc == 0);
63+
assert(val == 16384);
64+
65+
rc = zmq_getsockopt(socket, ZMQ_TCP_SEND_BUFFER, &val, &placeholder);
66+
assert(rc == 0);
67+
assert(val == 16384);
68+
69+
zmq_close(socket);
70+
zmq_ctx_term(ctx);
71+
}
72+
73+
74+
int main()
75+
{
76+
test_setsockopt_tcp_recv_buffer();
77+
test_setsockopt_tcp_send_buffer();
78+
}

0 commit comments

Comments
 (0)