From owner-freebsd-hackers Thu Nov 14 17:26:10 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id RAA00257 for hackers-outgoing; Thu, 14 Nov 1996 17:26:10 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id RAA00252 for ; Thu, 14 Nov 1996 17:26:08 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id SAA25075; Thu, 14 Nov 1996 18:12:13 -0700 From: Terry Lambert Message-Id: <199611150112.SAA25075@phaeton.artisoft.com> Subject: Re: Sockets question... To: jdp@polstra.com (John Polstra) Date: Thu, 14 Nov 1996 18:12:13 -0700 (MST) Cc: scrappy@ki.net, jgreco@brasil.moneng.mei.com, hackers@FreeBSD.ORG In-Reply-To: <199611150002.QAA10843@austin.polstra.com> from "John Polstra" at Nov 14, 96 04:02:52 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk > > > Are you checking the return value from write() to make sure it actually > > > thinks that N bytes were _written_? > > > > > *sigh* > > Well now, wait a minute. As long as you haven't set the socket for > non-blocking I/O, the write will always block until it's written the > full N bytes that you asked for. In other words, the write will always > return either -1 or N. Only if it's set up for non-blocking I/O can it > return a short count. Writes are different from reads in this respect. The problem that is supposedly being addressed by looking at the bytes written is knowing that the data will be available as a unit to the reader. There is no such guarantee. If you don't use non-blocking I/O, the read will block until the buffer is full. Use blocking I/O, and you won't have the problem with the reader returning before it should (or shouldn't). Otherwise the RPC interfaces wouldn't work at all. Instead of making a non-blocking read for which "it's OK if no data is available", use select() and only call a blocking read if the select is true. Any hang problems from fragmentation, etc. that happen after that are a result of you not marchalling your interfaces properly (again, I recommend the RPC code for examples). Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.