changeset 19820:a0e487d9c6f9

lib-http: Clarify http_server_response_*_payload() API and minor change to it Similar to the change in c3a4c93. Nothing used this API yet.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 22 Feb 2016 21:00:41 +0200
parents c1a959cba67a
children f48a7703d596
files src/lib-http/http-server-response.c src/lib-http/http-server.h
diffstat 2 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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 */