Modified: php/php-src/trunk/UPGRADING =================================================================== --- php/php-src/trunk/UPGRADING 2011-02-19 01:11:32 UTC (rev 308476) +++ php/php-src/trunk/UPGRADING 2011-02-19 01:28:37 UTC (rev 308477) @@ -164,7 +164,9 @@ 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 @@ - get_declared_traits() - http_response_code() - trait_exists() + - stream_set_chunk_size() f. New global constants Modified: php/php-src/trunk/ext/standard/basic_functions.c =================================================================== --- php/php-src/trunk/ext/standard/basic_functions.c 2011-02-19 01:11:32 UTC (rev 308476) +++ php/php-src/trunk/ext/standard/basic_functions.c 2011-02-19 01:28:37 UTC (rev 308477) @@ -2117,6 +2117,11 @@ 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 @@ 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) Modified: php/php-src/trunk/ext/standard/streamsfuncs.c =================================================================== --- php/php-src/trunk/ext/standard/streamsfuncs.c 2011-02-19 01:11:32 UTC (rev 308476) +++ php/php-src/trunk/ext/standard/streamsfuncs.c 2011-02-19 01:28:37 UTC (rev 308477) @@ -557,7 +557,7 @@ { 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 @@ { 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 @@ 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 @@ } /* }}} */ +/* {{{ 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) Modified: php/php-src/trunk/ext/standard/streamsfuncs.h =================================================================== --- php/php-src/trunk/ext/standard/streamsfuncs.h 2011-02-19 01:11:32 UTC (rev 308476) +++ php/php-src/trunk/ext/standard/streamsfuncs.h 2011-02-19 01:28:37 UTC (rev 308477) @@ -38,6 +38,7 @@ 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); Added: php/php-src/trunk/ext/standard/tests/file/userstreams_006.phpt =================================================================== --- php/php-src/trunk/ext/standard/tests/file/userstreams_006.phpt (rev 0) +++ php/php-src/trunk/ext/standard/tests/file/userstreams_006.phpt 2011-02-19 01:28:37 UTC (rev 308477) @@ -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: Modified: php/php-src/trunk/main/streams/xp_socket.c =================================================================== --- php/php-src/trunk/main/streams/xp_socket.c 2011-02-19 01:11:32 UTC (rev 308476) +++ php/php-src/trunk/main/streams/xp_socket.c 2011-02-19 01:28:37 UTC (rev 308477) @@ -400,10 +400,6 @@ } #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; }