Browse Source

Add command-line argument for keeping TCP_NODELAY (#1685)

pull/1686/head
Vladimir Olteanu 7 years ago
committed by Max Lv
parent
commit
1c64829dfa
5 changed files with 29 additions and 4 deletions
  1. 1
      src/common.h
  2. 8
      src/local.c
  3. 8
      src/redir.c
  4. 8
      src/server.c
  5. 8
      src/tunnel.c

1
src/common.h

@ -63,6 +63,7 @@ enum {
GETOPT_VAL_HELP = 257,
GETOPT_VAL_REUSE_PORT,
GETOPT_VAL_FAST_OPEN,
GETOPT_VAL_NODELAY,
GETOPT_VAL_ACL,
GETOPT_VAL_MTU,
GETOPT_VAL_MPTCP,

8
src/local.c

@ -101,6 +101,7 @@ static int acl = 0;
static int mode = TCP_ONLY;
static int ipv6first = 0;
static int fast_open = 0;
static int no_delay = 0;
static int udp_fd = 0;
static struct ev_signal sigint_watcher;
@ -948,7 +949,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents)
}
// Disable TCP_NODELAY after the first response are sent
if (!remote->recv_ctx->connected) {
if (!remote->recv_ctx->connected && !no_delay) {
int opt = 0;
setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
@ -1298,6 +1299,7 @@ main(int argc, char **argv)
static struct option long_options[] = {
{ "reuse-port", no_argument, NULL, GETOPT_VAL_REUSE_PORT },
{ "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN },
{ "no-delay", no_argument, NULL, GETOPT_VAL_NODELAY },
{ "acl", required_argument, NULL, GETOPT_VAL_ACL },
{ "mtu", required_argument, NULL, GETOPT_VAL_MTU },
{ "mptcp", no_argument, NULL, GETOPT_VAL_MPTCP },
@ -1336,6 +1338,10 @@ main(int argc, char **argv)
mptcp = 1;
LOGI("enable multipath TCP");
break;
case GETOPT_VAL_NODELAY:
no_delay = 1;
LOGI("enable TCP no-delay");
break;
case GETOPT_VAL_PLUGIN:
plugin = optarg;
break;

8
src/redir.c

@ -98,6 +98,7 @@ static int mode = TCP_ONLY;
static int nofile = 0;
#endif
static int fast_open = 0;
static int no_delay = 0;
static struct ev_signal sigint_watcher;
static struct ev_signal sigterm_watcher;
@ -437,7 +438,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents)
}
// Disable TCP_NODELAY after the first response are sent
if (!remote->recv_ctx->connected) {
if (!remote->recv_ctx->connected && !no_delay) {
int opt = 0;
setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
@ -905,6 +906,7 @@ main(int argc, char **argv)
{ "plugin", required_argument, NULL, GETOPT_VAL_PLUGIN },
{ "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS },
{ "reuse-port", no_argument, NULL, GETOPT_VAL_REUSE_PORT },
{ "no-delay", no_argument, NULL, GETOPT_VAL_NODELAY },
{ "password", required_argument, NULL, GETOPT_VAL_PASSWORD },
{ "key", required_argument, NULL, GETOPT_VAL_KEY },
{ "help", no_argument, NULL, GETOPT_VAL_HELP },
@ -929,6 +931,10 @@ main(int argc, char **argv)
mptcp = 1;
LOGI("enable multipath TCP");
break;
case GETOPT_VAL_NODELAY:
no_delay = 1;
LOGI("enable TCP no-delay");
break;
case GETOPT_VAL_PLUGIN:
plugin = optarg;
break;

8
src/server.c

@ -119,6 +119,7 @@ static int acl = 0;
static int mode = TCP_ONLY;
static int ipv6first = 0;
static int fast_open = 0;
static int no_delay = 0;
#ifdef HAVE_SETRLIMIT
static int nofile = 0;
@ -1142,7 +1143,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents)
}
// Disable TCP_NODELAY after the first response are sent
if (!remote->recv_ctx->connected) {
if (!remote->recv_ctx->connected && !no_delay) {
int opt = 0;
setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
@ -1501,6 +1502,7 @@ main(int argc, char **argv)
static struct option long_options[] = {
{ "fast-open", no_argument, NULL, GETOPT_VAL_FAST_OPEN },
{ "reuse-port", no_argument, NULL, GETOPT_VAL_REUSE_PORT },
{ "no-delay", no_argument, NULL, GETOPT_VAL_NODELAY },
{ "acl", required_argument, NULL, GETOPT_VAL_ACL },
{ "manager-address", required_argument, NULL,
GETOPT_VAL_MANAGER_ADDRESS },
@ -1526,6 +1528,10 @@ main(int argc, char **argv)
case GETOPT_VAL_FAST_OPEN:
fast_open = 1;
break;
case GETOPT_VAL_NODELAY:
no_delay = 1;
LOGI("enable TCP no-delay");
break;
case GETOPT_VAL_ACL:
LOGI("initializing acl...");
acl = !init_acl(optarg);

8
src/tunnel.c

@ -94,6 +94,7 @@ static int mode = TCP_ONLY;
#ifdef HAVE_SETRLIMIT
static int nofile = 0;
#endif
static int no_delay = 0;
static struct ev_signal sigint_watcher;
static struct ev_signal sigterm_watcher;
@ -377,7 +378,7 @@ remote_recv_cb(EV_P_ ev_io *w, int revents)
}
// Disable TCP_NODELAY after the first response are sent
if (!remote->recv_ctx->connected) {
if (!remote->recv_ctx->connected && !no_delay) {
int opt = 0;
setsockopt(server->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
setsockopt(remote->fd, SOL_TCP, TCP_NODELAY, &opt, sizeof(opt));
@ -788,6 +789,7 @@ main(int argc, char **argv)
static struct option long_options[] = {
{ "mtu", required_argument, NULL, GETOPT_VAL_MTU },
{ "no-delay", no_argument, NULL, GETOPT_VAL_NODELAY },
{ "mptcp", no_argument, NULL, GETOPT_VAL_MPTCP },
{ "plugin", required_argument, NULL, GETOPT_VAL_PLUGIN },
{ "plugin-opts", required_argument, NULL, GETOPT_VAL_PLUGIN_OPTS },
@ -818,6 +820,10 @@ main(int argc, char **argv)
mptcp = 1;
LOGI("enable multipath TCP");
break;
case GETOPT_VAL_NODELAY:
no_delay = 1;
LOGI("enable TCP no-delay");
break;
case GETOPT_VAL_PLUGIN:
plugin = optarg;
break;

Loading…
Cancel
Save