Mercurial > hg > nginx
comparison src/core/ngx_connection.c @ 4323:c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
The "so_keepalive" directive in mail module was deprecated.
Thanks to Vsevolod Stakhov for initial work.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 05 Dec 2011 08:06:15 +0000 |
parents | b044d6553d52 |
children | d620f497c50f |
comparison
equal
deleted
inserted
replaced
4322:acd8d267f557 | 4323:c4513d4dd024 |
---|---|
460 | 460 |
461 | 461 |
462 void | 462 void |
463 ngx_configure_listening_sockets(ngx_cycle_t *cycle) | 463 ngx_configure_listening_sockets(ngx_cycle_t *cycle) |
464 { | 464 { |
465 int keepalive; | |
465 ngx_uint_t i; | 466 ngx_uint_t i; |
466 ngx_listening_t *ls; | 467 ngx_listening_t *ls; |
467 | 468 |
468 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) | 469 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) |
469 struct accept_filter_arg af; | 470 struct accept_filter_arg af; |
496 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | 497 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
497 "setsockopt(SO_SNDBUF, %d) %V failed, ignored", | 498 "setsockopt(SO_SNDBUF, %d) %V failed, ignored", |
498 ls[i].sndbuf, &ls[i].addr_text); | 499 ls[i].sndbuf, &ls[i].addr_text); |
499 } | 500 } |
500 } | 501 } |
502 | |
503 if (ls[i].keepalive) { | |
504 keepalive = (ls[i].keepalive == 1) ? 1 : 0; | |
505 | |
506 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_KEEPALIVE, | |
507 (const void *) &keepalive, sizeof(int)) | |
508 == -1) | |
509 { | |
510 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
511 "setsockopt(SO_KEEPALIVE, %d) %V failed, ignored", | |
512 keepalive, &ls[i].addr_text); | |
513 } | |
514 } | |
515 | |
516 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
517 | |
518 if (ls[i].keepidle) { | |
519 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_KEEPIDLE, | |
520 (const void *) &ls[i].keepidle, sizeof(int)) | |
521 == -1) | |
522 { | |
523 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
524 "setsockopt(TCP_KEEPIDLE, %d) %V failed, ignored", | |
525 ls[i].keepidle, &ls[i].addr_text); | |
526 } | |
527 } | |
528 | |
529 if (ls[i].keepintvl) { | |
530 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_KEEPINTVL, | |
531 (const void *) &ls[i].keepintvl, sizeof(int)) | |
532 == -1) | |
533 { | |
534 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
535 "setsockopt(TCP_KEEPINTVL, %d) %V failed, ignored", | |
536 ls[i].keepintvl, &ls[i].addr_text); | |
537 } | |
538 } | |
539 | |
540 if (ls[i].keepcnt) { | |
541 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_KEEPCNT, | |
542 (const void *) &ls[i].keepcnt, sizeof(int)) | |
543 == -1) | |
544 { | |
545 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
546 "setsockopt(TCP_KEEPCNT, %d) %V failed, ignored", | |
547 ls[i].keepcnt, &ls[i].addr_text); | |
548 } | |
549 } | |
550 | |
551 #endif | |
501 | 552 |
502 #if (NGX_HAVE_SETFIB) | 553 #if (NGX_HAVE_SETFIB) |
503 if (ls[i].setfib != -1) { | 554 if (ls[i].setfib != -1) { |
504 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_SETFIB, | 555 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_SETFIB, |
505 (const void *) &ls[i].setfib, sizeof(int)) | 556 (const void *) &ls[i].setfib, sizeof(int)) |