diff options
author | Ruslan Ermilov <ru@nginx.com> | 2017-05-26 22:52:48 +0300 |
---|---|---|
committer | Ruslan Ermilov <ru@nginx.com> | 2017-05-26 22:52:48 +0300 |
commit | b66c18d2d50c53b063cd14a2c3e4c8ff8b1b22a5 (patch) | |
tree | c61e02ac50d38621b454b9972fe42f72fc87f18f /src/core/ngx_connection.c | |
parent | 8644d9491ad3c0eb16bcda1d452aba326e1f4dae (diff) | |
download | nginx-b66c18d2d50c53b063cd14a2c3e4c8ff8b1b22a5.tar.gz nginx-b66c18d2d50c53b063cd14a2c3e4c8ff8b1b22a5.zip |
Introduced ngx_tcp_nodelay().
Diffstat (limited to 'src/core/ngx_connection.c')
-rw-r--r-- | src/core/ngx_connection.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 2af287614..ec4692b0a 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -1346,6 +1346,49 @@ ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s, ngx_int_t +ngx_tcp_nodelay(ngx_connection_t *c) +{ + int tcp_nodelay; + + if (c->tcp_nodelay != NGX_TCP_NODELAY_UNSET) { + return NGX_OK; + } + + ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0, "tcp_nodelay"); + + tcp_nodelay = 1; + + if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, + (const void *) &tcp_nodelay, sizeof(int)) + == -1) + { +#if (NGX_SOLARIS) + if (c->log_error == NGX_ERROR_INFO) { + + /* Solaris returns EINVAL if a socket has been shut down */ + c->log_error = NGX_ERROR_IGNORE_EINVAL; + + ngx_connection_error(c, ngx_socket_errno, + "setsockopt(TCP_NODELAY) failed"); + + c->log_error = NGX_ERROR_INFO; + + return NGX_ERROR; + } +#endif + + ngx_connection_error(c, ngx_socket_errno, + "setsockopt(TCP_NODELAY) failed"); + return NGX_ERROR; + } + + c->tcp_nodelay = NGX_TCP_NODELAY_SET; + + return NGX_OK; +} + + +ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text) { ngx_uint_t level; |