Skip to content

Commit 2f23b19

Browse files
committed
Added new stuff
1 parent 9f23b02 commit 2f23b19

File tree

11 files changed

+616
-160
lines changed

11 files changed

+616
-160
lines changed

config.m4

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,73 @@ if test "$PHP_ZMQ" != "no"; then
3838

3939
AC_MSG_RESULT([found version $PHP_ZMQ_VERSION, under $PHP_ZMQ_PREFIX])
4040
PHP_ZMQ_LIBS=`$PKG_CONFIG libzmq --libs`
41-
PHP_ZMQ_INCS=`$PKG_CONFIG libzmq --cflags`
41+
PHP_ZMQ_CFLAGS=`$PKG_CONFIG libzmq --cflags`
4242

4343
PHP_EVAL_LIBLINE($PHP_ZMQ_LIBS, ZMQ_SHARED_LIBADD)
44-
PHP_EVAL_INCLINE($PHP_ZMQ_INCS)
44+
PHP_EVAL_INCLINE($PHP_ZMQ_CFLAGS)
4545
else
4646
AC_MSG_ERROR(Unable to find libzmq installation)
4747
fi
4848

49+
# Test functions
50+
ORIG_CFLAGS="$CFLAGS"
51+
ORIG_LDFLAGS="$LDFLAGS"
52+
53+
CFLAGS="$CFLAGS $PHP_ZMQ_CFLAGS"
54+
LDFLAGS="$LDFLAGS $PHP_ZMQ_LIBS"
55+
56+
AC_CHECK_LIB(
57+
[zmq], [zmq_socket_monitor],
58+
[AC_DEFINE(
59+
[PHP_ZMQ_HAVE_SOCKET_MONITOR], [1], [Whether zmq_socket_monitor function is available]
60+
)]
61+
)
62+
63+
AC_CHECK_LIB(
64+
[zmq], [zmq_proxy_steerable],
65+
[AC_DEFINE(
66+
[PHP_ZMQ_HAVE_PROXY_STEERABLE], [1], [Whether zmq_proxy_steerable function is available]
67+
)]
68+
)
69+
70+
AC_CHECK_LIB(
71+
[zmq], [zmq_z85_decode],
72+
[AC_DEFINE(
73+
[PHP_ZMQ_HAVE_Z85], [1], [Whether zmq_z85_decode function is available]
74+
)]
75+
)
76+
77+
AC_CHECK_LIB(
78+
[zmq], [zmq_curve_keypair],
79+
[AC_DEFINE(
80+
[PHP_ZMQ_HAVE_CURVE_KEYPAIR], [1], [Whether zmq_curve_keypair function is available]
81+
)]
82+
)
83+
84+
AC_CHECK_LIB(
85+
[zmq], [zmq_ctx_get],
86+
[AC_DEFINE(
87+
[PHP_ZMQ_HAVE_CTX_OPTIONS], [1], [Whether zmq_ctx_get/set is available]
88+
)]
89+
)
90+
91+
AC_CHECK_LIB(
92+
[zmq], [zmq_unbind],
93+
[AC_DEFINE(
94+
[PHP_ZMQ_HAVE_UNBIND], [1], [Whether zmq_unbind function is available]
95+
)]
96+
)
97+
98+
AC_CHECK_LIB(
99+
[zmq], [zmq_disconnect],
100+
[AC_DEFINE(
101+
[PHP_ZMQ_HAVE_DISCONNECT], [1], [Whether zmq_disconnect function is available]
102+
)]
103+
)
104+
105+
CFLAGS="$ORIG_CFLAGS"
106+
LDFLAGS="$ORIG_LDFLAGS"
107+
49108
if test "$PHP_CZMQ" != "no"; then
50109
if test "x$PHP_CZMQ" != "xyes"; then
51110
export PKG_CONFIG_PATH="${PHP_CZMQ}/${PHP_LIBDIR}/pkgconfig:${PHP_ZMQ_EXPLICIT_PKG_CONFIG_PATH}"
@@ -99,7 +158,7 @@ if test "$PHP_ZMQ" != "no"; then
99158
PHP_ADD_BUILD_DIR($abs_builddir/$subdir, 1)
100159
PHP_NEW_EXTENSION(zmq, $subdir/zmq.c $subdir/zmq_pollset.c $subdir/zmq_device.c $subdir/zmq_sockopt.c $subdir/zmq_fd_stream.c $subdir/zmq_clock.c, $ext_shared)
101160
else
102-
PHP_NEW_EXTENSION(zmq, zmq.c zmq_helpers.c zmq_pollset.c zmq_device.c zmq_sockopt.c zmq_fd_stream.c zmq_clock.c, $ext_shared)
161+
PHP_NEW_EXTENSION(zmq, zmq.c zmq_helpers.c zmq_pollset.c zmq_device.c zmq_sockopt.c zmq_fd_stream.c zmq_clock.c zmq_shared_ctx.c, $ext_shared)
103162
fi
104163
PKG_CONFIG_PATH="$ORIG_PKG_CONFIG_PATH"
105164
fi

config.w32

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ if (PHP_ZMQ != "no") {
55
if (CHECK_HEADER_ADD_INCLUDE("zmq.h", "CFLAGS_ZMQ", PHP_PHP_BUILD + "\\include;" + PHP_ZMQ)
66
&& CHECK_LIB("libzmq.lib", "zmq", PHP_PHP_BUILD + "\\lib;" + PHP_ZMQ))
77
{
8-
EXTENSION('zmq', 'zmq.c zmq_pollset.c zmq_device.c zmq_sockopt.c zmq_fd_stream.c zmq_clock.c');
8+
EXTENSION('zmq', 'zmq.c zmq_helpers.c zmq_pollset.c zmq_device.c zmq_sockopt.c zmq_fd_stream.c zmq_clock.c zmq_shared_ctx.c');
99
AC_DEFINE('HAVE_ZMQ', 1);
10+
AC_DEFINE('PHP_ZMQ_HAVE_SOCKET_MONITOR', 1);
11+
AC_DEFINE('PHP_ZMQ_HAVE_PROXY_STEERABLE', 1);
12+
AC_DEFINE('PHP_ZMQ_HAVE_Z85', 1);
13+
AC_DEFINE('PHP_ZMQ_HAVE_CURVE_KEYPAIR', 1);
14+
AC_DEFINE('PHP_ZMQ_HAVE_CTX_OPTIONS', 1);
15+
AC_DEFINE('PHP_ZMQ_HAVE_UNBIND', 1);
16+
AC_DEFINE('PHP_ZMQ_HAVE_DISCONNECT', 1);
1017
} else {
1118
WARNING("zmq not enabled; libraries and headers not found");
1219
}

options/generate.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
WGET=$(which wget)
4+
GSL=$(which gsl)
5+
GIT=$(which git)
6+
7+
if test "$WGET" = ""
8+
then
9+
echo "wget not found"
10+
exit 1
11+
fi
12+
13+
if test "$GSL" = ""
14+
then
15+
echo "gsl not found"
16+
exit 1
17+
fi
18+
19+
if test "$GIT" = ""
20+
then
21+
echo "git not found"
22+
exit 1
23+
fi
24+
25+
$WGET https://raw.githubusercontent.com/zeromq/czmq/master/src/sockopts.xml -O sockopts.xml
26+
git diff sockopts.xml
27+
28+
$GSL -script:sockopts.gsl sockopts.xml
29+
$GSL -script:sockopts_test.gsl sockopts.xml

options/sockopts_restrict.gsl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.# This is a code generator built using the iMatix GSL code generation
2+
.# language. See https://github.com/imatix/gsl for details. This script
3+
.# is licensed under MIT/X11.
4+
.#
5+
.template 1
6+
.if count (restrict)
7+
{
8+
. for restrict
9+
. if first()
10+
. .open = "if ("
11+
. else
12+
. .open = " "
13+
. endif
14+
. if last()
15+
. .close = ") {"
16+
. else
17+
. .close = " &&"
18+
. endif
19+
$(open)intern->socket->socket_type != ZMQ_$(TYPE)$(close)
20+
. endfor
21+
zend_throw_exception(php_zmq_socket_exception_sc_entry_get (), "ZMQ::SOCKOPT_$(NAME) is not valid for this socket type", errno);
22+
return;
23+
}
24+
}
25+
.endif
26+
.endtemplate

package.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<email>mkoppanen@php.net</email>
1111
<active>yes</active>
1212
</lead>
13-
<date>2016-01-14</date>
13+
<date>2016-01-21</date>
1414
<time>17:00:00</time>
1515
<version>
16-
<release>1.1.3</release>
16+
<release>1.1.4</release>
1717
<api>1.1.0</api>
1818
</version>
1919
<stability>
@@ -22,7 +22,8 @@
2222
</stability>
2323
<license>BSD License</license>
2424
<notes>
25-
- Fixes a bug where device callback was invoked too early
25+
- Introduces PHP7 support
26+
- Added methods: ZMQSocket::monitor, ZMQSocket::recvEvent, ZMQ::has
2627
</notes>
2728
<contents>
2829
<dir name="/">
@@ -49,7 +50,8 @@
4950
<file name="zmq_clock.c" role="src" />
5051
<file name="zmq_object_access.c" role="src" />
5152
<file name="zmq_helpers.c" role="src" />
52-
53+
<file name="zmq_shared_ctx.c" role="src" />
54+
5355
<!-- PHP5 legacy -->
5456
<dir name="php5">
5557
<file name="zmq.c" role="src" />
@@ -122,6 +124,8 @@
122124
<file name="050-sharedcontext.phpt" role="test" />
123125
<file name="051-socketcount.phpt" role="test" />
124126
<file name="052-pthreads.phpt" role="test" />
127+
<file name="053-z85.phpt" role="test" />
128+
<file name="054-curvekeypair.phpt" role="test" />
125129
<file name="bug_gh_156.phpt" role="test" />
126130
<file name="bug_gh_43.phpt" role="test" />
127131
<file name="bug_gh_49.phpt" role="test" />
@@ -135,21 +139,17 @@
135139
<file name="skipif-libzmq2.inc" role="test" />
136140
<file name="skipif-libzmq3.inc" role="test" />
137141
<file name="skipif-libzmq4.inc" role="test" />
138-
139142
<file name="libzmq2-sockopt.phpt" role="test" />
140143
<file name="libzmq3-sockopt.phpt" role="test" />
141144
<file name="libzmq4-sockopt.phpt" role="test" />
142-
143-
144-
145145
<file name="zeromq_test_helper.inc" role="test" />
146146
</dir>
147147
</dir>
148148
</contents>
149149
<dependencies>
150150
<required>
151151
<php>
152-
<min>5.2.0</min>
152+
<min>5.3.0</min>
153153
</php>
154154
<pearinstaller>
155155
<min>1.4.0</min>

php_zmq_private.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,22 @@ zend_long php_zmq_get_libzmq_version_id();
211211

212212
char *php_zmq_printable_func (zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);
213213

214+
215+
zend_bool php_zmq_shared_ctx_init();
216+
217+
void php_zmq_shared_ctx_assign_to(php_zmq_context *context);
218+
219+
void php_zmq_shared_ctx_destroy();
220+
221+
int php_zmq_shared_ctx_socket_count();
222+
223+
void php_zmq_shared_ctx_socket_count_incr();
224+
225+
void php_zmq_shared_ctx_socket_count_decr();
226+
227+
228+
229+
214230
ZEND_BEGIN_MODULE_GLOBALS(php_zmq)
215231
php_zmq_clock_ctx_t *clock_ctx;
216232
ZEND_END_MODULE_GLOBALS(php_zmq)

tests/052-pthreads.phpt

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Test pthreads integration
1414
--FILE--
1515
<?php
1616

17+
$threads = 10;
18+
1719
class MyWorker extends Thread {
1820
public $sendThisBack;
1921

@@ -23,32 +25,41 @@ class MyWorker extends Thread {
2325

2426
public function run() {
2527
$context = ZMQContext::acquire();
26-
var_dump($context->getSocketCount());
2728

28-
$socket = $context->getSocket(ZMQ::SOCKET_PAIR);
29+
$socket = $context->getSocket(ZMQ::SOCKET_PUSH);
2930
$socket->connect ("inproc://pthreads-test");
3031
$socket->send($this->sendThisBack);
32+
33+
sleep(2);
3134
}
3235
}
3336

3437
$context = ZMQContext::acquire();
35-
var_dump($context->getSocketCount());
3638

37-
$socket = $context->getSocket(ZMQ::SOCKET_PAIR);
39+
40+
$socket = $context->getSocket(ZMQ::SOCKET_PULL);
3841
$socket->bind("inproc://pthreads-test");
42+
$socket->setSockOpt(ZMQ::SOCKOPT_HWM, 1000);
43+
44+
$request = array();
45+
46+
for ($i = 0; $i < $threads; $i++) {
47+
$requests[$i] = new MyWorker("thr_$i");
48+
$requests[$i]->start();
49+
}
50+
51+
var_dump($context->getSocketCount());
52+
53+
for ($i = 0; $i < $threads; $i++) {
54+
$requests[$i]->join();
55+
}
3956

40-
$payload = "Hello from the other side";
41-
$request = new MyWorker($payload);
42-
43-
if ($request->start()) {
44-
$request->join();
45-
var_dump ($socket->recv());
57+
for ($i = 0; $i < $threads; $i++) {
58+
$socket->recv();
4659
}
4760

4861
echo "OK";
4962

5063
--EXPECT--
51-
int(0)
52-
int(1)
53-
string(25) "Hello from the other side"
64+
int(11)
5465
OK

tests/053-z85.phpt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
Test z85
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__) . '/skipif.inc');
6+
if (!in_array ('z85encode', get_class_methods ('zmq')))
7+
die ('skip z85encode not found in libzmq');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
function test_z85_encode_decode($input) {
13+
$encoded = zmq::z85encode($input);
14+
$decoded = zmq::z85decode($encoded);
15+
16+
if ($input !== $decoded) {
17+
echo "E: test_z85_encode_decode: input=[$input] encoded=[$encoded] decoded=[$decoded]" . PHP_EOL;
18+
}
19+
}
20+
21+
function test_z85_encode($input, $expect) {
22+
if ($expect !== zmq::z85encode($input)) {
23+
echo "E: test_z85_encode: input=[$input] expect=[$expect]" . PHP_EOL;
24+
}
25+
}
26+
27+
function test_z85_decode($input, $expect) {
28+
if ($expect !== zmq::z85decode($input)) {
29+
echo "E: test_z85_decode: input=[$input] expect=[$expect]" . PHP_EOL;
30+
}
31+
}
32+
33+
$file = file_get_contents(__DIR__ . '/rose.jpg');
34+
test_z85_encode_decode(substr($file, 0, 128));
35+
test_z85_encode_decode(substr($file, 128, 128));
36+
37+
for ($i = 4; $i <= 256; $i += 4) {
38+
$str = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", $i)), 0, $i);
39+
test_z85_encode_decode($str);
40+
}
41+
42+
// Incorrect length
43+
test_z85_encode('1234567', null);
44+
test_z85_encode(null, null);
45+
46+
test_z85_decode('1234567', null);
47+
test_z85_decode(null, null);
48+
49+
echo "OK";
50+
51+
--EXPECT--
52+
OK

tests/054-curvekeypair.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Test curve keypair
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__) . '/skipif.inc');
6+
if (!in_array ('curvekeypair', get_class_methods ('zmq')))
7+
die ('skip curvekeypair not found in libzmq');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
function test_z85_decode_encode($input) {
13+
14+
$decoded = zmq::z85decode($input);
15+
$encoded = zmq::z85encode($decoded);
16+
17+
if ($input !== $decoded) {
18+
echo "E: test_z85_decode_encode: input=[$input] encoded=[$encoded] decoded=[$decoded]" . PHP_EOL;
19+
}
20+
}
21+
22+
$keypair = ZMQ::curveKeypair();
23+
24+
test_z85_decode_encode($keypair['public_key']);
25+
test_z85_decode_encode($keypair['secret_key']);
26+
27+
28+
echo "OK";
29+
30+
--EXPECT--
31+
OK

0 commit comments

Comments
 (0)