From f671d1bc54d6db164cf4b03a9ef0e1ddcdd39c72 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Tue, 23 Jun 2020 14:16:43 +0300 Subject: Decreased level of some socket close() errors. --- src/nxt_socket.c | 47 +++++++++++++++++++++++++++++++++++------------ src/nxt_socket.h | 2 +- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/nxt_socket.c b/src/nxt_socket.c index cc3d7378..a8e0d514 100644 --- a/src/nxt_socket.c +++ b/src/nxt_socket.c @@ -50,18 +50,6 @@ nxt_socket_create(nxt_task_t *task, nxt_uint_t domain, nxt_uint_t type, } -void -nxt_socket_close(nxt_task_t *task, nxt_socket_t s) -{ - if (nxt_fast_path(close(s) == 0)) { - nxt_debug(task, "socket close(%d)", s); - - } else { - nxt_alert(task, "socket close(%d) failed %E", s, nxt_socket_errno); - } -} - - void nxt_socket_defer_accept(nxt_task_t *task, nxt_socket_t s, nxt_sockaddr_t *sa) { @@ -291,6 +279,41 @@ nxt_socket_shutdown(nxt_task_t *task, nxt_socket_t s, nxt_uint_t how) } +void +nxt_socket_close(nxt_task_t *task, nxt_socket_t s) +{ + nxt_err_t err; + nxt_uint_t level; + + if (nxt_fast_path(close(s) == 0)) { + nxt_debug(task, "socket close(%d)", s); + return; + } + + err = nxt_socket_errno; + + switch (err) { + + case NXT_ENOTCONN: + level = NXT_LOG_DEBUG; + break; + + case NXT_ECONNRESET: + case NXT_ENETDOWN: + case NXT_ENETUNREACH: + case NXT_EHOSTDOWN: + case NXT_EHOSTUNREACH: + level = NXT_LOG_ERR; + break; + + default: + level = NXT_LOG_ALERT; + } + + nxt_log(task, level, "socket close(%d) failed %E", s, err); +} + + nxt_err_t nxt_socket_error(nxt_socket_t s) { diff --git a/src/nxt_socket.h b/src/nxt_socket.h index e39d8e4d..718ad398 100644 --- a/src/nxt_socket.h +++ b/src/nxt_socket.h @@ -93,7 +93,6 @@ typedef union { NXT_EXPORT nxt_socket_t nxt_socket_create(nxt_task_t *task, nxt_uint_t family, nxt_uint_t type, nxt_uint_t protocol, nxt_uint_t flags); -NXT_EXPORT void nxt_socket_close(nxt_task_t *task, nxt_socket_t s); NXT_EXPORT void nxt_socket_defer_accept(nxt_task_t *task, nxt_socket_t s, nxt_sockaddr_t *sa); NXT_EXPORT nxt_int_t nxt_socket_getsockopt(nxt_task_t *task, nxt_socket_t s, @@ -106,6 +105,7 @@ NXT_EXPORT nxt_int_t nxt_socket_connect(nxt_task_t *task, nxt_socket_t s, nxt_sockaddr_t *sa); NXT_EXPORT void nxt_socket_shutdown(nxt_task_t *task, nxt_socket_t s, nxt_uint_t how); +NXT_EXPORT void nxt_socket_close(nxt_task_t *task, nxt_socket_t s); nxt_err_t nxt_socket_error(nxt_socket_t s); nxt_uint_t nxt_socket_error_level(nxt_err_t err); -- cgit