From: Michael Wallner Date: Mon, 16 Feb 2015 12:13:48 +0000 (+0100) Subject: fix ::toStream() in ZTS X-Git-Tag: RELEASE_2_3_0_RC1~20 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=3f5da039a09164701de8638669fe6e8d4e916970;ds=sidebyside fix ::toStream() in ZTS --- diff --git a/php_http_message.c b/php_http_message.c index efdf053..b7b500b 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -1677,6 +1677,16 @@ static PHP_METHOD(HttpMessage, toString) RETURN_EMPTY_STRING(); } +#ifdef ZTS +static size_t write_to_stream(void *s, const char *str, size_t len) +{ + TSRMLS_FETCH(); + return php_stream_write(s, str, len); +} +#else +# define write_to_stream (php_http_pass_callback_t)_php_stream_write +#endif + ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toStream, 0, 0, 1) ZEND_ARG_INFO(0, stream) ZEND_END_ARG_INFO(); @@ -1691,7 +1701,7 @@ static PHP_METHOD(HttpMessage, toStream) PHP_HTTP_MESSAGE_OBJECT_INIT(obj); php_stream_from_zval(s, &zstream); - php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s); + php_http_message_to_callback(obj->message, write_to_stream, s); } } diff --git a/tests/helper/proxy.inc b/tests/helper/proxy.inc index 61b20dd..363d76f 100644 --- a/tests/helper/proxy.inc +++ b/tests/helper/proxy.inc @@ -16,6 +16,7 @@ serve(function($client) { /* return the initial message as response body */ $response = new http\Env\Response; - $response->getBody()->append($request); + /* avoid OOM with $response->getBody()->append($request); */ + $request->toStream($response->getBody()->getResource()); $response->send($client); }); diff --git a/tests/helper/server.inc b/tests/helper/server.inc index 26f0c50..ed8516b 100644 --- a/tests/helper/server.inc +++ b/tests/helper/server.inc @@ -11,8 +11,13 @@ function serve(callable $cb) { if (getenv("PHP_HTTP_TEST_SSL")) { stream_socket_enable_crypto($client, true, STREAM_CRYPTO_METHOD_SSLv23_SERVER); } - while (!feof($client)) { - $cb($client); + try { + while (!feof($client)) { + $cb($client); + } + } catch (Exception $ex) { + fprintf(STDERR, "%s\n", $ex); + break; } } } while ($select !== false);