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;
 }
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to