From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 19 08:53:24 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 51C6F16A4CE for ; Mon, 19 Jan 2004 08:53:24 -0800 (PST) Received: from smtp2.enst.fr (reloaded.enst.fr [137.194.2.14]) by mx1.FreeBSD.org (Postfix) with ESMTP id 44BC143D6D for ; Mon, 19 Jan 2004 08:53:07 -0800 (PST) (envelope-from pook@enst.fr) Received: from email.enst.fr (muse.enst.fr [137.194.2.33]) by smtp2.enst.fr (Postfix) with ESMTP id 535023FA for ; Mon, 19 Jan 2004 17:53:05 +0100 (CET) Received: from roo (roo-ether.enst.fr [137.194.160.54]) by email.enst.fr (8.9.3/8.9.3) with ESMTP id RAA19828 for ; Mon, 19 Jan 2004 17:53:05 +0100 (CET) Received: from pook (helo=roo) by roo with local-esmtp (Exim 3.36 #1 (Debian)) id 1Aice9-0002by-00 for ; Mon, 19 Jan 2004 17:53:05 +0100 From: Stuart Pook To: freebsd-hackers@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Date: Mon, 19 Jan 2004 17:53:05 +0100 Message-Id: Sender: Stuart Pook X-Mailman-Approved-At: Tue, 20 Jan 2004 05:22:50 -0800 Subject: send(2) does not block, send(2) man page wrong? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jan 2004 16:53:24 -0000 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 is 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. I note that send on Linux and Solaris blocks and that on these systems select can be used to wait until the send will not block. I have written a test program, http://www.infres.enst.fr/~pook/send/server.c, that shows that send does not block on FreeBSD. It does with Linux and Solaris. thanks for your help Stuart