Discussion:
Socket buffers allocations
(too old to reply)
Bharat Joshi
2007-01-12 04:16:35 UTC
Permalink
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.

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?

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?

Thanks,
Bharat

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Christian Biere
2007-01-12 10:23:10 UTC
Permalink
Post by Bharat Joshi
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.
Excellent choice.
Post by Bharat Joshi
Before adding the socket to 'kqueue', I want to check if there
is enough space in socket buffer for a write to be successful.
Why before? Well, see FIONSPACE in ioctl(2).
Post by Bharat Joshi
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?
See kqueue(2) and EVFILT_WRITE:

EVFILT_WRITE Takes a descriptor as the identifier, and returns whenever
it is possible to write to the descriptor. For sockets,
pipes, fifos, and ttys, data will contain the amount of
space remaining in the write buffer.
--
Christian

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Bharat Joshi
2007-01-12 10:54:11 UTC
Permalink
Hi Christian,

Thansk a lot for quick reply.
Post by Christian Biere
Post by Bharat Joshi
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.
Excellent choice.
Post by Bharat Joshi
Before adding the socket to 'kqueue', I want to check if there
is enough space in socket buffer for a write to be successful.
Why before? Well, see FIONSPACE in ioctl(2).
I just found that this has been introduced in new revision. I was
using NetBSD 2.0.
Post by Christian Biere
Post by Bharat Joshi
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?
EVFILT_WRITE Takes a descriptor as the identifier, and returns whenever
it is possible to write to the descriptor. For sockets,
pipes, fifos, and ttys, data will contain the amount of
space remaining in the write buffer.
Yes. I had looked at it when I choose to use 'kqueue'.

If someone can answer my other questions as well, I would be able to
decide how and what to use in my application.

Thanks & Regards,
Bharat

PS: I am sorry that I am not subscribed to tech-net mailing list and I
forgot to ask for a cc to my reply as well. Please cc your reply to my
mail id as well.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Rui Paulo
2007-01-12 11:17:49 UTC
Permalink
Post by Bharat Joshi
Hi,
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).
Post by Bharat Joshi
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.
Post by Bharat Joshi
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



--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Loading...