Skip to content

Commit

Permalink
sockopt update to czmq/v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zebastian committed Feb 14, 2020
1 parent d63b88f commit 7ea3905
Show file tree
Hide file tree
Showing 4 changed files with 903 additions and 1 deletion.
9 changes: 8 additions & 1 deletion options/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ WGET=$(which wget)
GSL=$(which gsl)
GIT=$(which git)

cd `dirname "$0"`

if test "$WGET" = ""
then
echo "wget not found"
Expand All @@ -22,7 +24,12 @@ then
exit 1
fi

$WGET https://raw.githubusercontent.com/zeromq/czmq/master/src/sockopts.xml -O sockopts.xml
# latest version supported
$WGET https://raw.githubusercontent.com/zeromq/czmq/v4.0.0/src/sockopts.xml -O sockopts.xml

# not yet working
# $WGET https://raw.githubusercontent.com/zeromq/czmq/master/src/sockopts.xml -O sockopts.xml

git diff sockopts.xml

$GSL -script:sockopts.gsl sockopts.xml
Expand Down
52 changes: 52 additions & 0 deletions options/sockopts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,64 @@
test_value = "4000" />
<option name = "heartbeat_timeout" type = "int" mode = "rw" test = "DEALER"
test_value = "6000" />
<option name = "use_fd" type = "int" mode = "rw" test = "REQ"
test_value = "3" />
<option name = "xpub_manual" type = "int" mode = "w" test = "XPUB"
test_value = "1" >
<restrict type = "XPUB" />
</option>
<option name = "xpub_welcome_msg" type = "string" mode = "w" test = "XPUB"
test_value = "welcome" >
<restrict type = "XPUB" />
</option>
<option name = "stream_notify" type = "int" mode = "w" test = "STREAM"
test_value = "1" >
<restrict type = "STREAM" />
</option>
<option name = "invert_matching" type = "int" mode = "rw" test = "XPUB"
test_value = "1" >
<restrict type = "XPUB" />
<restrict type = "PUB" />
<restrict type = "SUB" />
</option>
<option name = "xpub_verboser" type = "int" mode = "w" test = "XPUB"
test_value = "1" >
<restrict type = "XPUB" />
</option>
<option name = "connect_timeout" type = "int" mode = "rw" test = "DEALER"
test_value = "200" />
<option name = "tcp_maxrt" type = "int" mode = "rw" test = "DEALER"
test_value = "200" />
<option name = "thread_safe" type = "int" mode = "r" test = "DEALER"
test_value = "0" />
<option name = "multicast_maxtpdu" type = "int" mode = "rw" test = "DEALER"
test_value = "1400" />

<!-- We don't test these as libzmq doesn't always support VMCI -->
<option name = "vmci_buffer_size" type = "uint64" mode = "rw" />
<option name = "vmci_buffer_min_size" type = "uint64" mode = "rw" />
<option name = "vmci_buffer_max_size" type = "uint64" mode = "rw" />
<option name = "vmci_connect_timeout" type = "int" mode = "rw" />

<!-- Options that are new in 4.1 -->
<option name = "tos" type = "int" mode = "rw" test = "DEALER" />
<option name = "router_handover" type = "int" mode = "w" test = "ROUTER">
<restrict type = "ROUTER" />
</option>
<option name = "connect_rid" type = "key" mode = "w" test = "ROUTER"
test_value = "ABCD" >
<restrict type = "ROUTER" />
<restrict type = "STREAM" />
</option>
<option name = "handshake_ivl" type = "int" mode = "rw" test = "DEALER"
test_value = "200" />
<option name = "socks_proxy" type = "string" mode = "rw" test = "DEALER"
test_value = "127.0.0.1" />
<option name = "xpub_nodrop" type = "int" mode = "w" test = "XPUB"
test_value = "1" >
<restrict type = "XPUB" />
<restrict type = "PUB" />
</option>

<!-- Options that are new in 4.0 -->
<option name = "router_mandatory" type = "int" mode = "w" test = "ROUTER">
Expand Down
234 changes: 234 additions & 0 deletions tests/libzmq4-sockopt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,174 @@ if (defined ("ZMQ::SOCKOPT_HEARTBEAT_TIMEOUT")) {
$tested++;


}
/* socket option is marked mode="rw" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_USE_FD")) {
$test_value = 3;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_REQ);

// Test read-write
$socket->setSockOpt(ZMQ::SOCKOPT_USE_FD, $test_value);
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_USE_FD);

if ($socket->getSockOpt(ZMQ::SOCKOPT_USE_FD) !== $test_value) {
echo "Failed to set ZMQ::SOCKOPT_USE_FD: expected=[$test_value] actual=[$retval]" . PHP_EOL;
}
$tested++;


}
/* socket option is marked mode="w" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_XPUB_MANUAL")) {
$test_value = 1;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);

// Test write-only
$socket->setSockOpt(ZMQ::SOCKOPT_XPUB_MANUAL, $test_value);
$tested++;

try {
$socket->getSockOpt(ZMQ::SOCKOPT_XPUB_MANUAL);
echo "Should not be able to get ZMQ::SOCKOPT_XPUB_MANUAL" . PHP_EOL;
} catch (ZMQSocketException $e) {}

}
/* socket option is marked mode="w" type=string php_type=string */
if (defined ("ZMQ::SOCKOPT_XPUB_WELCOME_MSG")) {
$test_value = "welcome";

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);

// Test write-only
$socket->setSockOpt(ZMQ::SOCKOPT_XPUB_WELCOME_MSG, $test_value);
$tested++;

try {
$socket->getSockOpt(ZMQ::SOCKOPT_XPUB_WELCOME_MSG);
echo "Should not be able to get ZMQ::SOCKOPT_XPUB_WELCOME_MSG" . PHP_EOL;
} catch (ZMQSocketException $e) {}

}
/* socket option is marked mode="w" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_STREAM_NOTIFY")) {
$test_value = 1;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_STREAM);

// Test write-only
$socket->setSockOpt(ZMQ::SOCKOPT_STREAM_NOTIFY, $test_value);
$tested++;

try {
$socket->getSockOpt(ZMQ::SOCKOPT_STREAM_NOTIFY);
echo "Should not be able to get ZMQ::SOCKOPT_STREAM_NOTIFY" . PHP_EOL;
} catch (ZMQSocketException $e) {}

}
/* socket option is marked mode="rw" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_INVERT_MATCHING")) {
$test_value = 1;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);

// Test read-write
$socket->setSockOpt(ZMQ::SOCKOPT_INVERT_MATCHING, $test_value);
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_INVERT_MATCHING);

if ($socket->getSockOpt(ZMQ::SOCKOPT_INVERT_MATCHING) !== $test_value) {
echo "Failed to set ZMQ::SOCKOPT_INVERT_MATCHING: expected=[$test_value] actual=[$retval]" . PHP_EOL;
}
$tested++;


}
/* socket option is marked mode="w" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_XPUB_VERBOSER")) {
$test_value = 1;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);

// Test write-only
$socket->setSockOpt(ZMQ::SOCKOPT_XPUB_VERBOSER, $test_value);
$tested++;

try {
$socket->getSockOpt(ZMQ::SOCKOPT_XPUB_VERBOSER);
echo "Should not be able to get ZMQ::SOCKOPT_XPUB_VERBOSER" . PHP_EOL;
} catch (ZMQSocketException $e) {}

}
/* socket option is marked mode="rw" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_CONNECT_TIMEOUT")) {
$test_value = 200;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);

// Test read-write
$socket->setSockOpt(ZMQ::SOCKOPT_CONNECT_TIMEOUT, $test_value);
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_CONNECT_TIMEOUT);

if ($socket->getSockOpt(ZMQ::SOCKOPT_CONNECT_TIMEOUT) !== $test_value) {
echo "Failed to set ZMQ::SOCKOPT_CONNECT_TIMEOUT: expected=[$test_value] actual=[$retval]" . PHP_EOL;
}
$tested++;


}
/* socket option is marked mode="rw" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_TCP_MAXRT")) {
$test_value = 200;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);

// Test read-write
$socket->setSockOpt(ZMQ::SOCKOPT_TCP_MAXRT, $test_value);
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_TCP_MAXRT);

if ($socket->getSockOpt(ZMQ::SOCKOPT_TCP_MAXRT) !== $test_value) {
echo "Failed to set ZMQ::SOCKOPT_TCP_MAXRT: expected=[$test_value] actual=[$retval]" . PHP_EOL;
}
$tested++;


}
/* socket option is marked mode="r" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_THREAD_SAFE")) {
$test_value = 0;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);

// Test read-only
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_THREAD_SAFE);
if (is_int($retval) === false) {
echo "Incorrect return type for ZMQ::SOCKOPT_THREAD_SAFE: expected=[int] actual=[" .gettype($retval). "]" . PHP_EOL;
}
$tested++;

try {
$socket->setSockOpt(ZMQ::SOCKOPT_THREAD_SAFE, 'x');
echo "Should not be able to set ZMQ::SOCKOPT_THREAD_SAFE" . PHP_EOL;
} catch (ZMQSocketException $e) {}

}
/* socket option is marked mode="rw" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_MULTICAST_MAXTPDU")) {
$test_value = 1400;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);

// Test read-write
$socket->setSockOpt(ZMQ::SOCKOPT_MULTICAST_MAXTPDU, $test_value);
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_MULTICAST_MAXTPDU);

if ($socket->getSockOpt(ZMQ::SOCKOPT_MULTICAST_MAXTPDU) !== $test_value) {
echo "Failed to set ZMQ::SOCKOPT_MULTICAST_MAXTPDU: expected=[$test_value] actual=[$retval]" . PHP_EOL;
}
$tested++;


}
/* socket option is marked mode="rw" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_TOS")) {
Expand Down Expand Up @@ -95,6 +263,72 @@ if (defined ("ZMQ::SOCKOPT_ROUTER_HANDOVER")) {
echo "Should not be able to get ZMQ::SOCKOPT_ROUTER_HANDOVER" . PHP_EOL;
} catch (ZMQSocketException $e) {}

}
/* socket option is marked mode="w" type=key php_type=string */
if (defined ("ZMQ::SOCKOPT_CONNECT_RID")) {
$test_value = "ABCD";

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_ROUTER);

// Test write-only
$socket->setSockOpt(ZMQ::SOCKOPT_CONNECT_RID, $test_value);
$tested++;

try {
$socket->getSockOpt(ZMQ::SOCKOPT_CONNECT_RID);
echo "Should not be able to get ZMQ::SOCKOPT_CONNECT_RID" . PHP_EOL;
} catch (ZMQSocketException $e) {}

}
/* socket option is marked mode="rw" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_HANDSHAKE_IVL")) {
$test_value = 200;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);

// Test read-write
$socket->setSockOpt(ZMQ::SOCKOPT_HANDSHAKE_IVL, $test_value);
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_HANDSHAKE_IVL);

if ($socket->getSockOpt(ZMQ::SOCKOPT_HANDSHAKE_IVL) !== $test_value) {
echo "Failed to set ZMQ::SOCKOPT_HANDSHAKE_IVL: expected=[$test_value] actual=[$retval]" . PHP_EOL;
}
$tested++;


}
/* socket option is marked mode="rw" type=string php_type=string */
if (defined ("ZMQ::SOCKOPT_SOCKS_PROXY")) {
$test_value = "127.0.0.1";

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_DEALER);

// Test read-write
$socket->setSockOpt(ZMQ::SOCKOPT_SOCKS_PROXY, $test_value);
$retval = $socket->getSockOpt(ZMQ::SOCKOPT_SOCKS_PROXY);

if ($socket->getSockOpt(ZMQ::SOCKOPT_SOCKS_PROXY) !== $test_value) {
echo "Failed to set ZMQ::SOCKOPT_SOCKS_PROXY: expected=[$test_value] actual=[$retval]" . PHP_EOL;
}
$tested++;


}
/* socket option is marked mode="w" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_XPUB_NODROP")) {
$test_value = 1;

$socket = ZMQContext::acquire()->getSocket(ZMQ::SOCKET_XPUB);

// Test write-only
$socket->setSockOpt(ZMQ::SOCKOPT_XPUB_NODROP, $test_value);
$tested++;

try {
$socket->getSockOpt(ZMQ::SOCKOPT_XPUB_NODROP);
echo "Should not be able to get ZMQ::SOCKOPT_XPUB_NODROP" . PHP_EOL;
} catch (ZMQSocketException $e) {}

}
/* socket option is marked mode="w" type=int php_type=int */
if (defined ("ZMQ::SOCKOPT_ROUTER_MANDATORY")) {
Expand Down
Loading

0 comments on commit 7ea3905

Please sign in to comment.