From 47c53825a5f512e96916325c10f68b70dd593528 Mon Sep 17 00:00:00 2001 From: Roy Anderson Date: Wed, 21 Mar 2018 12:30:01 +0800 Subject: [PATCH] Update tunnel.c Add TFO FEATURE --- src/tunnel.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/tunnel.c b/src/tunnel.c index 7970d33d..fbab58b3 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -154,10 +154,21 @@ create_and_bind(const char *addr, const char *port) } int opt = 1; - setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + if (fast_open == 1){ + + setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, TCP_FASTOPEN, &opt, sizeof(opt)); +#ifdef SO_NOSIGPIPE + setsockopt(listen_sock, SOL_SOCKET, SO_NOSIGPIPE, TCP_FASTOPEN, &opt, sizeof(opt)); +#endif + } + else { + setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); #ifdef SO_NOSIGPIPE setsockopt(listen_sock, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt)); #endif + + } + if (reuse_port) { int err = set_reuseport(listen_sock); if (err == 0) { @@ -1022,6 +1033,8 @@ main(int argc, char **argv) if (reuse_port == 0) { reuse_port = conf->reuse_port; } + fast_open = conf->fast_open; + #ifdef HAVE_SETRLIMIT if (nofile == 0) { nofile = conf->nofile;