From a3a5157286a7a3cca159926801f0a5b3936d17c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Sat, 19 Feb 2011 01:28:37 +0000 Subject: [PATCH] - PHP_STREAM_OPTION_WRITE_BUFFER no longer disables the read buffer of a plain stream when 0 is given as the value. - PHP_STREAM_OPTION_WRITE_BUFFER no longer changes the chunk size in socket streams. - Added stream_set_chunk_size() function. - Some signedness fixes. - Test for commit r308474, now that it's possible to actually test it. --- UPGRADING | 5 +- ext/standard/basic_functions.c | 6 ++ ext/standard/streamsfuncs.c | 41 +++++++- ext/standard/streamsfuncs.h | 1 + ext/standard/tests/file/userstreams_006.phpt | 38 ++++++++ .../tests/streams/stream_set_chunk_size.phpt | 93 +++++++++++++++++++ main/streams/plain_wrapper.c | 3 - main/streams/xp_socket.c | 4 - 8 files changed, 180 insertions(+), 11 deletions(-) create mode 100644 ext/standard/tests/file/userstreams_006.phpt create mode 100644 ext/standard/tests/streams/stream_set_chunk_size.phpt diff --git a/UPGRADING b/UPGRADING index 64c3cc218e..69b58bb709 100755 --- a/UPGRADING +++ b/UPGRADING @@ -164,7 +164,9 @@ UPGRADE NOTES - PHP X.Y strings. This breaks code that iterated the resulting stream array using a numeric index, but makes easier to identify which of the passed streams are present in the result. - +- stream_set_write_buffer() no longer disables the read buffer of a plain + stream when 0 is given as the second argument. +- stream_set_write_buffer() no longer changes the chunk size in socket streams. =================================== 5. Changes made to existing methods @@ -325,6 +327,7 @@ UPGRADE NOTES - PHP X.Y - get_declared_traits() - http_response_code() - trait_exists() + - stream_set_chunk_size() f. New global constants diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index f3341d5e7b..f7f1110237 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2117,6 +2117,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_stream_set_write_buffer, 0) ZEND_ARG_INFO(0, fp) ZEND_ARG_INFO(0, buffer) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_stream_set_chunk_size, 0) + ZEND_ARG_INFO(0, fp) + ZEND_ARG_INFO(0, chunk_size) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_stream_socket_enable_crypto, 0, 0, 2) ZEND_ARG_INFO(0, stream) @@ -3119,6 +3124,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(stream_set_read_buffer, arginfo_stream_set_read_buffer) PHP_FE(stream_set_write_buffer, arginfo_stream_set_write_buffer) PHP_FALIAS(set_file_buffer, stream_set_write_buffer, arginfo_stream_set_write_buffer) + PHP_FE(stream_set_chunk_size, arginfo_stream_set_chunk_size) PHP_DEP_FALIAS(set_socket_blocking, stream_set_blocking, arginfo_stream_set_blocking) PHP_FE(stream_set_blocking, arginfo_stream_set_blocking) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 9372d4d3f5..befb13fd7a 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -557,7 +557,7 @@ PHP_FUNCTION(stream_get_transports) { HashTable *stream_xport_hash; char *stream_xport; - int stream_xport_len; + uint stream_xport_len; ulong num_key; if (zend_parse_parameters_none() == FAILURE) { @@ -586,7 +586,8 @@ PHP_FUNCTION(stream_get_wrappers) { HashTable *url_stream_wrappers_hash; char *stream_protocol; - int key_flags, stream_protocol_len = 0; + int key_flags; + uint stream_protocol_len = 0; ulong num_key; if (zend_parse_parameters_none() == FAILURE) { @@ -924,7 +925,7 @@ static int parse_context_options(php_stream_context *context, zval *options TSRM HashPosition pos, opos; zval **wval, **oval; char *wkey, *okey; - int wkey_len, okey_len; + uint wkey_len, okey_len; int ret = SUCCESS; ulong num_key; @@ -1433,6 +1434,40 @@ PHP_FUNCTION(stream_set_write_buffer) } /* }}} */ +/* {{{ proto int stream_set_chunk_size(resource fp, int chunk_size) + Set the stream chunk size */ +PHP_FUNCTION(stream_set_chunk_size) +{ + int ret; + long csize; + zval *zstream; + php_stream *stream; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zstream, &csize) == FAILURE) { + RETURN_FALSE; + } + + if (csize <= 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size must be a positive integer, given %ld", csize); + RETURN_FALSE; + } + /* stream.chunk_size is actually a size_t, but php_stream_set_option + * can only use an int to accept the new value and return the old one. + * In any case, values larger than INT_MAX for a chunk size make no sense. + */ + if (csize > INT_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size cannot be larger than %d", INT_MAX); + RETURN_FALSE; + } + + php_stream_from_zval(stream, &zstream); + + ret = php_stream_set_option(stream, PHP_STREAM_OPTION_SET_CHUNK_SIZE, (int)csize, NULL); + + RETURN_LONG(ret > 0 ? (long)ret : (long)EOF); +} +/* }}} */ + /* {{{ proto int stream_set_read_buffer(resource fp, int buffer) Set file read buffer */ PHP_FUNCTION(stream_set_read_buffer) diff --git a/ext/standard/streamsfuncs.h b/ext/standard/streamsfuncs.h index 4d2c093f63..c1e22fd1cc 100644 --- a/ext/standard/streamsfuncs.h +++ b/ext/standard/streamsfuncs.h @@ -38,6 +38,7 @@ PHP_FUNCTION(stream_select); PHP_FUNCTION(stream_set_timeout); PHP_FUNCTION(stream_set_read_buffer); PHP_FUNCTION(stream_set_write_buffer); +PHP_FUNCTION(stream_set_chunk_size); PHP_FUNCTION(stream_get_transports); PHP_FUNCTION(stream_get_wrappers); PHP_FUNCTION(stream_get_line); diff --git a/ext/standard/tests/file/userstreams_006.phpt b/ext/standard/tests/file/userstreams_006.phpt new file mode 100644 index 0000000000..69ebd8d0a9 --- /dev/null +++ b/ext/standard/tests/file/userstreams_006.phpt @@ -0,0 +1,38 @@ +--TEST-- +User-space streams: set_options returns "not implemented" for unhandled option types +--FILE-- +flags |= PHP_STREAM_FLAG_NO_BUFFER; return setvbuf(data->file, NULL, _IONBF, 0); case PHP_STREAM_BUFFER_LINE: - stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER; return setvbuf(data->file, NULL, _IOLBF, size); case PHP_STREAM_BUFFER_FULL: - stream->flags ^= PHP_STREAM_FLAG_NO_BUFFER; return setvbuf(data->file, NULL, _IOFBF, size); default: diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index a085e859ed..7ddf8e1a34 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -400,10 +400,6 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void } #endif - case PHP_STREAM_OPTION_WRITE_BUFFER: - php_stream_set_chunk_size(stream, (ptrparam ? *(size_t *)ptrparam : PHP_SOCK_CHUNK_SIZE)); - return PHP_STREAM_OPTION_RETURN_OK; - default: return PHP_STREAM_OPTION_RETURN_NOTIMPL; } -- 2.40.0