# HG changeset patch # User Timo Sirainen # Date 1456167641 -7200 # Node ID a0e487d9c6f955877f60f971face83e31f995802 # Parent c1a959cba67ab27f96b181f67f78448f8f30d78d lib-http: Clarify http_server_response_*_payload() API and minor change to it Similar to the change in c3a4c93. Nothing used this API yet. diff -r c1a959cba67a -r a0e487d9c6f9 src/lib-http/http-server-response.c --- a/src/lib-http/http-server-response.c Mon Feb 22 20:58:03 2016 +0200 +++ b/src/lib-http/http-server-response.c Mon Feb 22 21:00:41 2016 +0200 @@ -420,6 +420,7 @@ { struct http_server_response *resp = *_resp; struct const_iovec iov; + int ret; i_assert(resp->blocking_output == NULL); @@ -430,16 +431,27 @@ 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) diff -r c1a959cba67a -r a0e487d9c6f9 src/lib-http/http-server.h --- a/src/lib-http/http-server.h Mon Feb 22 20:58:03 2016 +0200 +++ b/src/lib-http/http-server.h Mon Feb 22 21:00:41 2016 +0200 @@ -186,9 +186,13 @@ /* 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 */