Re: socket: setting SO_SNDBUF

From: Mike Coleman (mcoleman2@kc.rr.com)
Date: Thu May 11 2000 - 02:23:14 EST


Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
> > because I would expect following behaviour:
> >
> > err = getsockopt(s, SOL_SOCKET, SO_SNDBUF, &res1, &len);
> > err = setsockopt(s, SOL_SOCKET, SO_SNDBUF, &res1, len);
> > err = getsockopt(s, SOL_SOCKET, SO_SNDBUF, &res2, &len);
> >
> > after that sequence, res1 should be == res2 !
> >
> > Am I totally wrong?
>
> Nothing in the standards says anything about that being true

But it is the behavior that naive users like me would expect (modulo maybe
rounding up to the next power of two or some minimum). The current situation
is a bit like measuring beer in pints on the way into the keg and quarts on
the way out.

Putting it another way, if getsockopt(SNDBUF) tells me 4096, I'm thinking to
myself that 4096 octets will be buffered, when in fact it will only be 2048.
Or am I missing something?

--Mike

------------------------------------------------------------------------------

#!/usr/bin/env python

from socket import *

n = 64
print 'initial n is', n

s = socket(AF_INET, SOCK_STREAM)

for i in range(10):
    s.setsockopt(SOL_SOCKET, SO_SNDBUF, n)
    n = s.getsockopt(SOL_SOCKET, SO_SNDBUF)
    print 'n is', n

------------------------------------------------------------------------------
The output is

initial n is 64
n is 2048
n is 4096
n is 8192
n is 16384
n is 32768
n is 65536
n is 131070
n is 131070
n is 131070
n is 131070

-- 
Any sufficiently adverse technology is indistinguishable from Microsoft.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon May 15 2000 - 21:00:17 EST