cvs: php4 /ext/standard file.c file.h /main main.c network.c php_network.h php_streams.h streams.c

From: Date: Tue, 19 Mar 2002 17:49:03 +0000
Subject: cvs: php4 /ext/standard file.c file.h /main main.c network.c php_network.h php_streams.h streams.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10430@lists.php.net to get a copy of this message
wez Tue Mar 19 12:49:03 2002 EDT Modified files: /php4/ext/standard file.c file.h /php4/main main.c network.c php_network.h php_streams.h streams.c Log: fix for bug #16168 Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.215 php4/ext/standard/file.c:1.216 --- php4/ext/standard/file.c:1.215 Tue Mar 19 08:33:07 2002 +++ php4/ext/standard/file.c Tue Mar 19 12:48:57 2002 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.215 2002/03/19 13:33:07 wez Exp $ */ +/* $Id: file.c,v 1.216 2002/03/19 17:48:57 wez Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -126,6 +126,7 @@ zend_hash_init(&FG(ht_persistent_socks), 0, NULL, NULL, 1); FG(fgetss_state) = 0; FG(pclose_ret) = 0; + FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE; } Index: php4/ext/standard/file.h diff -u php4/ext/standard/file.h:1.54 php4/ext/standard/file.h:1.55 --- php4/ext/standard/file.h:1.54 Tue Mar 19 09:35:54 2002 +++ php4/ext/standard/file.h Tue Mar 19 12:48:57 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.h,v 1.54 2002/03/19 14:35:54 wez Exp $ */ +/* $Id: file.h,v 1.55 2002/03/19 17:48:57 wez Exp $ */ /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ @@ -108,6 +108,7 @@ int fgetss_state; int pclose_ret; HashTable ht_persistent_socks; + size_t def_chunk_size; } php_file_globals; #ifdef ZTS Index: php4/main/main.c diff -u php4/main/main.c:1.438 php4/main/main.c:1.439 --- php4/main/main.c:1.438 Mon Mar 18 13:54:30 2002 +++ php4/main/main.c Tue Mar 19 12:48:59 2002 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c,v 1.438 2002/03/18 18:54:30 wez Exp $ */ +/* $Id: main.c,v 1.439 2002/03/19 17:48:59 wez Exp $ */ /* {{{ includes */ @@ -565,13 +565,15 @@ { FILE *retval = NULL; php_stream *stream; + size_t old_chunk_size; TSRMLS_FETCH(); + old_chunk_size = FG(def_chunk_size); + FG(def_chunk_size) = 1; stream = php_stream_open_wrapper((char *)filename, "rb", USE_PATH|IGNORE_URL_WIN|REPORT_ERRORS, opened_path); + FG(def_chunk_size) = old_chunk_size; + if (stream) { - /* no need for us to check the stream type here */ - php_stream_sock_set_chunk_size(stream, 1 TSRMLS_CC); - /* when this succeeds, stream either has or will be freed automatically */ if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, (void**)&retval, REPORT_ERRORS) == FAILURE) Index: php4/main/network.c diff -u php4/main/network.c:1.42 php4/main/network.c:1.43 --- php4/main/network.c:1.42 Mon Mar 18 22:49:03 2002 +++ php4/main/network.c Tue Mar 19 12:48:59 2002 @@ -15,9 +15,8 @@ | Author: Stig Venaas <venaas@uninett.no> | +----------------------------------------------------------------------+ */ -/* $Id: network.c,v 1.42 2002/03/19 03:49:03 wez Exp $ */ +/* $Id: network.c,v 1.43 2002/03/19 17:48:59 wez Exp $ */ -#define PHP_SOCK_CHUNK_SIZE 8192 #define MAX_CHUNKS_PER_READ 10 #include "php.h" @@ -71,6 +70,8 @@ #include <sys/un.h> #endif +#include "ext/standard/file.h" + #ifdef PHP_WIN32 # define SOCK_ERR INVALID_SOCKET # define SOCK_CONN_ERR SOCKET_ERROR @@ -425,7 +426,7 @@ memset(sock, 0, sizeof(php_netstream_data_t)); sock->is_blocked = 1; - sock->chunk_size = PHP_SOCK_CHUNK_SIZE; + sock->chunk_size = FG(def_chunk_size); sock->timeout.tv_sec = -1; sock->socket = socket; @@ -780,7 +781,7 @@ if (ret) { /* DANGER!: data buffered in stream->readbuf will be forgotten! */ if (TOREAD(sock) > 0) - zend_error(E_WARNING, "%s(): buffered data lost during conversion to FILE*!", get_active_function_name(TSRMLS_C)); + zend_error(E_WARNING, "%s(): %d bytes of buffered data lost during conversion to FILE*!", get_active_function_name(TSRMLS_C), TOREAD(sock)); *ret = fdopen(sock->socket, stream->mode); if (*ret) return SUCCESS; Index: php4/main/php_network.h diff -u php4/main/php_network.h:1.19 php4/main/php_network.h:1.20 --- php4/main/php_network.h:1.19 Mon Mar 18 13:54:32 2002 +++ php4/main/php_network.h Tue Mar 19 12:49:00 2002 @@ -15,7 +15,7 @@ | Author: Stig Venaas <venaas@uninett.no> | +----------------------------------------------------------------------+ */ -/* $Id: php_network.h,v 1.19 2002/03/18 18:54:32 wez Exp $ */ +/* $Id: php_network.h,v 1.20 2002/03/19 17:49:00 wez Exp $ */ #ifndef _PHP_NETWORK_H #define _PHP_NETWORK_H @@ -72,6 +72,8 @@ # define SOCK_CONN_ERR -1 # define SOCK_RECV_ERR -1 #endif + +#define PHP_SOCK_CHUNK_SIZE 8192 #ifdef HAVE_SOCKADDR_STORAGE typedef struct sockaddr_storage php_sockaddr_storage; Index: php4/main/php_streams.h diff -u php4/main/php_streams.h:1.20 php4/main/php_streams.h:1.21 --- php4/main/php_streams.h:1.20 Tue Mar 19 09:35:55 2002 +++ php4/main/php_streams.h Tue Mar 19 12:49:02 2002 @@ -69,7 +69,7 @@ #define php_stream_open_wrapper_rel(path, mode, options, opened) _php_stream_open_wrapper((path), (mode), (options), (opened) STREAMS_REL_CC TSRMLS_CC) -#define php_stream_make_seekable_rel(origstream, newstream) _php_stream_make_seekable(origstream, newstream STREAMS_REL_CC TSRMLS_CC) +#define php_stream_make_seekable_rel(origstream, newstream, flags) _php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_REL_CC TSRMLS_CC) /* }}} */ @@ -266,8 +266,10 @@ #define PHP_STREAM_FAILED 2 /* an error occurred while attempting conversion */ #define PHP_STREAM_CRITICAL 3 /* an error occurred; origstream is in an unknown state; you should close origstream */ /* DO NOT call this on streams that are referenced by resources! */ -PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream STREAMS_DC TSRMLS_DC); -#define php_stream_make_seekable(origstream, newstream) _php_stream_make_seekable(origstream, newstream STREAMS_CC TSRMLS_CC) +#define PHP_STREAM_NO_PREFERENCE 0 +#define PHP_STREAM_PREFER_STDIO 1 +PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream, int flags STREAMS_DC TSRMLS_DC); +#define php_stream_make_seekable(origstream, newstream, flags) _php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_CC TSRMLS_CC) /* for user-space streams */ Index: php4/main/streams.c diff -u php4/main/streams.c:1.35 php4/main/streams.c:1.36 --- php4/main/streams.c:1.35 Tue Mar 19 09:35:55 2002 +++ php4/main/streams.c Tue Mar 19 12:49:02 2002 @@ -831,17 +831,13 @@ goto exit_success; } - { - TSRMLS_FETCH(); - - /* must be either: - a) programmer error - b) no memory - -> lets bail - */ - zend_error(E_ERROR, "%s(): fopencookie failed", get_active_function_name(TSRMLS_C)); - return FAILURE; - } + /* must be either: + a) programmer error + b) no memory + -> lets bail + */ + zend_error(E_ERROR, "%s(): fopencookie failed", get_active_function_name(TSRMLS_C)); + return FAILURE; #endif goto exit_fail; @@ -990,7 +986,7 @@ if (stream != NULL && (options & STREAM_MUST_SEEK)) { php_stream *newstream; - switch(php_stream_make_seekable_rel(stream, &newstream)) { + switch(php_stream_make_seekable_rel(stream, &newstream, PHP_STREAM_NO_PREFERENCE)) { case PHP_STREAM_UNCHANGED: return stream; case PHP_STREAM_RELEASED: @@ -1018,7 +1014,9 @@ return stream; } -PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream STREAMS_DC TSRMLS_DC) +#define PHP_STREAM_MAX_MEM 2 * 1024 * 1024 + +PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream, int flags STREAMS_DC TSRMLS_DC) { assert(newstream != NULL); @@ -1031,7 +1029,10 @@ /* Use a tmpfile and copy the old streams contents into it */ - *newstream = php_stream_fopen_tmpfile(); + if (flags & PHP_STREAM_PREFER_STDIO) + *newstream = php_stream_fopen_tmpfile(); + else + *newstream = php_stream_temp_create(TEMP_STREAM_DEFAULT, PHP_STREAM_MAX_MEM); if (*newstream == NULL) return PHP_STREAM_FAILED;

« previous php.cvs (#10430) next »