From c008e1015f7f719affefd2bbe270eae0f9975674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Fri, 21 Mar 2008 21:37:32 +0000 Subject: [PATCH] Attached is a patch that fixes the following: - The argument for setsockopt is an int, not a size_t. This breaks on 64bit OS's causing the buffer not to be set (or triggers a kernel bug on AIX due to size_t being parsed as an int and setting the socket buffer to zero due to bad kernel error checking). - Add a check to see if the socket buffer is large enough already, don't make it smaller if it is. From Niklas Edmundsson git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@22701 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/ftp/common/sockbuf.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/appl/ftp/common/sockbuf.c b/appl/ftp/common/sockbuf.c index a2f7e3997..793e3f7c0 100644 --- a/appl/ftp/common/sockbuf.c +++ b/appl/ftp/common/sockbuf.c @@ -45,10 +45,24 @@ void set_buffer_size(int fd, int read) { #if defined(SO_RCVBUF) && defined(SO_SNDBUF) && defined(HAVE_SETSOCKOPT) - size_t size = 4194304; + int size = 4194304; + int optname = read ? SO_RCVBUF : SO_SNDBUF; + +#ifdef HAVE_GETSOCKOPT + int curr=0; + socklen_t optlen; + + optlen = sizeof(curr); + if(getsockopt(fd, SOL_SOCKET, optname, (void *)&curr, &optlen) == 0) { + if(curr >= size) { + /* Already large enough */ + return; + } + } +#endif /* HAVE_GETSOCKOPT */ + while(size >= 131072 && - setsockopt(fd, SOL_SOCKET, read ? SO_RCVBUF : SO_SNDBUF, - (void *)&size, sizeof(size)) < 0) + setsockopt(fd, SOL_SOCKET, optname, (void *)&size, sizeof(size)) < 0) size /= 2; #endif }