]> granicus.if.org Git - php/commitdiff
Added nanosleep(), in addition to allowing setting of very short states.
authorIlia Alshanetsky <iliaa@php.net>
Wed, 12 Nov 2003 22:02:37 +0000 (22:02 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 12 Nov 2003 22:02:37 +0000 (22:02 +0000)
This function is signal safe.

NEWS
ext/standard/basic_functions.c
ext/standard/basic_functions.h

diff --git a/NEWS b/NEWS
index 01b6c0a0bf6392bb6fd8611a828de8624490e188..0534a3f058fad897ff03036fa100a528e429fd60 100644 (file)
--- 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)
index 3e38200075fbac21ba920ef88f0b3ce45aa2caa3..619e89d92bede99eb56a6552ea38848a8c984246 100644 (file)
@@ -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)
index 6ef8b91be9dc905c1e9a5bf5dab1e55d83d99694..e83fb68aeaec2f0492171f72d0806113be18eb8d 100644 (file)
@@ -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);