comparison src/stream/ngx_stream_core_module.c @ 7007:ed1101bbf19f

Introduced ngx_tcp_nodelay().
author Ruslan Ermilov <ru@nginx.com>
date Fri, 26 May 2017 22:52:48 +0300
parents d7ce41bdf050
children 7f955d3b9a0d
comparison
equal deleted inserted replaced
7006:9552758a786e 7007:ed1101bbf19f
307 307
308 ngx_int_t 308 ngx_int_t
309 ngx_stream_core_content_phase(ngx_stream_session_t *s, 309 ngx_stream_core_content_phase(ngx_stream_session_t *s,
310 ngx_stream_phase_handler_t *ph) 310 ngx_stream_phase_handler_t *ph)
311 { 311 {
312 int tcp_nodelay;
313 ngx_connection_t *c; 312 ngx_connection_t *c;
314 ngx_stream_core_srv_conf_t *cscf; 313 ngx_stream_core_srv_conf_t *cscf;
315 314
316 c = s->connection; 315 c = s->connection;
317 316
319 318
320 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); 319 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module);
321 320
322 if (c->type == SOCK_STREAM 321 if (c->type == SOCK_STREAM
323 && cscf->tcp_nodelay 322 && cscf->tcp_nodelay
324 && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) 323 && ngx_tcp_nodelay(c) != NGX_OK)
325 { 324 {
326 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, "tcp_nodelay"); 325 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
327 326 return NGX_OK;
328 tcp_nodelay = 1;
329
330 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,
331 (const void *) &tcp_nodelay, sizeof(int)) == -1)
332 {
333 ngx_connection_error(c, ngx_socket_errno,
334 "setsockopt(TCP_NODELAY) failed");
335 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
336 return NGX_OK;
337 }
338
339 c->tcp_nodelay = NGX_TCP_NODELAY_SET;
340 } 327 }
341 328
342 cscf->handler(s); 329 cscf->handler(s);
343 330
344 return NGX_OK; 331 return NGX_OK;