Subject: Re: Socket buffers allocations
To: Bharat Joshi <bharat.josh@gmail.com>
From: Rui Paulo <rpaulo@fnop.net>
List: tech-net
Date: 01/12/2007 11:17:49
On 12 Jan 2007, at 04:16, Bharat Joshi wrote:
> Hi,
>
> Couple of related questions:
>
> I am developing an application where I need to check whether a
> socket is ready for write or not. I can do that using select, poll or
> kqueue and I have chosen 'kqueue' to do it.
Maybe you already know this, but you'll only benefit from kqueue if
you have multiple file descriptors (sockets).
>
> Before adding the socket to 'kqueue', I want to check if there
> is enough space in socket buffer for a write to be successful. My
> first question is that is there a IOCTL/GETSOCKOPT option using which
> I can find out the space available in the send socket buffer?
>
> I was also looking to increase the size of the socket buffers
> after opening the socket. But I wanted to confirm that Kernel does not
> pre-allocate the memory for socket buffers and so I looked at the
> kernel code and it seems to me that kernel does not pre-allocate these
> buffers and the mbufs get allocated as and when a message is sent. Can
> someone please confirm this behaviour for me?
You can use setsockopt(3) with options SO_SNDBUF or SO_RCVBUF. I
think this is what you are referring to.
>
> If the answer to the above question is that 'buffers are not
> pre-allocated" than another question is that if I increase the size
> of the socket buffers, will it adversely affect any kernel
> functionality?
None that I'm aware of.
--
Rui Paulo