change array_list API
[m6w6/ext-http] / php_http_buffer.c
index bd99dc84f1677ce2a766b2c215796691719c7117..5a609be7337441b9e74b4f64e6a334cd29b18f1a 100644 (file)
@@ -72,6 +72,19 @@ PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex(php_http_buffer_t *buf, siz
        return 0;
 }
 
+PHP_HTTP_BUFFER_API char *php_http_buffer_account(php_http_buffer_t *buf, size_t to_account)
+{
+       /* it's probably already too late but check anyway */
+       if (to_account > buf->free) {
+               return NULL;
+       }
+
+       buf->free -= to_account;
+       buf->used += to_account;
+
+       return buf->data + buf->used;
+}
+
 PHP_HTTP_BUFFER_API size_t php_http_buffer_shrink(php_http_buffer_t *buf)
 {
        /* avoid another realloc on fixation */
@@ -356,7 +369,7 @@ PHP_HTTP_BUFFER_API size_t php_http_buffer_chunk_buffer(php_http_buffer_t **s, c
                return chunk_size;
        }
        
-       if (storage->used >= (chunk_size = storage->size >> 1)) {
+       if (storage->used >= chunk_size) {
                *chunk = estrndup(storage->data, chunk_size);
                php_http_buffer_cut(storage, 0, chunk_size);
                return chunk_size;
@@ -369,7 +382,7 @@ PHP_HTTP_BUFFER_API void php_http_buffer_chunked_output(php_http_buffer_t **s, c
 {
        char *chunk = NULL;
        size_t got = 0;
-       
+
        while ((got = php_http_buffer_chunk_buffer(s, data, data_len, &chunk, chunk_len))) {
                passout(opaque, chunk, got TSRMLS_CC);
                if (!chunk_len) {