{
struct http_server_response *resp = *_resp;
struct const_iovec iov;
+ int ret;
i_assert(resp->blocking_output == NULL);
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)
/* 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 */