diff options
| author | Vladimir Homutov <vl@nginx.com> | 2018-10-03 14:08:51 +0300 |
|---|---|---|
| committer | Vladimir Homutov <vl@nginx.com> | 2018-10-03 14:08:51 +0300 |
| commit | 1305b8414d22610b0820f6df5841418bf98fc370 (patch) | |
| tree | 321727a890c175f7238b6b12662561b9fd44533e /src/event/ngx_event_connect.c | |
| parent | ae1e6e5ec00bf87a0db446b06a1e864b4df59b20 (diff) | |
| download | nginx-1305b8414d22610b0820f6df5841418bf98fc370.tar.gz nginx-1305b8414d22610b0820f6df5841418bf98fc370.tar.bz2 | |
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.
Diffstat (limited to 'src/event/ngx_event_connect.c')
| -rw-r--r-- | src/event/ngx_event_connect.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c index 714fc47de..1ffa7984c 100644 --- 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_transparent(ngx_peer_connection_t *pc, 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_connection_t *pc) } } + 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"); |
