cvs: php4 /main streams.c

From: Date: Sat, 12 Oct 2002 02:31:43 +0000
Subject: cvs: php4 /main streams.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-14861@lists.php.net to get a copy of this message
wez Fri Oct 11 22:31:43 2002 EDT Modified files: /php4/main streams.c Log: Write in blocks of the current chunk_size for a stream. Should resolve problems with network writes. Index: php4/main/streams.c diff -u php4/main/streams.c:1.99 php4/main/streams.c:1.100 --- php4/main/streams.c:1.99 Sun Oct 6 23:12:06 2002 +++ php4/main/streams.c Fri Oct 11 22:31:42 2002 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.99 2002/10/07 03:12:06 sas Exp $ */ +/* $Id: streams.c,v 1.100 2002/10/12 02:31:42 wez Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -759,18 +759,31 @@ PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) { - size_t didwrite; + size_t didwrite = 0, towrite, justwrote; assert(stream); if (buf == NULL || count == 0 || stream->ops->write == NULL) return 0; - if (stream->filterhead) { - didwrite = stream->filterhead->fops->write(stream, stream->filterhead, buf, count TSRMLS_CC); - } else { - didwrite = stream->ops->write(stream, buf, count TSRMLS_CC); + while (count > 0) { + towrite = count; + if (towrite > stream->chunk_size) + towrite = stream->chunk_size; + + if (stream->filterhead) { + justwrote = stream->filterhead->fops->write(stream, stream->filterhead, buf, towrite TSRMLS_CC); + } else { + justwrote = stream->ops->write(stream, buf, towrite TSRMLS_CC); + } + if (justwrote > 0) { + stream->position += justwrote; + buf += justwrote; + count -= justwrote; + didwrite += justwrote; + } else { + break; + } } - stream->position += didwrite; return didwrite; }

« previous php.cvs (#14861) next »