svn commit: r362508 - stable/12/contrib/tnftp/src

Piotr Pawel Stefaniak pstef at FreeBSD.org
Mon Jun 22 19:15:51 UTC 2020


Author: pstef
Date: Mon Jun 22 19:15:50 2020
New Revision: 362508
URL: https://svnweb.freebsd.org/changeset/base/362508

Log:
  MFC r358405 (by hrs):
  Fix poor performance of ftp(1) due to small SO_SNDBUF and SO_RCVBUF.

Modified:
  stable/12/contrib/tnftp/src/cmds.c
  stable/12/contrib/tnftp/src/ftp_var.h
  stable/12/contrib/tnftp/src/main.c
  stable/12/contrib/tnftp/src/util.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/contrib/tnftp/src/cmds.c
==============================================================================
--- stable/12/contrib/tnftp/src/cmds.c	Mon Jun 22 19:09:47 2020	(r362507)
+++ stable/12/contrib/tnftp/src/cmds.c	Mon Jun 22 19:15:50 2020	(r362508)
@@ -2653,10 +2653,14 @@ setxferbuf(int argc, char *argv[])
 		goto usage;
 	}
 
-	if (dir & RATE_PUT)
+	if (dir & RATE_PUT) {
 		sndbuf_size = size;
-	if (dir & RATE_GET)
+		auto_sndbuf = 0;
+	}
+	if (dir & RATE_GET) {
 		rcvbuf_size = size;
+		auto_rcvbuf = 0;
+	}
 	fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n",
 	    sndbuf_size, rcvbuf_size);
 	code = 0;

Modified: stable/12/contrib/tnftp/src/ftp_var.h
==============================================================================
--- stable/12/contrib/tnftp/src/ftp_var.h	Mon Jun 22 19:09:47 2020	(r362507)
+++ stable/12/contrib/tnftp/src/ftp_var.h	Mon Jun 22 19:15:50 2020	(r362508)
@@ -298,6 +298,8 @@ GLOBAL	int	options;	/* used during socket creation */
 
 GLOBAL	int	sndbuf_size;	/* socket send buffer size */
 GLOBAL	int	rcvbuf_size;	/* socket receive buffer size */
+GLOBAL	int	auto_sndbuf;	/* flag: if != 0 then use auto sndbuf size */
+GLOBAL	int	auto_rcvbuf;	/* flag: if != 0 then use auto rcvbuf size */
 
 GLOBAL	int	macnum;		/* number of defined macros */
 GLOBAL	struct macel macros[16];

Modified: stable/12/contrib/tnftp/src/main.c
==============================================================================
--- stable/12/contrib/tnftp/src/main.c	Mon Jun 22 19:09:47 2020	(r362507)
+++ stable/12/contrib/tnftp/src/main.c	Mon Jun 22 19:15:50 2020	(r362508)
@@ -127,6 +127,9 @@ __RCSID(" NetBSD: main.c,v 1.117 2009/07/13 19:05:41 r
 #include <locale.h>
 
 #endif	/* tnftp */
+#ifdef __FreeBSD__
+#include <sys/sysctl.h>
+#endif
 
 #define	GLOBAL		/* force GLOBAL decls in ftp_var.h to be declared */
 #include "ftp_var.h"
@@ -509,6 +512,13 @@ main(int volatile argc, char **volatile argv)
 	(void)xsignal(SIGUSR1, crankrate);
 	(void)xsignal(SIGUSR2, crankrate);
 	(void)xsignal(SIGWINCH, setttywidth);
+
+	auto_rcvbuf = ((sysctlbyname("net.inet.tcp.recvbuf_auto",
+	    &auto_rcvbuf, &(size_t []){[0] = sizeof(int)}[0], NULL, 0) == 0) &&
+	    auto_rcvbuf == 1);
+	auto_sndbuf = ((sysctlbyname("net.inet.tcp.sendbuf_auto",
+	    &auto_sndbuf, &(size_t []){[0] = sizeof(int)}[0], NULL, 0) == 0) &&
+	    auto_sndbuf == 1);
 
 	if (argc > 0) {
 		if (isupload) {

Modified: stable/12/contrib/tnftp/src/util.c
==============================================================================
--- stable/12/contrib/tnftp/src/util.c	Mon Jun 22 19:09:47 2020	(r362507)
+++ stable/12/contrib/tnftp/src/util.c	Mon Jun 22 19:15:50 2020	(r362508)
@@ -1087,13 +1087,27 @@ setupsockbufsize(int sock)
 		    sndbuf_size);
 	}
 
+#ifdef __FreeBSD__
+	DPRINTF("auto_rcvbuf = %d\n", auto_rcvbuf);
+	if (auto_sndbuf == 0) {
+#endif
 	if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
 	    (void *)&sndbuf_size, sizeof(sndbuf_size)) == -1)
 		warn("Unable to set sndbuf size %d", sndbuf_size);
+#ifdef __FreeBSD__
+	}
+#endif
 
+#ifdef __FreeBSD__
+	DPRINTF("auto_sndbuf = %d\n", auto_sndbuf);
+	if (auto_rcvbuf == 0) {
+#endif
 	if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
 	    (void *)&rcvbuf_size, sizeof(rcvbuf_size)) == -1)
 		warn("Unable to set rcvbuf size %d", rcvbuf_size);
+#ifdef __FreeBSD__
+	}
+#endif
 }
 
 /*


More information about the svn-src-all mailing list