]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: Clarify http_server_response_*_payload() API and minor change to it
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 22 Feb 2016 19:00:41 +0000 (21:00 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 22 Feb 2016 19:00:41 +0000 (21:00 +0200)
Similar to the change in c3a4c93. Nothing used this API yet.

src/lib-http/http-server-response.c
src/lib-http/http-server.h

index 539739d809ed8c45e2e0e201046ff48403a5c1a2..e2fc03bf732d85e7496e87c0c0f7382b3ef42a24 100644 (file)
@@ -420,6 +420,7 @@ int http_server_response_send_payload(struct http_server_response **_resp,
 {
        struct http_server_response *resp = *_resp;
        struct const_iovec iov;
+       int ret;
 
        i_assert(resp->blocking_output == NULL);
 
@@ -430,16 +431,27 @@ int http_server_response_send_payload(struct http_server_response **_resp,
        memset(&iov, 0, sizeof(iov));
        iov.iov_base = data;
        iov.iov_len = size;
-       return http_server_response_output_payload(_resp, &iov, 1);
+       ret = http_server_response_output_payload(&resp, &iov, 1);
+       if (ret < 0)
+               *_resp = NULL;
+       else {
+               i_assert(ret == 0);
+               i_assert(resp != NULL);
+       }
+       return ret;
 }
 
 int http_server_response_finish_payload(struct http_server_response **_resp)
 {
        struct http_server_response *resp = *_resp;
+       int ret;
 
        i_assert(resp->blocking_output == NULL);
 
-       return http_server_response_output_payload(_resp, NULL, 0);
+       *_resp = NULL;
+       ret = http_server_response_output_payload(&resp, NULL, 0);
+       i_assert(ret != 0);
+       return ret < 0 ? -1 : 0;
 }
 
 void http_server_response_abort_payload(struct http_server_response **_resp)
index 78f48db580624cd68c90bfe5aa923888a2845644..8fc1dd06c8bae0f313eca4a2cd9c92117eab7e5c 100644 (file)
@@ -186,9 +186,13 @@ void http_server_switch_ioloop(struct http_server *server);
 
 /* submits response and blocks until provided payload is sent. Multiple calls
    are allowed; payload transmission is finished with
-   http_server_response_finish_payload(). */
+   http_server_response_finish_payload(). If the sending fails, returns -1
+   and sets resp=NULL to indicate that the response was freed, otherwise
+   returns 0 and resp is unchanged. */
 int http_server_response_send_payload(struct http_server_response **resp,
        const unsigned char *data, size_t size);
+/* Finish sending the payload. Always frees resp and sets it to NULL.
+   Returns 0 on success, -1 on error. */
 int http_server_response_finish_payload(struct http_server_response **resp);
 /* abort response payload transmission prematurely. this closes the associated
    connection */