Skip to content

Commit 7ea3905

Browse files
committed
sockopt update to czmq/v4.0.0
1 parent d63b88f commit 7ea3905

File tree

4 files changed

+903
-1
lines changed

4 files changed

+903
-1
lines changed

options/generate.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ WGET=$(which wget)
44
GSL=$(which gsl)
55
GIT=$(which git)
66

7+
cd `dirname "$0"`
8+
79
if test "$WGET" = ""
810
then
911
echo "wget not found"
@@ -22,7 +24,12 @@ then
2224
exit 1
2325
fi
2426

25-
$WGET https://raw.githubusercontent.com/zeromq/czmq/master/src/sockopts.xml -O sockopts.xml
27+
# latest version supported
28+
$WGET https://raw.githubusercontent.com/zeromq/czmq/v4.0.0/src/sockopts.xml -O sockopts.xml
29+
30+
# not yet working
31+
# $WGET https://raw.githubusercontent.com/zeromq/czmq/master/src/sockopts.xml -O sockopts.xml
32+
2633
git diff sockopts.xml
2734

2835
$GSL -script:sockopts.gsl sockopts.xml

options/sockopts.xml

+52
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,64 @@
1616
test_value = "4000" />
1717
<option name = "heartbeat_timeout" type = "int" mode = "rw" test = "DEALER"
1818
test_value = "6000" />
19+
<option name = "use_fd" type = "int" mode = "rw" test = "REQ"
20+
test_value = "3" />
21+
<option name = "xpub_manual" type = "int" mode = "w" test = "XPUB"
22+
test_value = "1" >
23+
<restrict type = "XPUB" />
24+
</option>
25+
<option name = "xpub_welcome_msg" type = "string" mode = "w" test = "XPUB"
26+
test_value = "welcome" >
27+
<restrict type = "XPUB" />
28+
</option>
29+
<option name = "stream_notify" type = "int" mode = "w" test = "STREAM"
30+
test_value = "1" >
31+
<restrict type = "STREAM" />
32+
</option>
33+
<option name = "invert_matching" type = "int" mode = "rw" test = "XPUB"
34+
test_value = "1" >
35+
<restrict type = "XPUB" />
36+
<restrict type = "PUB" />
37+
<restrict type = "SUB" />
38+
</option>
39+
<option name = "xpub_verboser" type = "int" mode = "w" test = "XPUB"
40+
test_value = "1" >
41+
<restrict type = "XPUB" />
42+
</option>
43+
<option name = "connect_timeout" type = "int" mode = "rw" test = "DEALER"
44+
test_value = "200" />
45+
<option name = "tcp_maxrt" type = "int" mode = "rw" test = "DEALER"
46+
test_value = "200" />
47+
<option name = "thread_safe" type = "int" mode = "r" test = "DEALER"
48+
test_value = "0" />
49+
<option name = "multicast_maxtpdu" type = "int" mode = "rw" test = "DEALER"
50+
test_value = "1400" />
51+
52+
<!-- We don't test these as libzmq doesn't always support VMCI -->
53+
<option name = "vmci_buffer_size" type = "uint64" mode = "rw" />
54+
<option name = "vmci_buffer_min_size" type = "uint64" mode = "rw" />
55+
<option name = "vmci_buffer_max_size" type = "uint64" mode = "rw" />
56+
<option name = "vmci_connect_timeout" type = "int" mode = "rw" />
1957

2058
<!-- Options that are new in 4.1 -->
2159
<option name = "tos" type = "int" mode = "rw" test = "DEALER" />
2260
<option name = "router_handover" type = "int" mode = "w" test = "ROUTER">
2361
<restrict type = "ROUTER" />
2462
</option>
63+
<option name = "connect_rid" type = "key" mode = "w" test = "ROUTER"
64+
test_value = "ABCD" >
65+
<restrict type = "ROUTER" />
66+
<restrict type = "STREAM" />
67+
</option>
68+
<option name = "handshake_ivl" type = "int" mode = "rw" test = "DEALER"
69+
test_value = "200" />
70+
<option name = "socks_proxy" type = "string" mode = "rw" test = "DEALER"
71+
test_value = "127.0.0.1" />
72+
<option name = "xpub_nodrop" type = "int" mode = "w" test = "XPUB"
73+
test_value = "1" >
74+
<restrict type = "XPUB" />
75+
<restrict type = "PUB" />
76+
</option>
2577

2678
<!-- Options that are new in 4.0 -->
2779
<option name = "router_mandatory" type = "int" mode = "w" test = "ROUTER">

tests/libzmq4-sockopt.phpt

+234
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,174 @@ if (defined ("ZMQ::SOCKOPT_HEARTBEAT_TIMEOUT")) {
6262
$tested++;
6363

6464

65+
}
66+
/* socket option is marked mode="rw" type=int php_type=int */
67+
if (defined ("ZMQ::SOCKOPT_USE_FD")) {
68+
$test_value = 3;
69+
70+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_REQ);
71+
72+
// Test read-write
73+
$socket->setSockOpt(ZMQ::SOCKOPT_USE_FD, $test_value);
74+
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_USE_FD);
75+
76+
if ($socket->getSockOpt(ZMQ::SOCKOPT_USE_FD) !== $test_value) {
77+
echo "Failed to set ZMQ::SOCKOPT_USE_FD: expected=[$test_value] actual=[$retval]" . PHP_EOL;
78+
}
79+
$tested++;
80+
81+
82+
}
83+
/* socket option is marked mode="w" type=int php_type=int */
84+
if (defined ("ZMQ::SOCKOPT_XPUB_MANUAL")) {
85+
$test_value = 1;
86+
87+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);
88+
89+
// Test write-only
90+
$socket->setSockOpt(ZMQ::SOCKOPT_XPUB_MANUAL, $test_value);
91+
$tested++;
92+
93+
try {
94+
$socket->getSockOpt(ZMQ::SOCKOPT_XPUB_MANUAL);
95+
echo "Should not be able to get ZMQ::SOCKOPT_XPUB_MANUAL" . PHP_EOL;
96+
} catch (ZMQSocketException $e) {}
97+
98+
}
99+
/* socket option is marked mode="w" type=string php_type=string */
100+
if (defined ("ZMQ::SOCKOPT_XPUB_WELCOME_MSG")) {
101+
$test_value = "welcome";
102+
103+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);
104+
105+
// Test write-only
106+
$socket->setSockOpt(ZMQ::SOCKOPT_XPUB_WELCOME_MSG, $test_value);
107+
$tested++;
108+
109+
try {
110+
$socket->getSockOpt(ZMQ::SOCKOPT_XPUB_WELCOME_MSG);
111+
echo "Should not be able to get ZMQ::SOCKOPT_XPUB_WELCOME_MSG" . PHP_EOL;
112+
} catch (ZMQSocketException $e) {}
113+
114+
}
115+
/* socket option is marked mode="w" type=int php_type=int */
116+
if (defined ("ZMQ::SOCKOPT_STREAM_NOTIFY")) {
117+
$test_value = 1;
118+
119+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_STREAM);
120+
121+
// Test write-only
122+
$socket->setSockOpt(ZMQ::SOCKOPT_STREAM_NOTIFY, $test_value);
123+
$tested++;
124+
125+
try {
126+
$socket->getSockOpt(ZMQ::SOCKOPT_STREAM_NOTIFY);
127+
echo "Should not be able to get ZMQ::SOCKOPT_STREAM_NOTIFY" . PHP_EOL;
128+
} catch (ZMQSocketException $e) {}
129+
130+
}
131+
/* socket option is marked mode="rw" type=int php_type=int */
132+
if (defined ("ZMQ::SOCKOPT_INVERT_MATCHING")) {
133+
$test_value = 1;
134+
135+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);
136+
137+
// Test read-write
138+
$socket->setSockOpt(ZMQ::SOCKOPT_INVERT_MATCHING, $test_value);
139+
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_INVERT_MATCHING);
140+
141+
if ($socket->getSockOpt(ZMQ::SOCKOPT_INVERT_MATCHING) !== $test_value) {
142+
echo "Failed to set ZMQ::SOCKOPT_INVERT_MATCHING: expected=[$test_value] actual=[$retval]" . PHP_EOL;
143+
}
144+
$tested++;
145+
146+
147+
}
148+
/* socket option is marked mode="w" type=int php_type=int */
149+
if (defined ("ZMQ::SOCKOPT_XPUB_VERBOSER")) {
150+
$test_value = 1;
151+
152+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);
153+
154+
// Test write-only
155+
$socket->setSockOpt(ZMQ::SOCKOPT_XPUB_VERBOSER, $test_value);
156+
$tested++;
157+
158+
try {
159+
$socket->getSockOpt(ZMQ::SOCKOPT_XPUB_VERBOSER);
160+
echo "Should not be able to get ZMQ::SOCKOPT_XPUB_VERBOSER" . PHP_EOL;
161+
} catch (ZMQSocketException $e) {}
162+
163+
}
164+
/* socket option is marked mode="rw" type=int php_type=int */
165+
if (defined ("ZMQ::SOCKOPT_CONNECT_TIMEOUT")) {
166+
$test_value = 200;
167+
168+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);
169+
170+
// Test read-write
171+
$socket->setSockOpt(ZMQ::SOCKOPT_CONNECT_TIMEOUT, $test_value);
172+
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_CONNECT_TIMEOUT);
173+
174+
if ($socket->getSockOpt(ZMQ::SOCKOPT_CONNECT_TIMEOUT) !== $test_value) {
175+
echo "Failed to set ZMQ::SOCKOPT_CONNECT_TIMEOUT: expected=[$test_value] actual=[$retval]" . PHP_EOL;
176+
}
177+
$tested++;
178+
179+
180+
}
181+
/* socket option is marked mode="rw" type=int php_type=int */
182+
if (defined ("ZMQ::SOCKOPT_TCP_MAXRT")) {
183+
$test_value = 200;
184+
185+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);
186+
187+
// Test read-write
188+
$socket->setSockOpt(ZMQ::SOCKOPT_TCP_MAXRT, $test_value);
189+
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_MAXRT);
190+
191+
if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_MAXRT) !== $test_value) {
192+
echo "Failed to set ZMQ::SOCKOPT_TCP_MAXRT: expected=[$test_value] actual=[$retval]" . PHP_EOL;
193+
}
194+
$tested++;
195+
196+
197+
}
198+
/* socket option is marked mode="r" type=int php_type=int */
199+
if (defined ("ZMQ::SOCKOPT_THREAD_SAFE")) {
200+
$test_value = 0;
201+
202+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);
203+
204+
// Test read-only
205+
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_THREAD_SAFE);
206+
if (is_int($retval) === false) {
207+
echo "Incorrect return type for ZMQ::SOCKOPT_THREAD_SAFE: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL;
208+
}
209+
$tested++;
210+
211+
try {
212+
$socket->setSockOpt(ZMQ::SOCKOPT_THREAD_SAFE, 'x');
213+
echo "Should not be able to set ZMQ::SOCKOPT_THREAD_SAFE" . PHP_EOL;
214+
} catch (ZMQSocketException $e) {}
215+
216+
}
217+
/* socket option is marked mode="rw" type=int php_type=int */
218+
if (defined ("ZMQ::SOCKOPT_MULTICAST_MAXTPDU")) {
219+
$test_value = 1400;
220+
221+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);
222+
223+
// Test read-write
224+
$socket->setSockOpt(ZMQ::SOCKOPT_MULTICAST_MAXTPDU, $test_value);
225+
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_MULTICAST_MAXTPDU);
226+
227+
if ($socket->getSockOpt(ZMQ::SOCKOPT_MULTICAST_MAXTPDU) !== $test_value) {
228+
echo "Failed to set ZMQ::SOCKOPT_MULTICAST_MAXTPDU: expected=[$test_value] actual=[$retval]" . PHP_EOL;
229+
}
230+
$tested++;
231+
232+
65233
}
66234
/* socket option is marked mode="rw" type=int php_type=int */
67235
if (defined ("ZMQ::SOCKOPT_TOS")) {
@@ -95,6 +263,72 @@ if (defined ("ZMQ::SOCKOPT_ROUTER_HANDOVER")) {
95263
echo "Should not be able to get ZMQ::SOCKOPT_ROUTER_HANDOVER" . PHP_EOL;
96264
} catch (ZMQSocketException $e) {}
97265

266+
}
267+
/* socket option is marked mode="w" type=key php_type=string */
268+
if (defined ("ZMQ::SOCKOPT_CONNECT_RID")) {
269+
$test_value = "ABCD";
270+
271+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_ROUTER);
272+
273+
// Test write-only
274+
$socket->setSockOpt(ZMQ::SOCKOPT_CONNECT_RID, $test_value);
275+
$tested++;
276+
277+
try {
278+
$socket->getSockOpt(ZMQ::SOCKOPT_CONNECT_RID);
279+
echo "Should not be able to get ZMQ::SOCKOPT_CONNECT_RID" . PHP_EOL;
280+
} catch (ZMQSocketException $e) {}
281+
282+
}
283+
/* socket option is marked mode="rw" type=int php_type=int */
284+
if (defined ("ZMQ::SOCKOPT_HANDSHAKE_IVL")) {
285+
$test_value = 200;
286+
287+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);
288+
289+
// Test read-write
290+
$socket->setSockOpt(ZMQ::SOCKOPT_HANDSHAKE_IVL, $test_value);
291+
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_HANDSHAKE_IVL);
292+
293+
if ($socket->getSockOpt(ZMQ::SOCKOPT_HANDSHAKE_IVL) !== $test_value) {
294+
echo "Failed to set ZMQ::SOCKOPT_HANDSHAKE_IVL: expected=[$test_value] actual=[$retval]" . PHP_EOL;
295+
}
296+
$tested++;
297+
298+
299+
}
300+
/* socket option is marked mode="rw" type=string php_type=string */
301+
if (defined ("ZMQ::SOCKOPT_SOCKS_PROXY")) {
302+
$test_value = "127.0.0.1";
303+
304+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);
305+
306+
// Test read-write
307+
$socket->setSockOpt(ZMQ::SOCKOPT_SOCKS_PROXY, $test_value);
308+
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_SOCKS_PROXY);
309+
310+
if ($socket->getSockOpt(ZMQ::SOCKOPT_SOCKS_PROXY) !== $test_value) {
311+
echo "Failed to set ZMQ::SOCKOPT_SOCKS_PROXY: expected=[$test_value] actual=[$retval]" . PHP_EOL;
312+
}
313+
$tested++;
314+
315+
316+
}
317+
/* socket option is marked mode="w" type=int php_type=int */
318+
if (defined ("ZMQ::SOCKOPT_XPUB_NODROP")) {
319+
$test_value = 1;
320+
321+
$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);
322+
323+
// Test write-only
324+
$socket->setSockOpt(ZMQ::SOCKOPT_XPUB_NODROP, $test_value);
325+
$tested++;
326+
327+
try {
328+
$socket->getSockOpt(ZMQ::SOCKOPT_XPUB_NODROP);
329+
echo "Should not be able to get ZMQ::SOCKOPT_XPUB_NODROP" . PHP_EOL;
330+
} catch (ZMQSocketException $e) {}
331+
98332
}
99333
/* socket option is marked mode="w" type=int php_type=int */
100334
if (defined ("ZMQ::SOCKOPT_ROUTER_MANDATORY")) {

0 commit comments

Comments
 (0)