From 9fabfd77eef7dfc249d6060334d1534f3d22a830 Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Fri, 10 Aug 2012 09:11:01 +0200 Subject: [PATCH] added --so-keepalive --- core/socket.c | 6 ++++++ core/uwsgi.c | 1 + uwsgi.h | 1 + 3 files changed, 8 insertions(+) diff --git a/core/socket.c b/core/socket.c index c4a18fca..9857aaa2 100644 --- a/core/socket.c +++ b/core/socket.c @@ -586,6 +586,12 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) { } + if (uwsgi.so_keepalive) { + if (setsockopt(serverfd, SOL_SOCKET, SO_KEEPALIVE, &uwsgi.so_keepalive, sizeof(int))) { + uwsgi_error("setsockopt()"); + } + } + if (bind(serverfd, (struct sockaddr *) &uws_addr, sizeof(uws_addr)) != 0) { if (errno == EADDRINUSE) { diff --git a/core/uwsgi.c b/core/uwsgi.c index 51e815c6..0bc0728e 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -255,6 +255,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"no-server", no_argument, 0, "force no-server mode", uwsgi_opt_true, &uwsgi.no_server, 0}, {"command-mode", no_argument, 0, "force command mode", uwsgi_opt_true, &uwsgi.command_mode, UWSGI_OPT_IMMEDIATE}, {"no-defer-accept", no_argument, 0, "disable deferred-accept on sockets", uwsgi_opt_true, &uwsgi.no_defer_accept, 0}, + {"so-keepalive", no_argument, 0, "enable TCP KEEPALIVEs", uwsgi_opt_true, &uwsgi.so_keepalive, 0}, {"limit-as", required_argument, 0, "limit processes address space/vsz", uwsgi_opt_set_megabytes, &uwsgi.rl.rlim_max, 0}, {"limit-nproc", required_argument, 0, "limit the number of spawnable processes", uwsgi_opt_set_int, &uwsgi.rl_nproc.rlim_max, 0}, {"reload-on-as", required_argument, 0, "reload if address space is higher than specified megabytes", uwsgi_opt_set_megabytes, &uwsgi.reload_on_as, UWSGI_OPT_MEMORY}, diff --git a/uwsgi.h b/uwsgi.h index 0670fea5..69ffb5c7 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1504,6 +1504,7 @@ struct uwsgi_server { int vassal_sos_backlog; int no_defer_accept; + int so_keepalive; int page_size;