send(2) does not block, send(2) man page wrong?
Ruslan Ermilov
ru at freebsd.org
Fri Jan 23 08:40:51 PST 2004
On Fri, Jan 23, 2004 at 04:25:07PM +0100, Stuart Pook wrote:
> The documentation for send(2) says
>
> If no messages space is available at the socket to hold the message to be
> transmitted, then send() normally blocks, unless the socket has been
> placed in non-blocking I/O mode. The select(2) call may be used to
> determine when it is possible to send more data.
>
> I cannot get send (or sendto which is what really interests me)
> to block on FreeBSD 4.9. When I send as fast as I can to a socket,
> send rapidly fails with ENOBUFS. I am not surprised that the kernel is
> running out of mbufs but I am surprised that send does not block until
> more become available.
>
> Select does not block either. It always says that I can write to the
> socket and then send fails with ENOBUFS.
>
> The udp_output function in /sys/netinet/udp_usrreq.c, seems clear:
>
> /*
> * Calculate data length and get a mbuf
> * for UDP and IP headers.
> */
> M_PREPEND(m, sizeof(struct udpiphdr), M_DONTWAIT);
> if (m == 0) {
> error = ENOBUFS;
> if (addr)
> splx(s);
> goto release;
> }
>
> There is no sign of send blocking waiting for a mbuf or of it returning
> EAGAIN if the socket is non-blocking.
>
> Is the documentation for send(2) wrong or is there some way to make
> send and sendto block?
>
> I have used setsockopt(s, SOL_SOCKET, SO_SNDBUF) to reduce the size
> of the output queue for the socket but send still returns ENOBUFS and
> never blocks or returns EAGAIN.
>
UDP sockets don't use send buffer (like TCP does) for storing data,
only receive buffer, so SO_SNDBUF only affects the maximum size of
one write operation.
Cheers,
--
Ruslan Ermilov
FreeBSD committer
ru at FreeBSD.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20040123/c7029747/attachment.bin
More information about the freebsd-hackers
mailing list