Browse files

Fixes GH-50

  • Loading branch information...
1 parent 8c4146a commit 87d3e5c40cc90d962afaa868f2020e3ef12dea58 @mkoppanen committed Feb 15, 2012
Showing with 78 additions and 12 deletions.
  1. +64 −0 tests/bug_gh_50.phpt
  2. +14 −12 zmq_pollset.c
View
64 tests/bug_gh_50.phpt
@@ -0,0 +1,64 @@
+--TEST--
+Test for Github issue #50
+--SKIPIF--
+<?php
+ require_once(dirname(__FILE__) . '/skipif.inc');
+?>
+--FILE--
+<?php
+
+$context = new ZMQContext (1, false);
+$server = new ZMQSocket ($context, ZMQ::SOCKET_PUB);
+$server->bind ('inproc://test');
+
+$client = new ZMQSocket ($context, ZMQ::SOCKET_SUB);
+$client->setsockopt (ZMQ::SOCKOPT_SUBSCRIBE, "");
+$client->connect ('inproc://test');
+
+$client2 = new ZMQSocket ($context, ZMQ::SOCKET_SUB);
+$client2->setsockopt (ZMQ::SOCKOPT_SUBSCRIBE, "");
+$client2->connect ('inproc://test');
+
+$poll = new ZMQPoll ();
+$poll->add ($client, ZMQ::POLL_IN);
+$poll->add ($client2, ZMQ::POLL_IN);
+
+$readable = array();
+$writable = array();
+
+$server->send ("Hello all");
+
+$res = $poll->poll ($readable, $writable, 1000);
+var_dump ($poll->count () == $res, $readable, $writable);
+
+foreach ($readable as $r)
+ $r->recv ();
+
+$poll->remove ($client2);
+$server->send ("Hello all");
+
+$res = $poll->poll ($readable, $writable, 1000);
+var_dump ($poll->count () == $res, $readable, $writable);
+
+?>
+
+--EXPECT--
+bool(true)
+array(2) {
+ [0]=>
+ object(ZMQSocket)#3 (0) {
+ }
+ [1]=>
+ object(ZMQSocket)#4 (0) {
+ }
+}
+array(0) {
+}
+bool(true)
+array(1) {
+ [0]=>
+ object(ZMQSocket)#3 (0) {
+ }
+}
+array(0) {
+}
View
26 zmq_pollset.c
@@ -105,19 +105,19 @@ void php_zmq_pollset_delete_all(php_zmq_pollset *set TSRMLS_DC)
static void php_spl_object_hash(zval *obj, char *result TSRMLS_DC) /* {{{*/
{
PHP_MD5_CTX context;
- unsigned char digest[16];
-
+ unsigned char digest[16];
+
char *hash;
int len;
-
+
len = spprintf(&hash, 0, "%p:%d", Z_OBJ_HT_P(obj), Z_OBJ_HANDLE_P(obj));
-
- result[0] = '\0';
- PHP_MD5Init(&context);
- PHP_MD5Update(&context, (unsigned char*) hash, len);
- PHP_MD5Final(digest, &context);
- make_digest(result, digest);
- efree(hash);
+
+ result[0] = '\0';
+ PHP_MD5Init(&context);
+ PHP_MD5Update(&context, (unsigned char*) hash, len);
+ PHP_MD5Final(digest, &context);
+ make_digest(result, digest);
+ efree(hash);
}
/* }}} */
#endif
@@ -273,7 +273,9 @@ static void php_zmq_pollitem_copy(php_zmq_pollitem *target, php_zmq_pollitem *so
{
target->events = source->events;
target->entry = source->entry;
- target->key_len = source->key_len;
+ target->key_len = source->key_len;
+ target->socket = source->socket;
+ target->fd = source->fd;
memcpy(target->key, source->key, source->key_len + 1);
}
@@ -289,7 +291,7 @@ zend_bool php_zmq_pollset_delete_by_key(php_zmq_pollset *set, char key[35], int
for (i = 0; i < set->num_php_items; i++) {
if (!match && key_len == set->php_items[i].key_len &&
!memcmp(set->php_items[i].key, key, key_len)) {
-
+
if (Z_TYPE_P(set->php_items[i].entry) == IS_OBJECT) {
zend_objects_store_del_ref(set->php_items[i].entry TSRMLS_CC);
}

0 comments on commit 87d3e5c

Please sign in to comment.