Commits

Ruslan Osmanov committed baf84fa

Add: test for EvStat

Comments (0)

Files changed (6)

-libevent buffer functionality
+Start watchers automatically by default
+=======================================
+In most cases watchers are started automatically.
+Getting rid of need to call ::start() method we skip the function call overhead!.
+
+
+libevent buffer functionality?
 =============================
 
 	<?php
 	PHP_ME(EvStat, set,         arginfo_ev_stat_set, ZEND_ACC_PUBLIC)
 	PHP_ME(EvStat, attr,        arginfo_ev__void,    ZEND_ACC_PUBLIC)
 	PHP_ME(EvStat, prev,        arginfo_ev__void,    ZEND_ACC_PUBLIC)
+	PHP_ME(EvStat, stat,        arginfo_ev__void,    ZEND_ACC_PUBLIC)
 
 	{ NULL, NULL, NULL }
 };
 PHP_METHOD(EvStat, set);
 PHP_METHOD(EvStat, attr);
 PHP_METHOD(EvStat, prev);
+PHP_METHOD(EvStat, stat);
 /* }}} */
 #endif
 
 {
 	PHP_EV_LOOP_FETCH_FROM_THIS;
 
-	long how = 0;
+	long how = EVBREAK_ONE;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &how) == FAILURE) {
 		return;
 }
 /* }}} */
 
+/* {{{ proto bool EvStat::stat(void) */
+PHP_METHOD(EvStat, stat)
+{
+	php_ev_object *ev_obj;
+	ev_stat       *stat_watcher;
+	ev_statdata   *st;
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	ev_obj       = (php_ev_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
+	stat_watcher = (ev_stat *) PHP_EV_WATCHER_FETCH_FROM_OBJECT(ev_obj);
+
+	st = &stat_watcher->attr;
+
+	ev_stat_stat(PHP_EV_LOOP_FETCH_FROM_OBJECT(ev_obj), stat_watcher);
+
+	if (st->st_nlink) {
+		RETURN_TRUE;
+	}
+	RETURN_FALSE;
+}
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4

tests/07_stat.phpt

+--TEST--
+Check for EvStat functionality
+--FILE--
+<?php 
+error_reporting(0);
+
+$loop = EvLoop::default_loop();
+
+$fh = tempnam(__DIR__, 'ev_tmp_');
+
+$w = new EvStat("$fh", 0.1, $loop, function ($w, $r) use ($loop) {
+	$prev = $w->prev();
+
+	echo "ok 5\n";
+	echo $prev ? "" : "not ", "ok 6\n";
+	echo 13 == count($prev) ? "" : "not ", "ok 7\n";
+	echo 1 == $prev['nlink'] ? "" : "not ", "ok 8\n";
+	echo FALSE == $w->attr() ? "" : "not ", "ok 9\n";
+	echo FALSE == $w->stat() ? "" : "not ", "ok 10\n";
+
+   	$loop->break();
+});
+$w->start();
+
+
+$t = new EvTimer(0.2, 0, $loop, function ($w, $r) use ($loop) {
+	echo "ok 2\n";
+	$loop->break();
+});
+$t->start();
+
+echo $w->stat() ? "" : "not ", "ok 1\n";
+$loop->run();
+echo "ok 3\n";
+
+unlink($fh);
+
+$t = new EvTimer(0.2, 0, $loop, function ($w, $r) use ($loop) {
+	echo "ok 2\n";
+	$loop->break();
+});
+$t->start();
+
+echo "ok 4\n";
+$loop->run();
+echo "ok 11\n";
+
+?>
+--CLEAN--
+<?php
+@unlink($fh);
+?>
+--EXPECT--
+ok 1
+ok 2
+ok 3
+ok 4
+ok 5
+ok 6
+ok 7
+ok 8
+ok 9
+ok 10
+ok 11