Mercurial > hg > nginx
diff src/event/ngx_event_connect.c @ 7371:8b68d50090e4
Upstream: proxy_socket_keepalive and friends.
The directives enable the use of the SO_KEEPALIVE option on
upstream connections. By default, the value is left unchanged.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Wed, 03 Oct 2018 14:08:51 +0300 |
parents | 91ea68dd1501 |
children | fdc3d40979b0 |
line wrap: on
line diff
--- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -20,7 +20,7 @@ static ngx_int_t ngx_event_connect_set_t ngx_int_t ngx_event_connect_peer(ngx_peer_connection_t *pc) { - int rc, type; + int rc, type, value; #if (NGX_HAVE_IP_BIND_ADDRESS_NO_PORT || NGX_LINUX) in_port_t port; #endif @@ -73,6 +73,18 @@ ngx_event_connect_peer(ngx_peer_connecti } } + if (pc->so_keepalive) { + value = 1; + + if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, + (const void *) &value, sizeof(int)) + == -1) + { + ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, + "setsockopt(SO_KEEPALIVE) failed, ignored"); + } + } + if (ngx_nonblocking(s) == -1) { ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, ngx_nonblocking_n " failed");