}
+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_http_upstream_ssl_init_connection(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_connection_t *c)
{
- int tcp_nodelay;
ngx_int_t rc;
ngx_http_core_loc_conf_t *clcf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
- if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, 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_http_upstream_finalize_request(r, u,
+ if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
+ ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- c->tcp_nodelay = NGX_TCP_NODELAY_SET;
+ return;
}
}
ngx_http_upstream_send_request_body(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_uint_t do_write)
{
- int tcp_nodelay;
ngx_int_t rc;
ngx_chain_t *out, *cl, *ln;
ngx_connection_t *c;
c = u->peer.connection;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
- if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, 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");
- return NGX_ERROR;
- }
-
- c->tcp_nodelay = NGX_TCP_NODELAY_SET;
+ if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
+ return NGX_ERROR;
}
r->read_event_handler = ngx_http_upstream_read_request_handler;
static void
ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
- int tcp_nodelay;
ssize_t n;
ngx_int_t rc;
ngx_event_pipe_t *p;
return;
}
- if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, 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_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- c->tcp_nodelay = NGX_TCP_NODELAY_SET;
+ if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
+ ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
+ return;
}
n = u->buffer.last - u->buffer.pos;
static void
ngx_http_upstream_upgrade(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
- int tcp_nodelay;
ngx_connection_t *c;
ngx_http_core_loc_conf_t *clcf;
r->write_event_handler = ngx_http_upstream_upgraded_write_downstream;
if (clcf->tcp_nodelay) {
- tcp_nodelay = 1;
-
- if (c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay");
-
- 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_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
- c->tcp_nodelay = NGX_TCP_NODELAY_SET;
+ if (ngx_tcp_nodelay(c) != NGX_OK) {
+ ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
+ return;
}
- if (u->peer.connection->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, u->peer.connection->log, 0,
- "tcp_nodelay");
-
- if (setsockopt(u->peer.connection->fd, IPPROTO_TCP, TCP_NODELAY,
- (const void *) &tcp_nodelay, sizeof(int)) == -1)
- {
- ngx_connection_error(u->peer.connection, ngx_socket_errno,
- "setsockopt(TCP_NODELAY) failed");
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- u->peer.connection->tcp_nodelay = NGX_TCP_NODELAY_SET;
+ if (ngx_tcp_nodelay(u->peer.connection) != NGX_OK) {
+ ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
+ return;
}
}
ngx_stream_core_content_phase(ngx_stream_session_t *s,
ngx_stream_phase_handler_t *ph)
{
- int tcp_nodelay;
ngx_connection_t *c;
ngx_stream_core_srv_conf_t *cscf;
if (c->type == SOCK_STREAM
&& cscf->tcp_nodelay
- && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET)
+ && ngx_tcp_nodelay(c) != NGX_OK)
{
- 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_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
- return NGX_OK;
- }
-
- c->tcp_nodelay = NGX_TCP_NODELAY_SET;
+ ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
+ return NGX_OK;
}
cscf->handler(s);