X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_api.h;h=052fb1e1c817a9cb92bd5e99ff1930b9e724ba70;hp=325378c4d0ec3d2e167d6efaafa8c36ccc196ca4;hb=5b440d6af3dd3052dde7b137f975692f0aa84603;hpb=9676c81efbb8f180fa189d71a7ecb50dde4f5646 diff --git a/php_http_api.h b/php_http_api.h index 325378c..052fb1e 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -54,9 +54,7 @@ extern zval *_http_exception_wrap(zval *old_exception, zval *new_exception, zend } #define http_final(ex_ce) \ if (EG(exception)) { \ - zval *exception = http_exception_wrap(EG(exception), NULL, ex_ce); \ - EG(exception) = NULL; \ - zend_throw_exception_object(exception TSRMLS_CC); \ + EG(exception) = http_exception_wrap(EG(exception), NULL, ex_ce); \ } #endif /* ZEND_ENGINE_2 */ @@ -158,6 +156,41 @@ PHP_HTTP_API void _http_parse_params_default_callback(void *ht, const char *key, PHP_HTTP_API STATUS _http_parse_params_ex(const char *params, int flags, http_parse_params_callback cb, void *cb_arg TSRMLS_DC); +#define http_sleep(s) _http_sleep(s) +static inline void _http_sleep(double s) +{ +#define HTTP_DIFFSEC (0.001) +#define HTTP_MLLISEC (1000) +#define HTTP_MCROSEC (1000 * 1000) +#define HTTP_NANOSEC (1000 * 1000 * 1000) +#define HTTP_MSEC(s) (s * HTTP_MLLISEC) +#define HTTP_USEC(s) (s * HTTP_MCROSEC) +#define HTTP_NSEC(s) (s * HTTP_NANOSEC) + +#if defined(PHP_WIN32) + Sleep((DWORD) HTTP_MSEC(s)); +#elif defined(HAVE_USLEEP) + usleep(HTTP_USEC(s)); +#elif defined(HAVE_NANOSLEEP) + struct timespec req, rem; + + req.tv_sec = (time_t) s; + req.tv_nsec = HTTP_NSEC(s) % HTTP_NANOSEC; + + while (nanosleep(&req, &rem) && (errno == EINTR) && (HTTP_NSEC(rem.tv_sec) + rem.tv_nsec) > HTTP_NSEC(HTTP_DIFFSEC))) { + req.tv_sec = rem.tv_sec; + req.tv_nsec = rem.tv_nsec; + } +#else + struct timeval timeout; + + timeout.tv.sec = (time_t) s; + timeout.tv_usec = HTTP_USEC(s) % HTTP_MCROSEC; + + select(0, NULL, NULL, NULL, &timeout); +#endif +} + #define http_locate_body _http_locate_body static inline const char *_http_locate_body(const char *message) {