diff --git a/core/socket.c b/core/socket.c index b4f3792e..0cf67164 100644 --- a/core/socket.c +++ b/core/socket.c @@ -551,7 +551,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) { } if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEADDR, (const void *) &reuse, sizeof(int)) < 0) { - uwsgi_error("setsockopt()"); + uwsgi_error("SO_REUSEADDR setsockopt()"); uwsgi_nuclear_blast(); } @@ -559,7 +559,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) { #ifdef IP_FREEBIND if (uwsgi.freebind) { if (setsockopt(serverfd, SOL_IP, IP_FREEBIND, (const void *) &uwsgi.freebind, sizeof(int)) < 0) { - uwsgi_error("setsockopt()"); + uwsgi_error("IP_FREEBIND setsockopt()"); uwsgi_nuclear_blast(); } } @@ -569,7 +569,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) { if (uwsgi.reuse_port) { #ifdef SO_REUSEPORT if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEPORT, (const void *) &uwsgi.reuse_port, sizeof(int)) < 0) { - uwsgi_error("setsockopt()"); + uwsgi_error("SO_REUSEPORT setsockopt()"); uwsgi_nuclear_blast(); } #else @@ -577,11 +577,21 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) { #endif } + if (uwsgi.so_send_timeout) { + struct timeval tv; + tv.tv_sec = uwsgi.so_send_timeout; + tv.tv_usec = 0; + if (setsockopt(serverfd, SOL_SOCKET, SO_SNDTIMEO, (const void *) &tv, sizeof(struct timeval)) < 0) { + uwsgi_error("SO_SNDTIMEO setsockopt()"); + uwsgi_nuclear_blast(); + } + } + if (!uwsgi.no_defer_accept) { #ifdef __linux__ if (setsockopt(serverfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], sizeof(int))) { - uwsgi_error("setsockopt()"); + uwsgi_error("TCP_DEFER_ACCEPT setsockopt()"); } // OSX has no SO_ACCEPTFILTER !!! #elif defined(__freebsd__) @@ -589,7 +599,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) { strcpy(afa.af_name, "dataready"); afa.af_arg[0] = 0; if (setsockopt(serverfd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(struct accept_filter_arg))) { - uwsgi_error("setsockopt()"); + uwsgi_error("SO_ACCEPTFILTER setsockopt()"); } #endif @@ -597,7 +607,7 @@ 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()"); + uwsgi_error("SO_KEEPALIVE setsockopt()"); } } diff --git a/core/uwsgi.c b/core/uwsgi.c index 1be70588..d3bb49e8 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -264,6 +264,10 @@ static struct uwsgi_option uwsgi_base_options[] = { {"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}, + {"so-send-timeout", no_argument, 0, "set SO_SNDTIMEO", uwsgi_opt_set_int, &uwsgi.so_send_timeout, 0}, + {"socket-send-timeout", no_argument, 0, "set SO_SNDTIMEO", uwsgi_opt_set_int, &uwsgi.so_send_timeout, 0}, + {"so-write-timeout", no_argument, 0, "set SO_SNDTIMEO", uwsgi_opt_set_int, &uwsgi.so_send_timeout, 0}, + {"socket-write-timeout", no_argument, 0, "set SO_SNDTIMEO", uwsgi_opt_set_int, &uwsgi.so_send_timeout, 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 c18575a8..74c2aaed 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1623,6 +1623,7 @@ struct uwsgi_server { int no_defer_accept; int so_keepalive; + int so_send_timeout; int page_size; int cpus;