- fix sending userspace streams (only reading 8k at once)
authorMichael Wallner <mike@php.net>
Mon, 27 Mar 2006 17:38:21 +0000 (17:38 +0000)
committerMichael Wallner <mike@php.net>
Mon, 27 Mar 2006 17:38:21 +0000 (17:38 +0000)
# clean up http_response_data_fetch() at the same run

http_send_api.c
package2.xml

index fd4c4745b627f3ab5d05df27d11b1731a18162d5..f8bb733e9fc9aefde6e8192c0b781ea6cb1132c8 100644 (file)
@@ -99,12 +99,12 @@ static inline void _http_send_response_data_plain(void **buffer, const char *dat
 }
 /* }}} */
 
-#define HTTP_CHUNK_AVAIL(len, cs) ((len -= cs) >= 0)
 /* {{{ http_send_response_data_fetch */
 #define http_send_response_data_fetch(b, d, l, m, s, e) _http_send_response_data_fetch((b), (d), (l), (m), (s), (e) TSRMLS_CC)
 static inline void _http_send_response_data_fetch(void **buffer, const void *data, size_t data_len, http_send_mode mode, size_t begin, size_t end TSRMLS_DC)
 {
-       long len = end - begin, chunk_size = 40960;
+       char *buf;
+       long got, len = end - begin;
        
        switch (mode)
        {
@@ -113,16 +113,14 @@ static inline void _http_send_response_data_fetch(void **buffer, const void *dat
                        php_stream *s = (php_stream *) data;
 
                        if (SUCCESS == php_stream_seek(s, begin, SEEK_SET)) {
-                               char *buf = emalloc(chunk_size);
-
-                               while (HTTP_CHUNK_AVAIL(len, chunk_size)) {
-                                       http_send_response_data_plain(buffer, buf, php_stream_read(s, buf, chunk_size));
-                               }
-                               /* read & write left over */
-                               if (len) {
-                                       http_send_response_data_plain(buffer, buf, php_stream_read(s, buf, chunk_size + len));
+                               buf = emalloc(HTTP_SENDBUF_SIZE);
+                               
+                               while (len > 0) {
+                                       got = php_stream_read(s, buf, MIN(len, HTTP_SENDBUF_SIZE));
+                                       http_send_response_data_plain(buffer, buf, got);
+                                       len -= got;
                                }
-       
+                               
                                efree(buf);
                        }
                }
@@ -130,15 +128,13 @@ static inline void _http_send_response_data_fetch(void **buffer, const void *dat
 
                case SEND_DATA:
                {
-                       char *s = (char *) data + begin;
-
-                       while (HTTP_CHUNK_AVAIL(len, chunk_size)) {
-                               http_send_response_data_plain(buffer, s, chunk_size);
-                               s += chunk_size;
-                       }
-                       /* write left over */
-                       if (len) {
-                               http_send_response_data_plain(buffer, s, chunk_size + len);
+                       buf = (char *) data + begin;
+                       
+                       while (len > 0) {
+                               got = MIN(len, HTTP_SENDBUF_SIZE);
+                               http_send_response_data_plain(buffer, buf, got);
+                               len -= got;
+                               buf += got;
                        }
                }
                break;
index fe78373f13b4b7c07e7c5b7f3dd6958bbacce159..647e072f9680aac4725c199c697a40fd21758c0a 100644 (file)
@@ -48,6 +48,7 @@ HttpResponse
  <notes><![CDATA[
 * Fixed Bug #7192: Build against libcurl >= 7.15.2 fails
 * Fixed access of super globals
+* Fixed sending userspace streams
 ]]></notes>
  <contents>
   <dir name="/">