From b298ed5b70363b89c36c34e807f6144fb81f6c50 Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Mon, 12 Apr 2010 13:10:05 +0000 Subject: [PATCH] - [doc] merge stream_set_read_buffer, equivalent of stream_set_write_buffer for read operations. Fixing possible bad effects while reading devices --- NEWS | 2 ++ ext/standard/basic_functions.c | 6 +++++ ext/standard/streamsfuncs.c | 41 +++++++++++++++++++++++++-------- ext/standard/streamsfuncs.h | 1 + ext/standard/var_unserializer.c | 2 +- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index 0bc7fbb94c..f51132d4c6 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ PHP NEWS - Upgraded bundled sqlite to version 3.6.23.1. (Ilia) - Upgraded bundled PCRE to version 8.02. (Ilia) +- Added stream_set_read_buffer, allows to set the buffer for read operation. + (Pierre). - Added stream filter support to mcrypt extension (ported from mcrypt_filter). (Stas) - Added full_special_chars filter to ext/filter (Rasmus) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 38c608f670..e9a6a8bd60 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2100,6 +2100,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_stream_set_timeout, 0) ZEND_END_ARG_INFO() #endif +ZEND_BEGIN_ARG_INFO(arginfo_stream_set_read_buffer, 0) + ZEND_ARG_INFO(0, fp) + ZEND_ARG_INFO(0, buffer) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO(arginfo_stream_set_write_buffer, 0) ZEND_ARG_INFO(0, fp) ZEND_ARG_INFO(0, buffer) @@ -3104,6 +3109,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */ PHP_FE(fputcsv, arginfo_fputcsv) PHP_FE(flock, arginfo_flock) PHP_FE(get_meta_tags, arginfo_get_meta_tags) + 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) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 6bc2e0598b..170618f76c 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -1372,16 +1372,8 @@ PHP_FUNCTION(stream_set_write_buffer) size_t buff; php_stream *stream; - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) { - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) { + RETURN_FALSE; } php_stream_from_zval(stream, &arg1); @@ -1399,6 +1391,35 @@ PHP_FUNCTION(stream_set_write_buffer) } /* }}} */ +/* {{{ proto int stream_set_read_buffer(resource fp, int buffer) + Set file read buffer */ +PHP_FUNCTION(stream_set_read_buffer) +{ + zval *arg1; + int ret; + long arg2; + size_t buff; + php_stream *stream; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) { + RETURN_FALSE; + } + + php_stream_from_zval(stream, &arg1); + + buff = arg2; + + /* if buff is 0 then set to non-buffered */ + if (buff == 0) { + ret = php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_NONE, NULL); + } else { + ret = php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_FULL, &buff); + } + + RETURN_LONG(ret == 0 ? 0 : EOF); +} +/* }}} */ + /* {{{ proto int stream_socket_enable_crypto(resource stream, bool enable [, int cryptokind [, resource sessionstream]]) Enable or disable a specific kind of crypto on the stream */ PHP_FUNCTION(stream_socket_enable_crypto) diff --git a/ext/standard/streamsfuncs.h b/ext/standard/streamsfuncs.h index 268be381b4..5eb9385e0d 100644 --- a/ext/standard/streamsfuncs.h +++ b/ext/standard/streamsfuncs.h @@ -36,6 +36,7 @@ PHP_FUNCTION(stream_get_contents); PHP_FUNCTION(stream_set_blocking); PHP_FUNCTION(stream_select); PHP_FUNCTION(stream_set_timeout); +PHP_FUNCTION(stream_set_read_buffer); PHP_FUNCTION(stream_set_write_buffer); PHP_FUNCTION(stream_get_transports); PHP_FUNCTION(stream_get_wrappers); diff --git a/ext/standard/var_unserializer.c b/ext/standard/var_unserializer.c index a497224ea9..1ed2710f1f 100644 --- a/ext/standard/var_unserializer.c +++ b/ext/standard/var_unserializer.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.5 on Mon Jan 11 14:20:08 2010 */ +/* Generated by re2c 0.13.5 on Mon Apr 12 10:11:22 2010 */ #line 1 "ext/standard/var_unserializer.re" /* +----------------------------------------------------------------------+ -- 2.40.0