Mercurial > hg > nginx
diff src/stream/ngx_stream_handler.c @ 6221:7565e056fad6
Stream: the "tcp_nodelay" directive.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Mon, 10 Aug 2015 12:14:41 +0300 |
parents | 0dcef374b8bb |
children | d1f94042c29c |
line wrap: on
line diff
--- a/src/stream/ngx_stream_handler.c Tue Aug 11 16:28:55 2015 +0300 +++ b/src/stream/ngx_stream_handler.c Mon Aug 10 12:14:41 2015 +0300 @@ -23,6 +23,7 @@ void ngx_stream_init_connection(ngx_connection_t *c) { + int tcp_nodelay; u_char text[NGX_SOCKADDR_STRLEN]; size_t len; ngx_int_t rc; @@ -165,6 +166,24 @@ } } + if (cscf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) { + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, "tcp_nodelay"); + + tcp_nodelay = 1; + + if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, + (const void *) &tcp_nodelay, sizeof(int)) == -1) + { + ngx_connection_error(c, ngx_socket_errno, + "setsockopt(TCP_NODELAY) failed"); + ngx_stream_close_connection(c); + return; + } + + c->tcp_nodelay = NGX_TCP_NODELAY_SET; + } + + #if (NGX_STREAM_SSL) { ngx_stream_ssl_conf_t *sslcf;