summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2002-03-19 17:49:02 +0000
committerWez Furlong <wez@php.net>2002-03-19 17:49:02 +0000
commit14a3911866c0f69f4e5eafc8f7d320878d1b995c (patch)
tree561d813ef64f5fb9a27bc0f2ca4615c846b96d6e
parentb92f2da5fa2fd69de34f3f0136078db7410ae15f (diff)
downloadphp-git-14a3911866c0f69f4e5eafc8f7d320878d1b995c.tar.gz
fix for bug #16168
-rw-r--r--ext/standard/file.c1
-rw-r--r--ext/standard/file.h1
-rw-r--r--main/main.c8
-rw-r--r--main/network.c7
-rw-r--r--main/php_network.h2
-rwxr-xr-xmain/php_streams.h8
-rwxr-xr-xmain/streams.c29
7 files changed, 33 insertions, 23 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 727faa96ca..a58b511902 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -126,6 +126,7 @@ static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC)
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;
}
diff --git a/ext/standard/file.h b/ext/standard/file.h
index ba9fb54dae..54d63469d1 100644
--- a/ext/standard/file.h
+++ b/ext/standard/file.h
@@ -108,6 +108,7 @@ typedef struct {
int fgetss_state;
int pclose_ret;
HashTable ht_persistent_socks;
+ size_t def_chunk_size;
} php_file_globals;
#ifdef ZTS
diff --git a/main/main.c b/main/main.c
index b7abac4af2..e6b8c8f0fd 100644
--- a/main/main.c
+++ b/main/main.c
@@ -565,13 +565,15 @@ static FILE *php_fopen_wrapper_for_zend(const char *filename, char **opened_path
{
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)
diff --git a/main/network.c b/main/network.c
index 0d80527018..be15ae2677 100644
--- a/main/network.c
+++ b/main/network.c
@@ -17,7 +17,6 @@
*/
/* $Id$ */
-#define PHP_SOCK_CHUNK_SIZE 8192
#define MAX_CHUNKS_PER_READ 10
#include "php.h"
@@ -71,6 +70,8 @@ int inet_aton(const char *, struct in_addr *);
#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 @@ PHPAPI php_stream *_php_stream_sock_open_from_socket(int socket, int persistent
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 @@ static int php_sockop_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
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;
diff --git a/main/php_network.h b/main/php_network.h
index 3d1f29a831..37e0a1add5 100644
--- a/main/php_network.h
+++ b/main/php_network.h
@@ -73,6 +73,8 @@
# define SOCK_RECV_ERR -1
#endif
+#define PHP_SOCK_CHUNK_SIZE 8192
+
#ifdef HAVE_SOCKADDR_STORAGE
typedef struct sockaddr_storage php_sockaddr_storage;
#else
diff --git a/main/php_streams.h b/main/php_streams.h
index 8d264f021d..a590c9c94f 100755
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -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 @@ PHPAPI php_stream *_php_stream_open_wrapper(char *path, char *mode, int options,
#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 */
diff --git a/main/streams.c b/main/streams.c
index 24393fed1d..9665d8e240 100755
--- a/main/streams.c
+++ b/main/streams.c
@@ -831,17 +831,13 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show
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 @@ out:
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 @@ out:
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 @@ PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstr
/* 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;