From a726646ff3b8b439e8cb6f0b478eaa6582b0967b Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 29 Mar 2025 02:34:36 +0100 Subject: [PATCH] if 128k network buffer fails then try 64k as last resort --- src/i_tcp.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 85e2655f2..0edeaaa3e 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -1053,12 +1053,32 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen } if (opt < 128<<10) - CONS_Alert(CONS_WARNING, M_GetText("Can't set buffer length to 128k, file transfer will be bad\n")); - else - CONS_Printf(M_GetText("Network system buffer set to: %dKb\n"), opt>>10); + { + CONS_Alert(CONS_WARNING, M_GetText("Can't set buffer length to 128k, retrying with 64k\n")); + opt = 64<<10; + opts = (socklen_t)sizeof(opt); + rc = setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&opt, opts); + if (rc <= -1) + { + e = errno; + I_OutputMsg("setting SO_RCVBUF failed: #%u, %s\n", e, strerror(e)); + } + opt = 0; + rc = getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&opt, &opts); + if (rc <= -1) + { + e = errno; + I_OutputMsg("getting SO_RCVBUF failed: #%u, %s\n", e, strerror(e)); + } + + if (opt < 64<<10) + CONS_Alert(CONS_WARNING, M_GetText("Can't set buffer length to 64k, file transfer will be bad\n")); + } } } + CONS_Printf(M_GetText("Network system buffer set to: %dKb\n"), opt>>10); + rc = getsockname(s, (struct sockaddr *)&sin, &len); if (rc != 0) {