Skip to content

Commit a92814b

Browse files
authored
Merge pull request #299 from Castaglia/proxy-disable-nagle
Disable the Nagle algorithm by default on our TCP connections to back…
2 parents 304348c + 6422f10 commit a92814b

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

lib/proxy/conn.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,12 @@ conn_t *proxy_conn_get_server_conn(pool *p, struct proxy_session *proxy_sess,
10231023
pr_inet_close(p, server_conn);
10241024

10251025
pr_pool_tag(ctrl_conn->pool, "proxy backend ctrl conn pool");
1026+
1027+
/* Make sure that TCP_NODELAY is enabled (i.e. Nagle is disabled) by default
1028+
* for our control connections.
1029+
*/
1030+
(void) pr_inet_set_proto_nodelay(ctrl_conn->pool, ctrl_conn, 1);
1031+
10261032
return ctrl_conn;
10271033
}
10281034

lib/proxy/ftp/conn.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ conn_t *proxy_ftp_conn_accept(pool *p, conn_t *data_conn, conn_t *ctrl_conn,
128128

129129
pr_trace_msg(trace_channel, 9,
130130
"accepted connection from server '%s'", conn->remote_name);
131+
132+
/* Make sure that TCP_NODELAY is enabled (i.e. Nagle is disabled) by default
133+
* for our data connections.
134+
*/
135+
(void) pr_inet_set_proto_nodelay(conn->pool, conn, 1);
136+
131137
return conn;
132138
}
133139

@@ -247,6 +253,12 @@ conn_t *proxy_ftp_conn_connect(pool *p, const pr_netaddr_t *bind_addr,
247253

248254
pr_trace_msg(trace_channel, 9,
249255
"connected to server '%s'", opened->remote_name);
256+
257+
/* Make sure that TCP_NODELAY is enabled (i.e. Nagle is disabled) by default
258+
* for our data connections.
259+
*/
260+
(void) pr_inet_set_proto_nodelay(opened->pool, opened, 1);
261+
250262
return opened;
251263
}
252264

lib/proxy/tls.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,22 +1417,11 @@ static int tls_connect(conn_t *conn, const char *host_name,
14171417
}
14181418

14191419
/* If configured, set a timer for the handshake. */
1420-
if (handshake_timeout) {
1420+
if (handshake_timeout > 0) {
14211421
handshake_timer_id = pr_timer_add(handshake_timeout, -1,
14221422
&proxy_module, handshake_timeout_cb, "SSL/TLS handshake");
14231423
}
14241424

1425-
/* Make sure that TCP_NODELAY is enabled for the handshake. */
1426-
(void) pr_inet_set_proto_nodelay(conn->pool, conn, 1);
1427-
1428-
/* Make sure that TCP_CORK (aka TCP_NOPUSH) is DISABLED for the handshake. */
1429-
if (pr_inet_set_proto_cork(conn->wfd, 0) < 0) {
1430-
pr_trace_msg(trace_channel, 9,
1431-
"error disabling TCP_CORK on %s conn: %s",
1432-
nstrm->strm_type == PR_NETIO_STRM_CTRL ? "control" : "data",
1433-
strerror(errno));
1434-
}
1435-
14361425
connect_retry:
14371426

14381427
blocking = tls_get_block(conn);
@@ -1555,17 +1544,7 @@ static int tls_connect(conn_t *conn, const char *host_name,
15551544
/* Disable the handshake timer. */
15561545
pr_timer_remove(handshake_timer_id, &proxy_module);
15571546

1558-
/* Disable TCP_NODELAY, now that the handshake is done. */
1559-
(void) pr_inet_set_proto_nodelay(conn->pool, conn, 0);
1560-
1561-
if (nstrm->strm_type == PR_NETIO_STRM_DATA) {
1562-
/* Re-enable TCP_CORK (aka TCP_NOPUSH), now that the handshake is done. */
1563-
if (pr_inet_set_proto_cork(conn->wfd, 1) < 0) {
1564-
pr_trace_msg(trace_channel, 9,
1565-
"error re-enabling TCP_CORK on data conn: %s", strerror(errno));
1566-
}
1567-
1568-
} else if (nstrm->strm_type == PR_NETIO_STRM_CTRL) {
1547+
if (nstrm->strm_type == PR_NETIO_STRM_CTRL) {
15691548
int reused;
15701549

15711550
/* Only try to cache the new SSL session if we actually did create a

0 commit comments

Comments
 (0)