aboutsummaryrefslogtreecommitdiff
path: root/src/stream/ngx_stream_proxy_module.c
diff options
context:
space:
mode:
authorVladimir Homutov <vl@nginx.com>2015-08-10 12:14:41 +0300
committerVladimir Homutov <vl@nginx.com>2015-08-10 12:14:41 +0300
commitb537def75ef942346122e1f182104851f5e039a0 (patch)
tree2295bbf72011a19b956c402a7866706916e69022 /src/stream/ngx_stream_proxy_module.c
parent50ff8b3c3a3eba0984ce55c63ab8ac07dcb65265 (diff)
downloadnginx-b537def75ef942346122e1f182104851f5e039a0.tar.gz
nginx-b537def75ef942346122e1f182104851f5e039a0.zip
Stream: the "tcp_nodelay" directive.
Diffstat (limited to 'src/stream/ngx_stream_proxy_module.c')
-rw-r--r--src/stream/ngx_stream_proxy_module.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c
index e5ec62e36..852925cbd 100644
--- a/src/stream/ngx_stream_proxy_module.c
+++ b/src/stream/ngx_stream_proxy_module.c
@@ -478,13 +478,35 @@ ngx_stream_proxy_connect(ngx_stream_session_t *s)
static void
ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
{
+ int tcp_nodelay;
u_char *p;
ngx_connection_t *c, *pc;
ngx_log_handler_pt handler;
ngx_stream_upstream_t *u;
+ ngx_stream_core_srv_conf_t *cscf;
ngx_stream_proxy_srv_conf_t *pscf;
u = s->upstream;
+ pc = u->peer.connection;
+
+ cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module);
+
+ if (cscf->tcp_nodelay && pc->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
+ ngx_log_debug0(NGX_LOG_DEBUG_STREAM, pc->log, 0, "tcp_nodelay");
+
+ tcp_nodelay = 1;
+
+ if (setsockopt(pc->fd, IPPROTO_TCP, TCP_NODELAY,
+ (const void *) &tcp_nodelay, sizeof(int)) == -1)
+ {
+ ngx_connection_error(pc, ngx_socket_errno,
+ "setsockopt(TCP_NODELAY) failed");
+ ngx_stream_proxy_next_upstream(s);
+ return;
+ }
+
+ pc->tcp_nodelay = NGX_TCP_NODELAY_SET;
+ }
if (u->proxy_protocol) {
if (ngx_stream_proxy_send_proxy_protocol(s) != NGX_OK) {
@@ -496,8 +518,6 @@ ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
- pc = u->peer.connection;
-
#if (NGX_STREAM_SSL)
if (pscf->ssl && pc->ssl == NULL) {
ngx_stream_proxy_ssl_init_connection(s);