Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Aug 2002 16:51:03 -0400 
From:      Loh John Wu <ljwu@sandvine.com>
To:        "'freebsd-questions@FreeBSD.ORG'" <freebsd-questions@FreeBSD.ORG>
Subject:   why can't I set my socket's buffer size to be the MIB value "kern .ipc.maxsockbuf" on FreeBSD 4.5
Message-ID:  <FE045D4D9F7AED4CBFF1B3B813C85337B911C1@mail.sandvine.com>

next in thread | raw e-mail | index | archive | help
Hello,

I'm trying to determine the maximum buffer size for both the input (receive)
and output (send) buffers for a socket on a FreeBSD 4.5 system. From the man
pages on the setsockopt() call, it says
"The system places an absolute maximum on these values, which is accessible
through the sysctl(3) MIB variable ``kern.ipc.maxsockbuf''."

Therefore, in my code, I first read the 'kern.ipc.maxsockbuf' MIB value with
the sysctlbyname() function and then use the returned value and set my
socket's buffer size.
to be the maxsockbuf size with the setsockopt() function.  However, when I
do the setsockopt() function with that value, it returns an ERRNO of 55=No
Buffer Space Available.
I'm not sure why this is occurring (the no buffer space available) as I'm
using maxsockbuf MIB value from the system to set my socket buffer size.

Did I do something wrong in my determination of the maxsockbuf or is there
another method to determine the system's maxsockbuf size.
Any help would be greatly appreciated.

Code snipet and output below: So I do something like,

        int bufSize = 0;
        size_t bufSizeLen = sizeof(bufSize);
        char maxsockbuf[] = "kern.ipc.maxsockbuf";
        
        /* get max buffer size */
        if (sysctlbyname(maxsockbuf, (char*)&bufSize,
                         &bufSizeLen, 0, 0) == -1)
        {
            printf("sysctlbyname get failed. Errno=%d, Error=%s\n",
                   errno, strerror(errno)); 
            return;
        }
        else
        {
            printf("Socket max bufsize is %d\n", bufSize);
        }
        
        /* set max buffer */  
        if (setsockopt(socketFd, SOL_SOCKET, SO_RCVBUF,
                        (char *)&bufSize, sizeof(bufSize)) == -1) {
             printf("setsockopt failed for socket %d. Errno=%d, Error=%s\n",
                     socketFd, errno, strerror(errno));
        }

Output of above code is:

Socket max bufsize is 262144
setsockopt failed for socket 17. Errno=55, Error=No buffer space available

thanks in advance,
John


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?FE045D4D9F7AED4CBFF1B3B813C85337B911C1>