Commits

Ruslan Osmanov  committed 510f337

Add: EvLoop props: depth, io/timeout intervals, backend
Fix: tests

  • Participants
  • Parent commits 84dde2b

Comments (0)

Files changed (3)

 }
 /* }}} */
 
+/* {{{ ev_loop_prop_io_interval_read */
+static int ev_loop_prop_io_interval_read(php_ev_object *obj, zval **retval TSRMLS_DC)
+{
+	PHP_EV_ASSERT(obj->ptr);
+
+	php_ev_loop *loop_obj = PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(obj);
+
+	MAKE_STD_ZVAL(*retval);
+	ZVAL_DOUBLE(*retval, loop_obj->io_collect_interval);
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ ev_loop_prop_io_interval_write */
+static int ev_loop_prop_io_interval_write(php_ev_object *obj, zval *value TSRMLS_DC)
+{
+	php_ev_loop *loop_obj;
+
+	PHP_EV_ASSERT(obj->ptr);
+
+	loop_obj = PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(obj);
+
+	loop_obj->io_collect_interval = Z_DVAL_P(value);
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ ev_loop_prop_timeout_interval_read */
+static int ev_loop_prop_timeout_interval_read(php_ev_object *obj, zval **retval TSRMLS_DC)
+{
+	PHP_EV_ASSERT(obj->ptr);
+
+	php_ev_loop *loop_obj = PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(obj);
+
+	MAKE_STD_ZVAL(*retval);
+	ZVAL_DOUBLE(*retval, loop_obj->timeout_collect_interval);
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ ev_loop_prop_timeout_interval_write */
+static int ev_loop_prop_timeout_interval_write(php_ev_object *obj, zval *value TSRMLS_DC)
+{
+	php_ev_loop *loop_obj;
+
+	PHP_EV_ASSERT(obj->ptr);
+
+	loop_obj = PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(obj);
+
+	loop_obj->timeout_collect_interval = Z_DVAL_P(value);
+
+	return SUCCESS;
+}
+/* }}} */
+
+/* {{{ ev_loop_prop_depth_read */
+static int ev_loop_prop_depth_read(php_ev_object *obj, zval **retval TSRMLS_DC)
+{
+	PHP_EV_ASSERT(obj->ptr);
+
+	php_ev_loop *loop_obj = PHP_EV_LOOP_OBJECT_FETCH_FROM_OBJECT(obj);
+
+	MAKE_STD_ZVAL(*retval);
+	ZVAL_LONG(*retval, ev_depth(PHP_EV_LOOP_FETCH_FROM_OBJECT(obj)));
+
+	return SUCCESS;
+}
+/* }}} */
+
 /* }}} */
 
 /* {{{ EvWatcher property handlers */
 
 /* {{{ ev_loop_property_entries[] */
 const php_ev_property_entry ev_loop_property_entries[] = {
-	{"data",            sizeof("data")            - 1, ev_loop_prop_data_read,            ev_loop_prop_data_write},
-	{"backend",         sizeof("backend")         - 1, ev_loop_prop_backend_read,         NULL},
-	{"is_default_loop", sizeof("is_default_loop") - 1, ev_loop_prop_is_default_loop_read, NULL},
-	{"iteration",       sizeof("iteration")       - 1, ev_loop_prop_iteration_loop_read,  NULL},
-	{"pending",         sizeof("pending")         - 1, ev_loop_prop_pending_loop_read,    NULL},
+	{"data",             sizeof("data")             - 1, ev_loop_prop_data_read,             ev_loop_prop_data_write},
+	{"backend",          sizeof("backend")          - 1, ev_loop_prop_backend_read,          NULL},
+	{"is_default_loop",  sizeof("is_default_loop")  - 1, ev_loop_prop_is_default_loop_read,  NULL},
+	{"iteration",        sizeof("iteration")        - 1, ev_loop_prop_iteration_loop_read,   NULL},
+	{"pending",          sizeof("pending")          - 1, ev_loop_prop_pending_loop_read,     NULL},
+	{"io_interval",      sizeof("io_interval")      - 1, ev_loop_prop_io_interval_read,      ev_loop_prop_io_interval_write},
+	{"timeout_interval", sizeof("timeout_interval") - 1, ev_loop_prop_timeout_interval_read, ev_loop_prop_timeout_interval_write},
+	{"depth",            sizeof("depth")            - 1, ev_loop_prop_depth_read,            NULL},
     {NULL, 0, NULL, NULL}
 };
 /* }}} */
 
 /* {{{ ev_loop_property_entry_info[] */
 const zend_property_info ev_loop_property_entry_info[] = {
-	{ZEND_ACC_PUBLIC, "data",            sizeof("data")            - 1, -1, 0, NULL, 0, NULL},
-	{ZEND_ACC_PUBLIC, "backend",         sizeof("backend")         - 1, -1, 0, NULL, 0, NULL},
-	{ZEND_ACC_PUBLIC, "is_default_loop", sizeof("is_default_loop") - 1, -1, 0, NULL, 0, NULL},
-	{ZEND_ACC_PUBLIC, "iteration",       sizeof("iteration")       - 1, -1, 0, NULL, 0, NULL},
-	{ZEND_ACC_PUBLIC, "pending",         sizeof("pending")         - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "data",             sizeof("data")             - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "backend",          sizeof("backend")          - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "is_default_loop",  sizeof("is_default_loop")  - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "iteration",        sizeof("iteration")        - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "pending",          sizeof("pending")          - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "io_interval",      sizeof("io_interval")      - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "timeout_interval", sizeof("timeout_interval") - 1, -1, 0, NULL, 0, NULL},
+	{ZEND_ACC_PUBLIC, "depth",            sizeof("depth")            - 1, -1, 0, NULL, 0, NULL},
 	{0, NULL, 0, -1, 0, NULL, 0, NULL}
 };
 /* }}} */

File tests/03_ev_loop_props.phpt

 Check for EvLoop class properties
 --FILE--
 <?php 
-function cb($watcher, $revents) {
-	echo __FUNCTION__, "() called", PHP_EOL;
-	$watcher->stop();
+function my_print_props($l) {
+	echo "backend:";          var_dump($l->backend);
+	echo "data:";             var_dump($l->data);
+	echo "is_default_loop:";  var_dump($l->is_default_loop);
+	echo "iteration:";        var_dump($l->iteration);
+	echo "pending:";          var_dump($l->pending);
+	echo "io_interval:";      var_dump($l->io_interval);
+	echo "timeout_interval:"; var_dump($l->timeout_interval);
+	echo "depth:";            var_dump($l->depth);
+}
+
+function cb($w, $r) {
 	return FALSE;
 }
-//$fd = fopen('listen_to_me', 'r');
 
-$loop       = EvLoop::default_loop();
-$loop->data = "ld";
-$io_watcher = new EvIo(STDIN, EV_READ, $loop, "cb", "data", 2);
-var_dump($io_watcher->get_loop());
-var_dump($io_watcher->priority);
-var_dump($io_watcher->data);
+$l                   = EvLoop::default_loop();
+$l->data             = "ld";
+$l->io_interval      = 1.1;
+$l->timeout_interval = 1.2;
+my_print_props($l);
+
 
-//$io_watcher->start();
-//$loop->run();
-//echo "closing fd\n";
-//fclose($fd);
+$flags               = EVFLAG_NOENV | EVFLAG_NOINOTIFY; /* 17825792 */
+$l                   = new EvLoop($flags, "cb", "data", 1.1, 1.2);
+$l->data             = "ld2";
+$l->io_interval      = 2.1;
+$l->timeout_interval = 2.2;
 
+var_dump($flags);
+my_print_props($l);
 ?>
---EXPECT--
+--EXPECTF--
+backend:int(%d)
+data:string(2) "ld"
+is_default_loop:bool(true)
+iteration:int(0)
+pending:int(0)
+io_interval:float(1.1)
+timeout_interval:float(1.2)
+depth:int(0)
+int(17825792)
+backend:int(%d)
+data:string(3) "ld2"
+is_default_loop:bool(false)
+iteration:int(0)
+pending:int(0)
+io_interval:float(2.1)
+timeout_interval:float(2.2)
+depth:int(0)

File tests/04_ev_watcher_construct_variation.phpt

---TEST--
-Check for constructors of the classes derived from EvWatcher
---FILE--
-<?php
-function cb() {
-	return FALSE;
-}
-
-$loop = new EvLoop();
-$io_watcher = new EvIo(STDIN, EV_READ, $loop, "cb");
-var_dump($io_watcher);
-
-
-?>
---EXPECTF--