Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zyre binding #133

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c79c471
Add ZMQZyre class, a binding of the libzyre
wysman Jul 2, 2014
e3ad68f
Update api.h
wysman Jul 2, 2014
b18fec2
Add test on ZMQZyre::getSocket
wysman Jul 2, 2014
b35155c
Refactor ZMQZyre::getSocket
wysman Jul 3, 2014
994f3ca
Display version of libs
wysman Jul 3, 2014
929b108
Remove a camelcase variable
wysman Jul 3, 2014
f0ccd4f
Use real tabs
wysman Jul 3, 2014
7bd6f6c
add zend_parse_parameters_none where missing
wysman Jul 3, 2014
574d4a0
Fix returns after zend_parse_parameters
wysman Jul 3, 2014
fa37d9b
Use PHP_ZMQ_ZYRE_OBJECT to create this pointer
wysman Jul 3, 2014
0027747
Ensure peer or groupe name are not empty
wysman Jul 3, 2014
cfabf10
Check for null pointers
wysman Jul 3, 2014
5d74206
Set persistent_id to NULL
wysman Jul 3, 2014
64d6cd1
Add test of using ZMQPoll with ZMQZyre
wysman Jul 3, 2014
c4be910
Add zyre tests file in the package.xml
wysman Jul 3, 2014
7a2297f
Use correct filename... need a break ;)
wysman Jul 3, 2014
05c5c8d
Throw exception, if group name or peer id are empty
wysman Jul 8, 2014
89a3911
ecalloc, do not need null check
wysman Jul 8, 2014
0955820
Fix memory leak
wysman Jul 8, 2014
40ed1b5
Use zsys_version to find libczmq version at execution
wysman Jul 16, 2014
2d5e18c
Add gitignore
wysman Jul 16, 2014
46e7b8f
Merge remote-tracking branch 'origin/master' into zyre
wysman Jul 16, 2014
db12454
Display the CZMQ & Zyre librairy version, only if detected by configu…
wysman Jul 16, 2014
2c2e564
Fix build if zyre is not available
wysman Jul 17, 2014
104e908
Add install from bianary repo of czmq & zyre
wysman Jul 22, 2014
bb5f512
Reduce travis test matrix for test, will be revert
wysman Jul 22, 2014
b087ddb
be verbose on link creation for travis log
wysman Jul 22, 2014
0ec9791
configure PKG_CONFIG_PATH in travis bootstrap
wysman Jul 22, 2014
c4b9fc2
typo
wysman Jul 22, 2014
05f8a3f
Try direct export, configure script do not detect czmq/zyre
wysman Jul 22, 2014
1f220e1
add debugs
wysman Jul 22, 2014
cfcc299
Test autodetection of libzmq in configure script
wysman Jul 22, 2014
1a18827
Ensure the php extension build is OK, before running test
wysman Jul 22, 2014
6a96e40
Pass TSRMLS_C into zhash_foreach callback
wysman Jul 22, 2014
45190b8
Remove pre-installed version of zmq by travis
wysman Jul 22, 2014
c99745f
Be more verbose on pkg-config
wysman Jul 22, 2014
141ff43
Restore with-zmq option on configure
wysman Jul 23, 2014
af91e6a
Test build from source for czmq/zyre ibs with the same prefix as zmq …
wysman Jul 23, 2014
3ecd031
typo
wysman Jul 23, 2014
ae15fc2
typo
wysman Oct 8, 2014
0cf5fbb
Merge branch 'master' into zyre
wysman Oct 13, 2014
6ce250f
Reduce tests matrix, will be revert
wysman Oct 13, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
*~
*.lo
*.la

build/
.libs/
autom4te.cache/
modules/

tests/*.diff
tests/*.exp
tests/*.log
tests/*.out
tests/*.php
tests/*.sh

Makefile*
configure*
libtool
ltmain.sh
missing
mkinstalldirs
install-sh
aclocal.m4
acinclude.m4
.deps

config*
!config.m4
!config.w32

21 changes: 8 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
language: php

php:
- 5.6
- 5.5
- 5.4
- 5.3

env:
- ZEROMQ_VERSION=v2.2.0
- ZEROMQ_VERSION=v3.1.0
- ZEROMQ_VERSION=v3.2.0
- ZEROMQ_VERSION=v3.2.1
- ZEROMQ_VERSION=v3.2.2
- ZEROMQ_VERSION=v3.2.3
- ZEROMQ_VERSION=v3.2.4
- ZEROMQ_VERSION=v4.0.0
- ZEROMQ_VERSION=v4.0.1

- ZEROMQ_VERSION=v4.0.1 WITH_CZMQ=true
- ZEROMQ_VERSION=v4.0.1 WITH_CZMQ=true WITH_ZYRE=true

before_install:
- sudo apt-get update
- sudo apt-get remove libzmq3-dev libzmq3
- sudo apt-get install uuid-dev
script: travis/script.sh $ZEROMQ_VERSION $WITH_CZMQ

script: travis/script.sh $ZEROMQ_VERSION $WITH_CZMQ $WITH_ZYRE

86 changes: 86 additions & 0 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,91 @@ public function count() {}
public function clear() {}
}

class ZMQZyre {
const LIBZYRE_VERSION = '1.1.0';
/**
* Construct a ZMQZyre
*
* @param ZMQContext $context
* @return void
*/
public function __construct(ZMQContext $ZMQContext) {}
/**
* Set node header; these are provided to other nodes during discovery and come in each ENTER message.
*
* @param string $name
* @param string $value
* @return void
*/
public function setHeader($name, $value="") {}
/**
* Start node, after setting header values. When you start a node it begins discovery and connection.
There is no stop method; to stop a node, destroy it.
*
* @return void
*/
public function start() {}
/**
* Stop node, this signals to other peers that this node will go away.
This is polite; however you can also just destroy the node without stopping it.
*
* @return void
*/
public function stop() {}
/**
* Join a named group; after joining a group you can send messages
to the group and all Zyre nodes in that group will receive them.
*
* @param string $group
* @return void
*/
public function join($group) {}
/**
* Leave a group.
*
* @param string $group
* @return void
*/
public function leave($group) {}
/**
* Receive next message from network; the message may be a control
message (ENTER, EXIT, JOIN, LEAVE) or data (WHISPER, SHOUT).
Returns associative array, or NULL if interrupted
*
* @return void
*/
public function recv() {}
/**
* Send a message on the network to a specific peer
*
* @param string $peer
* @param string $data
* @return void
*/
public function sendPeer($peer, $data) {}
/**
* Send a message on the network for a group
*
* @param string $group
* @param string $data
* @return void
*/
public function sendGroup($group, $data) {}
/**
* Get zyre ZeroMQ socket, for polling or receiving messages
*
* @return ZMQSocket
*/
public function getSocket() {}
}

class ZMQException extends Exception {}
class ZMQContextException extends ZMQException {}
class ZMQSocketException extends ZMQException {}
class ZMQPollException extends ZMQException {}
class ZMQDeviceException extends ZMQException {}
class ZMQZyreException extends ZMQException {}

/**
* A security certificate for the ØMQ CURVE authentication mechanism.
*/
Expand Down Expand Up @@ -665,5 +750,6 @@ public function deny($address) {}
*/
public function configure($type, $domain, $filename) {}
}

?>
</code></pre>
26 changes: 26 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ PHP_ARG_ENABLE(zmq_pthreads, whether to enable support for php threads extens
PHP_ARG_WITH(czmq, whether to enable CZMQ support,
[ --with-czmq[=DIR] Enable CZMQ support. DIR is the prefix to CZMQ installation directory.], no, no)

PHP_ARG_WITH(zyre, whether to enable Zyre support,
[ --with-zyre[=DIR] Enable Zyre support. DIR is the prefix to Zyre installation directory.], no, no)

if test "$PHP_ZMQ" != "no"; then

AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
Expand Down Expand Up @@ -69,6 +72,29 @@ if test "$PHP_ZMQ" != "no"; then
fi
fi

if test "$PHP_ZYRE" != "no" -a "$PHP_CZMQ" != "no"; then
if test "x$PHP_ZYRE" != "xyes"; then
export PKG_CONFIG_PATH="${PHP_ZYRE}/${PHP_LIBDIR}/pkgconfig"
fi

AC_MSG_CHECKING(for Zyre)
if $PKG_CONFIG --exists libzyre; then
PHP_ZYRE_VERSION=`$PKG_CONFIG libzyre --modversion`
PHP_ZYRE_PREFIX=`$PKG_CONFIG libzyre --variable=prefix`
AC_MSG_RESULT([found version $PHP_ZYRE_VERSION in $PHP_ZYRE_PREFIX])

PHP_ZYRE_LIBS=`$PKG_CONFIG libzyre --libs`
PHP_ZYRE_INCS=`$PKG_CONFIG libzyre --cflags`

PHP_EVAL_LIBLINE($PHP_ZYRE_LIBS, ZMQ_SHARED_LIBADD)
PHP_EVAL_INCLINE($PHP_ZYRE_INCS)

AC_DEFINE([HAVE_ZYRE], [], [ZYRE was found])
else
AC_MSG_RESULT([no])
fi
fi

AC_CHECK_HEADERS([stdint.h],[php_zmq_have_stdint=yes; break;])
if test $php_zmq_have_stdint != "yes"; then
AC_MSG_ERROR(Unable to find stdint.h)
Expand Down
9 changes: 9 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
<file name="rose.jpg" role="test" />
<file name="skipif.inc" role="test" />
<file name="zeromq_test_helper.inc" role="test" />

<!-- Zyre tests files -->
<file name="skipzyre.inc" role="test" />
<file name="zyre-001.phpt" role="test" />
<file name="zyre-002.phpt" role="test" />
<file name="zyre-003.phpt" role="test" />
<file name="zyre-004.phpt" role="test" />
<file name="zyre-005.phpt" role="test" />
<file name="zyre-006.phpt" role="test" />
</dir>
</dir>
</contents>
Expand Down
12 changes: 12 additions & 0 deletions php_zmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@
extern zend_module_entry zmq_module_entry;
#define phpext_zmq_ptr &zmq_module_entry

/* PHP 5.4 */
#if PHP_VERSION_ID < 50399
# define object_properties_init(zo, class_type) { \
zval *tmp; \
zend_hash_copy((*zo).properties, \
&class_type->default_properties, \
(copy_ctor_func_t) zval_add_ref, \
(void *) &tmp, \
sizeof(zval *)); \
}
#endif

#endif /* _PHP_ZMQ_H_ */
19 changes: 19 additions & 0 deletions php_zmq_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
# endif
#endif

#if defined(HAVE_CZMQ) && defined(HAVE_ZYRE)
# include <czmq.h>
# include <zyre.h>
# if ZYRE_VERSION_MAJOR == 1 && CZMQ_VERSION_MAJOR >= 2
# define HAVE_ZYRE_1
# endif
#endif

#ifdef PHP_WIN32
# include "win32/php_stdint.h"
#else
Expand Down Expand Up @@ -275,6 +283,17 @@ ZEND_BEGIN_MODULE_GLOBALS(php_zmq)
php_zmq_clock_ctx_t *clock_ctx;
ZEND_END_MODULE_GLOBALS(php_zmq)


#ifdef HAVE_ZYRE_1
#define PHP_ZMQ_ZYRE_OBJECT php_zmq_zyre *this = (php_zmq_zyre *)zend_object_store_get_object(getThis() TSRMLS_CC)
typedef struct _php_zmq_zyre {
zend_object zend_object;
zctx_t *shadow_context;
zyre_t *zyre;
zval *internal_socket;
} php_zmq_zyre;
#endif

#ifdef HAVE_CZMQ_2
typedef struct _php_zmq_cert {
zend_object zend_object;
Expand Down
6 changes: 6 additions & 0 deletions tests/skipzyre.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

if (!extension_loaded("zmq")) die("skip");
if (!class_exists('ZMQZyre')) die('skip');

?>
15 changes: 15 additions & 0 deletions tests/zyre-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Test [Zyre] Object can be instancied multiple time
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipzyre.inc'); ?>
--FILE--
<?php

$ctx = new ZMQContext;
$z1 = new ZMQZyre($ctx);
$z2 = new ZMQZyre($ctx);
$z3 = new ZMQZyre($ctx);
echo "OK";

--EXPECTF--
OK
42 changes: 42 additions & 0 deletions tests/zyre-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
Test [Zyre] Headers are received on ENTER event
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipzyre.inc'); ?>
--FILE--
<?php

$ctx = new ZMQContext;

$z1 = new ZMQZyre($ctx);
$z1->setHeader('X-TEST', 'Z1');
$z1->start();

$z2 = new ZMQZyre($ctx);
$z2->setHeader('X-TEST', 'Z2');
$z2->start();

usleep(100000);

$obj = $z1->recv();
var_dump($obj->command);
var_dump($obj->headers->{'X-TEST'});

$obj = $z2->recv();
var_dump($obj->command);
var_dump($obj->headers->{'X-TEST'});

$z1->stop();

usleep(100000);

$obj = $z2->recv();
var_dump($obj->command);

$z2->stop();

--EXPECTF--
string(5) "ENTER"
string(2) "Z2"
string(5) "ENTER"
string(2) "Z1"
string(4) "EXIT"
Loading