From 204fcbe5d3ffb4a9c1383e39f7549b8326801894 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Tue, 29 Jul 2008 16:46:11 +0000 Subject: [PATCH] MFH: Added pcntl_signal_dispatch() [DOC] pcntl_signal_dispatch() allows to dispatch pending signals to registered signal handler functions on-demand. This allows to use pcntl_signal() without ticks. --- ext/pcntl/pcntl.c | 16 ++++++++++--- ext/pcntl/php_pcntl.h | 1 + ext/pcntl/tests/pcntl_signal_dispatch.phpt | 26 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 ext/pcntl/tests/pcntl_signal_dispatch.phpt diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index f1c8ec8c93..9dce4b7ff4 100755 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -134,6 +134,7 @@ const zend_function_entry pcntl_functions[] = { PHP_FE(pcntl_waitpid, arginfo_pcntl_waitpid) PHP_FE(pcntl_wait, arginfo_pcntl_wait) PHP_FE(pcntl_signal, arginfo_pcntl_signal) + PHP_FE(pcntl_signal_dispatch, arginfo_pcntl_void) PHP_FE(pcntl_wifexited, arginfo_pcntl_wifexited) PHP_FE(pcntl_wifstopped, arginfo_pcntl_wifstopped) PHP_FE(pcntl_wifsignaled, arginfo_pcntl_wifsignaled) @@ -173,7 +174,7 @@ ZEND_GET_MODULE(pcntl) #endif static void pcntl_signal_handler(int); -static void pcntl_tick_handler(); +static void pcntl_signal_dispatch(); void php_register_signal_constants(INIT_FUNC_ARGS) { @@ -262,7 +263,7 @@ PHP_RINIT_FUNCTION(pcntl) PHP_MINIT_FUNCTION(pcntl) { php_register_signal_constants(INIT_FUNC_ARGS_PASSTHRU); - php_add_tick_function(pcntl_tick_handler); + php_add_tick_function(pcntl_signal_dispatch); return SUCCESS; } @@ -644,6 +645,15 @@ PHP_FUNCTION(pcntl_signal) } /* }}} */ +/* {{{ proto bool pcntl_signal_dispatch() + Dispatch signals to signal handlers */ +PHP_FUNCTION(pcntl_signal_dispatch) +{ + pcntl_signal_dispatch(); + RETURN_TRUE; +} +/* }}} */ + #ifdef HAVE_GETPRIORITY /* {{{ proto int pcntl_getpriority([int pid [, int process_identifier]]) Get the priority of any process */ @@ -747,7 +757,7 @@ static void pcntl_signal_handler(int signo) PCNTL_G(tail) = psig; } -void pcntl_tick_handler() +void pcntl_signal_dispatch() { zval *param, **handle, *retval; struct php_pcntl_pending_signal *queue, *next; diff --git a/ext/pcntl/php_pcntl.h b/ext/pcntl/php_pcntl.h index f7e5efe9fd..cd6d82e1f0 100644 --- a/ext/pcntl/php_pcntl.h +++ b/ext/pcntl/php_pcntl.h @@ -44,6 +44,7 @@ PHP_FUNCTION(pcntl_wexitstatus); PHP_FUNCTION(pcntl_wtermsig); PHP_FUNCTION(pcntl_wstopsig); PHP_FUNCTION(pcntl_signal); +PHP_FUNCTION(pcntl_signal_dispatch); PHP_FUNCTION(pcntl_exec); #ifdef HAVE_GETPRIORITY PHP_FUNCTION(pcntl_getpriority); diff --git a/ext/pcntl/tests/pcntl_signal_dispatch.phpt b/ext/pcntl/tests/pcntl_signal_dispatch.phpt new file mode 100644 index 0000000000..82e0a78f15 --- /dev/null +++ b/ext/pcntl/tests/pcntl_signal_dispatch.phpt @@ -0,0 +1,26 @@ +--TEST-- +pcnt_signal_dispatch() +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Start! +Signal handler called! +Done! -- 2.50.1