save funccall
[m6w6/ext-http] / php_http_env_response.c
index cb5275248b02f1bde747daef7483f73ee43ff722..4d6ef037471fb9bb02faf0a32f2773e052a631e1 100644 (file)
@@ -6,7 +6,7 @@
     | modification, are permitted provided that the conditions mentioned |
     | in the accompanying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
-    | Copyright (c) 2004-2013, Michael Wallner <mike@php.net>            |
+    | Copyright (c) 2004-2014, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
 */
 
@@ -217,7 +217,9 @@ static size_t output(void *context, char *buf, size_t len TSRMLS_DC)
 {
        php_http_env_response_t *r = context;
 
-       r->ops->write(r, buf, len);
+       if (SUCCESS != r->ops->write(r, buf, len)) {
+               return (size_t) -1;
+       }
 
        /*      we really only need to flush when throttling is enabled,
                because we push the data as fast as possible anyway if not */
@@ -231,7 +233,7 @@ static size_t output(void *context, char *buf, size_t len TSRMLS_DC)
 #define php_http_env_response_send_done(r) php_http_env_response_send_data((r), NULL, 0)
 static STATUS php_http_env_response_send_data(php_http_env_response_t *r, const char *buf, size_t len)
 {
-       size_t chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE;
+       size_t chunks_sent, chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE;
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
        if (r->content.encoder) {
@@ -248,15 +250,16 @@ static STATUS php_http_env_response_send_data(php_http_env_response_t *r, const
                        }
                }
 
-               if (enc_str) {
-                       php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC);
-                       STR_FREE(enc_str);
+               if (!enc_str) {
+                       return SUCCESS;
                }
+               chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC);
+               STR_FREE(enc_str);
        } else {
-               php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC);
+               chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC);
        }
 
-       return SUCCESS;
+       return chunks_sent != (size_t) -1 ? SUCCESS : FAILURE;
 }
 
 php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg TSRMLS_DC)
@@ -996,7 +999,9 @@ static STATUS php_http_env_response_stream_write(php_http_env_response_t *r, con
                }
        }
 
-       php_stream_write(stream_ctx->stream, data_str, data_len);
+       if (data_len != php_stream_write(stream_ctx->stream, data_str, data_len)) {
+               return FAILURE;
+       }
 
        return SUCCESS;
 }
@@ -1089,11 +1094,9 @@ static PHP_METHOD(HttpEnvResponse, __invoke)
 
                PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
 
-               if (obj->body || SUCCESS == php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), (void *) &obj->body TSRMLS_CC)) {
-                       php_http_message_body_append(obj->message->body, ob_str, ob_len);
-                       RETURN_TRUE;
-               }
-               RETURN_FALSE;
+               php_http_message_object_init_body_object(obj);
+               php_http_message_body_append(obj->message->body, ob_str, ob_len);
+               RETURN_TRUE;
        }
 }