From owner-freebsd-stable Wed Aug 13 18:52:36 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id SAA14196 for stable-outgoing; Wed, 13 Aug 1997 18:52:36 -0700 (PDT) Received: from genesis.atrad.adelaide.edu.au (genesis.atrad.adelaide.edu.au [129.127.96.120]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id SAA14186; Wed, 13 Aug 1997 18:52:32 -0700 (PDT) Received: (from msmith@localhost) by genesis.atrad.adelaide.edu.au (8.8.5/8.7.3) id LAA17391; Thu, 14 Aug 1997 11:21:59 +0930 (CST) From: Michael Smith Message-Id: <199708140151.LAA17391@genesis.atrad.adelaide.edu.au> Subject: Re: A small buffer question.. In-Reply-To: from 0000-Administrator at "Aug 13, 97 04:37:27 pm" To: root@acromail.ml.org (0000-Administrator) Date: Thu, 14 Aug 1997 11:21:58 +0930 (CST) Cc: freebsd-hackers@FreeBSD.ORG, freebsd-stable@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-stable@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 0000-Administrator stands accused of saying: > > If the low level write() call is used to write to a data file then unlike > fwrite() where you must do an fflush to make sure that info is on disk I > am assuming that some type of flush is not necessary (can someone fill me > in on how to insure when using write() and read() calls that the data > actually gets to the disk), more importantly though if I open a socket and > then use a connect call to connect to a remote system and use write() to > write a block of data, is that block of data sent entirely as soon as > possible? (It would make it much easier to deal with your questions if you tried to use the English language as it was designed. Most particularly, organise your thoughts into sentences, punctuate said sentences, and keep them discrete.) You are asking some really basic and not very bright questions here that would better be answered by a reading of K&R or an introductory C programming text. To cover your main points : - fwrite() may or may not commit data to the OS depending on the buffering mode applicable to the handle in question and the content of the written data. - no system call guarantees that data is "on disk". The write() system call returns once the data is queued to be written, but this does not guarantee that the data has actually hit whatever media it is aimed at. - write() to a socket will return, again, once data is committed to the socket buffers. It would be stupid for the system not to send such data as soon as was practical. > I have basically handled these things when using the stdio library i.e > fwrite, printf etc., and found that an fflush is absolutely required to > get the packets out of the buffers etc and sent -- I am just not that sure > about how buffering (at the os level not library level) in this case > affects this. You appear to have been misusing the stdio library. If you insist on using it, at the very least study the setvbuf() function. -- ]] Mike Smith, Software Engineer msmith@gsoft.com.au [[ ]] Genesis Software genesis@gsoft.com.au [[ ]] High-speed data acquisition and (GSM mobile) 0411-222-496 [[ ]] realtime instrument control. (ph) +61-8-8267-3493 [[ ]] Unix hardware collector. "Where are your PEZ?" The Tick [[