X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_api.h;h=2e6efca9fdee5464b5b1b844f033229755133699;hb=2c0c193bdcfaa2e3c6b336da078f371e96fcec52;hp=325378c4d0ec3d2e167d6efaafa8c36ccc196ca4;hpb=9676c81efbb8f180fa189d71a7ecb50dde4f5646;p=m6w6%2Fext-http diff --git a/php_http_api.h b/php_http_api.h index 325378c..2e6efca 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,62 @@ 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_str _http_locate_str +static inline const char *_http_locate_str(const char *h, size_t h_len, const char *n, size_t n_len) +{ + const char *p, *e; + + if (n_len && h_len) { + e = h + h_len; + do { + if (*h == *n) { + for (p = n; *p == h[p-n]; ++p) { + if (p == n+n_len-1) { + return h; + } + } + } + } while (h++ != e); + } + + return NULL; +} + #define http_locate_body _http_locate_body static inline const char *_http_locate_body(const char *message) {