Mercurial > dovecot > core-2.2
changeset 19821:f48a7703d596
lib-http: http_server_connection_unref() now always sets *conn=NULL
This makes its behavior consistent with other APIs in Dovecot.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Mon, 22 Feb 2016 21:15:37 +0200 |
parents | a0e487d9c6f9 |
children | 554ef83e133c |
files | src/lib-http/http-server-connection.c src/lib-http/http-server.h |
diffstat | 2 files changed, 24 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-http/http-server-connection.c Mon Feb 22 21:00:41 2016 +0200 +++ b/src/lib-http/http-server-connection.c Mon Feb 22 21:15:37 2016 +0200 @@ -21,6 +21,9 @@ http_server_connection_disconnect(struct http_server_connection *conn, const char *reason); +static bool +http_server_connection_unref_is_closed(struct http_server_connection *conn); + /* * Logging */ @@ -563,8 +566,7 @@ req = http_server_request_new(conn); } - http_server_connection_unref(&conn); - if (conn == NULL || conn->closed) { + if (http_server_connection_unref_is_closed(conn)) { /* connection got closed */ return; } @@ -607,8 +609,7 @@ i_unreached(); } - http_server_connection_unref(&conn); - if (conn == NULL || conn->closed) { + if (http_server_connection_unref_is_closed(conn)) { /* connection got closed */ return; } @@ -715,10 +716,7 @@ /* check whether connection is still viable */ http_server_connection_ref(conn); (void)http_server_connection_check_input(conn); - http_server_connection_unref(&conn); - if (conn == NULL || conn->closed) - return -1; - return 0; + return http_server_connection_unref_is_closed(conn) ? -1 : 0; } void http_server_connection_write_failed(struct http_server_connection *conn, @@ -817,8 +815,7 @@ blocks again, or the connection is closed */ while (!conn->closed && http_server_connection_next_response(conn)); - http_server_connection_unref(&conn); - if (conn == NULL || conn->closed) + if (http_server_connection_unref_is_closed(conn)) return -1; /* accept more requests if possible */ @@ -1025,13 +1022,15 @@ connection_disconnect(&conn->conn); } -void http_server_connection_unref(struct http_server_connection **_conn) +bool http_server_connection_unref(struct http_server_connection **_conn) { struct http_server_connection *conn = *_conn; i_assert(conn->refcount > 0); + + *_conn = NULL; if (--conn->refcount > 0) - return; + return TRUE; http_server_connection_disconnect(conn, NULL); @@ -1049,7 +1048,17 @@ i_free(conn->disconnect_reason); i_free(conn); - *_conn = NULL; + return FALSE; +} + +static bool +http_server_connection_unref_is_closed(struct http_server_connection *conn) +{ + bool closed = conn->closed; + + if (!http_server_connection_unref(&conn)) + closed = TRUE; + return closed; } void http_server_connection_close(struct http_server_connection **_conn,
--- a/src/lib-http/http-server.h Mon Feb 22 21:00:41 2016 +0200 +++ b/src/lib-http/http-server.h Mon Feb 22 21:15:37 2016 +0200 @@ -74,7 +74,8 @@ int fd_in, int fd_out, bool ssl, const struct http_server_callbacks *callbacks, void *context); void http_server_connection_ref(struct http_server_connection *conn); -void http_server_connection_unref(struct http_server_connection **_conn); +/* Returns FALSE if unrefing destroyed the connection entirely */ +bool http_server_connection_unref(struct http_server_connection **_conn); void http_server_connection_close(struct http_server_connection **_conn, const char *reason); const struct http_server_stats *