From: Ilia Alshanetsky Date: Wed, 12 Nov 2003 22:02:37 +0000 (+0000) Subject: Added nanosleep(), in addition to allowing setting of very short states. X-Git-Tag: php-5.0.0b3RC1~708 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3691ab699cfd335d62239540c096770cbe845eb8;p=php Added nanosleep(), in addition to allowing setting of very short states. This function is signal safe. --- diff --git a/NEWS b/NEWS index 01b6c0a0bf..0534a3f058 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? Oct 2003, PHP 5 Beta 3 -- Added dba_key_split() to split inifile keys in an array. (Marcus) +- Added new functions: + . dba_key_split() to split inifile keys in an array. (Marcus) + . nanosleep() signal safe sleep (Magnus, Ilia) - Fixed bug #26083 (Non-working write support in ext/dom). (Ilia) - Fixed bug #24394 (Serializing cross-referenced objects causes segfault). (Moriyoshi) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 3e38200075..619e89d92b 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -301,6 +301,7 @@ function_entry basic_functions[] = { PHP_FE(bin2hex, NULL) PHP_FE(sleep, NULL) PHP_FE(usleep, NULL) + PHP_FE(nanosleep, NULL) PHP_FE(time, NULL) PHP_FE(mktime, NULL) PHP_FE(gmmktime, NULL) @@ -1690,6 +1691,34 @@ PHP_FUNCTION(usleep) } /* }}} */ +/* {{{ proto mixed nanosleep(long seconds, long nanoseconds) + Delay for a number of seconds and nano seconds */ +PHP_FUNCTION(nanosleep) +{ + long tv_sec, tv_nsec; + struct timespec php_req, php_rem; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &tv_sec, &tv_nsec)) { + WRONG_PARAM_COUNT; + } + + php_req.tv_sec = (time_t) tv_sec; + php_req.tv_nsec = tv_nsec; + if (!nanosleep(&php_req, &php_rem)) { + RETURN_TRUE; + } else if (errno == EINTR) { + array_init(return_value); + add_assoc_long_ex(return_value, "seconds", sizeof("seconds"), php_rem.tv_sec); + add_assoc_long_ex(return_value, "nanoseconds", sizeof("nanoseconds"), php_rem.tv_nsec); + return; + } else if (errno == EINVAL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "nanoseconds was not in the range 0 to 999 999 999 or seconds was negative"); + } + + RETURN_FALSE; +} +/* }}} */ + /* {{{ proto string get_current_user(void) Get the name of the owner of the current PHP script */ PHP_FUNCTION(get_current_user) diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 6ef8b91be9..e83fb68aea 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -48,6 +48,7 @@ PHP_FUNCTION(constant); PHP_FUNCTION(toggle_short_open_tag); PHP_FUNCTION(sleep); PHP_FUNCTION(usleep); +PHP_FUNCTION(nanosleep); PHP_FUNCTION(flush); PHP_FUNCTION(ip2long); PHP_FUNCTION(long2ip);