Ruslan Osmanov avatar Ruslan Osmanov committed 2af69d8

Fix: default loop had been set even when EvLoop ctor __construct'or called
Fix: method camel case naming
Add: test for timer/periodic watchers acting with loop created with EvLoop

Comments (0)

Files changed (6)

 const zend_function_entry ev_loop_class_entry_functions[] = {
 	PHP_ME(EvLoop, __construct,       arginfo_ev_default_loop,      ZEND_ACC_PUBLIC  | ZEND_ACC_CTOR)
 	PHP_ME(EvLoop, defaultLoop,       arginfo_ev_default_loop,      ZEND_ACC_PUBLIC  | ZEND_ACC_STATIC)
-	PHP_ME(EvLoop, loop_fork,         arginfo_ev__void,             ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, loopFork,          arginfo_ev__void,             ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, verify,            arginfo_ev__void,             ZEND_ACC_PUBLIC)
-	PHP_ME(EvLoop, invoke_pending,    arginfo_ev__void,             ZEND_ACC_PUBLIC)
-	PHP_ME(EvLoop, now_update,        arginfo_ev__void,             ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, invokePending,     arginfo_ev__void,             ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, nowUpdate,         arginfo_ev__void,             ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, suspend,           arginfo_ev__void,             ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, resume,            arginfo_ev__void,             ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, now,               arginfo_ev__void,             ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, run,               arginfo_ev_run,               ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, break,             arginfo_ev_break,             ZEND_ACC_PUBLIC)
-	PHP_ME(EvLoop, feed_signal_event, arginfo_ev_feed_signal_event, ZEND_ACC_PUBLIC)
+	PHP_ME(EvLoop, feedSignalEvent,  arginfo_ev_feed_signal_event, ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, io,                arginfo_ev_loop_io,           ZEND_ACC_PUBLIC)
 	PHP_ME(EvLoop, timer,             arginfo_ev_loop_timer,        ZEND_ACC_PUBLIC)
 #if EV_PERIODIC_ENABLE
 	PHP_ME(EvWatcher, clear,        arginfo_ev__void,                ZEND_ACC_PUBLIC)
 	PHP_ME(EvWatcher, invoke,       arginfo_ev_watcher_invoke,       ZEND_ACC_PUBLIC)
 	PHP_ME(EvWatcher, feed,         arginfo_ev_watcher_feed,         ZEND_ACC_PUBLIC)
-	PHP_ME(EvWatcher, get_loop,     arginfo_ev__void,                ZEND_ACC_PUBLIC)
+	PHP_ME(EvWatcher, getLoop,      arginfo_ev__void,                ZEND_ACC_PUBLIC)
 	PHP_ME(EvWatcher, keepalive,    arginfo_ev_watcher_keepalive,    ZEND_ACC_PUBLIC)
-	PHP_ME(EvWatcher, set_callback, arginfo_ev_watcher_set_callback, ZEND_ACC_PUBLIC)
+	PHP_ME(EvWatcher, setCallback,  arginfo_ev_watcher_set_callback, ZEND_ACC_PUBLIC)
 
 	{ NULL, NULL, NULL }
 };
 /* {{{ EvLoop */
 PHP_METHOD(EvLoop, __construct);
 PHP_METHOD(EvLoop, defaultLoop);
-PHP_METHOD(EvLoop, loop_fork);
+PHP_METHOD(EvLoop, loopFork);
 PHP_METHOD(EvLoop, verify);
-PHP_METHOD(EvLoop, invoke_pending);
-PHP_METHOD(EvLoop, now_update);
+PHP_METHOD(EvLoop, invokePending);
+PHP_METHOD(EvLoop, nowUpdate);
 PHP_METHOD(EvLoop, suspend);
 PHP_METHOD(EvLoop, resume);
 PHP_METHOD(EvLoop, now);
 PHP_METHOD(EvWatcher, clear);
 PHP_METHOD(EvWatcher, invoke);
 PHP_METHOD(EvWatcher, feed);
-PHP_METHOD(EvWatcher, get_loop);
+PHP_METHOD(EvWatcher, getLoop);
 PHP_METHOD(EvWatcher, keepalive);
-PHP_METHOD(EvWatcher, set_callback);
+PHP_METHOD(EvWatcher, setCallback);
 /* }}} */
 
 /* {{{ EvIo */
 		ev_obj = (php_ev_object *) zend_object_store_get_object(return_value TSRMLS_CC);
 
 		/* Save return_value in MyG(default_loop) */
-		if (!*default_loop_ptr_ptr) {
+		if (is_default_loop && !*default_loop_ptr_ptr) {
 			MAKE_STD_ZVAL(*default_loop_ptr_ptr);
 			REPLACE_ZVAL_VALUE(default_loop_ptr_ptr, return_value, 1);
 		}
 	ptr->timeout_collect_interval = timeout_collect_interval;
 	ev_obj->ptr                   = (void *) ptr;
 
-	ev_set_userdata(loop, (void *) return_value); 
+	ev_set_userdata(loop, (void *) (in_ctor ? getThis() : return_value)); 
 }
 /* }}} */
 
         RETURN_DOUBLE((double)ev_##name());            \
     }
 
-PHP_EV_LOOP_METHOD_VOID(loop_fork)
+PHP_EV_LOOP_METHOD_VOID(loopFork)
 PHP_EV_LOOP_METHOD_VOID(verify)
-PHP_EV_LOOP_METHOD_VOID(invoke_pending)
-PHP_EV_LOOP_METHOD_VOID(now_update)
+PHP_EV_LOOP_METHOD_VOID(invokePending)
+PHP_EV_LOOP_METHOD_VOID(nowUpdate)
 PHP_EV_LOOP_METHOD_VOID(suspend)
 PHP_EV_LOOP_METHOD_VOID(resume)
 
 }
 /* }}} */
 
-/* {{{ proto void EvLoop::feed_signal_event(int signum) */
-PHP_METHOD(EvLoop, feed_signal_event)
+/* {{{ proto void EvLoop::feedSignalEvent(int signum) */
+PHP_METHOD(EvLoop, feedSignalEvent)
 {
 	long			signum;
 	php_ev_object	*ev_obj;
         <file role="src" name="06_keepalive.phpt"/>
         <file role="src" name="07_stat.phpt"/>
         <file role="src" name="08_priority.phpt"/>
+        <file role="src" name="09_loop_timer.phpt"/>
       </dir>
       <dir name="libev">
         <file role="src" name="ev.c"/>

tests/09_loop_timer.phpt

+--TEST--
+Check for EvTimer and EvPeriodic created for custom loop instance
+--FILE--
+<?php 
+#error_reporting(0);
+
+$l = new EvLoop();
+
+$fudge = 0.02;
+
+$id = 1;
+
+$base = $l->now();
+$prev = $l->now();
+
+for ($i = 1; $i <= /*125*/25; ++$i) {
+	$t = $i * $i * 1.735435336;
+	$t -= (int) $t;
+	$timer = $l->timer($t, 0, function ($w, $r)
+		use (&$id, &$prev, $base, $i, $t, $fudge) {
+			$now = $w->getLoop()->now();
+
+			echo $now + $fudge >= $prev      ? "" : "not ", "ok ", ++$id,
+				" # t0 $i $now + $fudge >= $prev\n";
+			echo $now + $fudge >= $base + $t ? "" : "not ", "ok ", ++$id,
+				" # t1 $i $now + $fudge >= $base + $t\n";
+
+			if (! ($id % 3)) {
+				$t *= 0.0625;
+				$w->set($t, 0);
+				$w->start();
+				$t = $now + $t - $base;
+			}
+
+			$prev = $now;
+		});
+
+	$t = $i * $i * 1.375475771;
+	$t -= (int) $t;
+	$periodic = $l->periodic($base + $t, 0, NULL, function ($w, $r)
+		use (&$id, &$prev, $base, $i, $t, $fudge) {
+			$now = $w->getLoop()->now();
+
+			echo $now >= $prev      ? "" : "not ", "ok ", ++$id,
+				" # p0 $i $now >= $prev\n";
+			echo $now >= $base + $t ? "" : "not ", "ok ", ++$id,
+				" # p1 $i $now >= $base + $t\n";
+
+			if (! ($id % 3)) {
+				$t *= 1.0625;
+				$w->set($base + $t, 0);
+				$w->start();
+			}
+
+			$prev = $now;
+		});
+}
+
+#ev_run();
+print "ok 1\n";
+$l->run();
+print "ok 152\n";
+
+?>
+--EXPECTF--
+ok 1
+ok 2 %s
+ok 3 %s
+ok 4 %s
+ok 5 %s
+ok 6 %s
+ok 7 %s
+ok 8 %s
+ok 9 %s
+ok 10 %s
+ok 11 %s
+ok 12 %s
+ok 13 %s
+ok 14 %s
+ok 15 %s
+ok 16 %s
+ok 17 %s
+ok 18 %s
+ok 19 %s
+ok 20 %s
+ok 21 %s
+ok 22 %s
+ok 23 %s
+ok 24 %s
+ok 25 %s
+ok 26 %s
+ok 27 %s
+ok 28 %s
+ok 29 %s
+ok 30 %s
+ok 31 %s
+ok 32 %s
+ok 33 %s
+ok 34 %s
+ok 35 %s
+ok 36 %s
+ok 37 %s
+ok 38 %s
+ok 39 %s
+ok 40 %s
+ok 41 %s
+ok 42 %s
+ok 43 %s
+ok 44 %s
+ok 45 %s
+ok 46 %s
+ok 47 %s
+ok 48 %s
+ok 49 %s
+ok 50 %s
+ok 51 %s
+ok 52 %s
+ok 53 %s
+ok 54 %s
+ok 55 %s
+ok 56 %s
+ok 57 %s
+ok 58 %s
+ok 59 %s
+ok 60 %s
+ok 61 %s
+ok 62 %s
+ok 63 %s
+ok 64 %s
+ok 65 %s
+ok 66 %s
+ok 67 %s
+ok 68 %s
+ok 69 %s
+ok 70 %s
+ok 71 %s
+ok 72 %s
+ok 73 %s
+ok 74 %s
+ok 75 %s
+ok 76 %s
+ok 77 %s
+ok 78 %s
+ok 79 %s
+ok 80 %s
+ok 81 %s
+ok 82 %s
+ok 83 %s
+ok 84 %s
+ok 85 %s
+ok 86 %s
+ok 87 %s
+ok 88 %s
+ok 89 %s
+ok 90 %s
+ok 91 %s
+ok 92 %s
+ok 93 %s
+ok 94 %s
+ok 95 %s
+ok 96 %s
+ok 97 %s
+ok 98 %s
+ok 99 %s
+ok 100 %s
+ok 101 %s
+ok 102 %s
+ok 103 %s
+ok 104 %s
+ok 105 %s
+ok 106 %s
+ok 107 %s
+ok 108 %s
+ok 109 %s
+ok 110 %s
+ok 111 %s
+ok 112 %s
+ok 113 %s
+ok 114 %s
+ok 115 %s
+ok 116 %s
+ok 117 %s
+ok 118 %s
+ok 119 %s
+ok 120 %s
+ok 121 %s
+ok 122 %s
+ok 123 %s
+ok 124 %s
+ok 125 %s
+ok 126 %s
+ok 127 %s
+ok 128 %s
+ok 129 %s
+ok 130 %s
+ok 131 %s
+ok 132 %s
+ok 133 %s
+ok 134 %s
+ok 135 %s
+ok 136 %s
+ok 137 %s
+ok 138 %s
+ok 139 %s
+ok 140 %s
+ok 141 %s
+ok 142 %s
+ok 143 %s
+ok 144 %s
+ok 145 %s
+ok 146 %s
+ok 147 %s
+ok 148 %s
+ok 149 %s
+ok 150 %s
+ok 151 %s
+ok 152
 }
 /* }}} */
 
-/* {{{ proto EvLoop EvWatcher::get_loop(void) */
-PHP_METHOD(EvWatcher, get_loop)
+/* {{{ proto EvLoop EvWatcher::getLoop(void) */
+PHP_METHOD(EvWatcher, getLoop)
 {
 	php_ev_object *o_self;
 	php_ev_loop   *o_loop;
 
 	o_self = (php_ev_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
 	w      = PHP_EV_WATCHER_FETCH_FROM_OBJECT(o_self);
-	o_loop   = php_ev_watcher_loop(w);
+	o_loop = php_ev_watcher_loop(w);
 
 	zval *zloop = (zval *) ev_userdata(o_loop->loop);
 
 }
 /* }}} */
 
-/* {{{ proto void EvWatcher::set_callback(callable callback) */
-PHP_METHOD(EvWatcher, set_callback)
+/* {{{ proto void EvWatcher::setCallback(callable callback) */
+PHP_METHOD(EvWatcher, setCallback)
 {
 	ev_watcher            *w;
 	zend_fcall_info        fci;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.