Skip to content

Commit 096eedc

Browse files
committed
Add uv_stop()
1 parent 2b04d12 commit 096eedc

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

php_uv.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_run, 0, 0, 1)
26882688
ZEND_ARG_INFO(0, loop)
26892689
ZEND_END_ARG_INFO()
26902690

2691+
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_stop, 0, 0, 1)
2692+
ZEND_ARG_INFO(0, loop)
2693+
ZEND_END_ARG_INFO()
2694+
26912695
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_loop_delete, 0, 0, 1)
26922696
ZEND_ARG_INFO(0, loop)
26932697
ZEND_END_ARG_INFO()
@@ -3483,6 +3487,22 @@ PHP_FUNCTION(uv_run)
34833487
}
34843488
/* }}} */
34853489

3490+
/* {{{ proto void uv_stop([resource $uv_loop])
3491+
*/
3492+
PHP_FUNCTION(uv_stop)
3493+
{
3494+
zval *zloop = NULL;
3495+
uv_loop_t *loop;
3496+
3497+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
3498+
"|z",&zloop) == FAILURE) {
3499+
return;
3500+
}
3501+
PHP_UV_FETCH_UV_DEFAULT_LOOP(loop, zloop);
3502+
uv_stop(loop);
3503+
}
3504+
/* }}} */
3505+
34863506
/* {{{ proto long uv_run_once([resource $uv_loop])
34873507
*/
34883508
PHP_FUNCTION(uv_run_once)
@@ -6439,6 +6459,7 @@ static zend_function_entry uv_functions[] = {
64396459
PHP_FE(uv_unref, arginfo_uv_unref)
64406460
PHP_FE(uv_loop_new, NULL)
64416461
PHP_FE(uv_default_loop, NULL)
6462+
PHP_FE(uv_stop, arginfo_uv_stop)
64426463
PHP_FE(uv_run, arginfo_uv_run)
64436464
PHP_FE(uv_run_once, arginfo_uv_run_once)
64446465
PHP_FE(uv_ip4_addr, arginfo_uv_ip4_addr)

tests/100-uv_stop.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Test uv_stop ends loop execution
3+
--FILE--
4+
<?php
5+
$loop = uv_default_loop();
6+
$timer = uv_timer_init();
7+
8+
$i = 0;
9+
uv_timer_start($timer, 10, 10, function($timer) use (&$i, $loop) {
10+
echo "count: {$i}" . PHP_EOL;
11+
$i++;
12+
13+
if ($i > 3) {
14+
uv_stop($loop);
15+
}
16+
});
17+
18+
uv_run();
19+
20+
echo "finished" . PHP_EOL;
21+
--EXPECT--
22+
count: 0
23+
count: 1
24+
count: 2
25+
count: 3
26+
finished

0 commit comments

Comments
 (0)