Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Aug 1997 11:21:58 +0930 (CST)
From:      Michael Smith <msmith@atrad.adelaide.edu.au>
To:        root@acromail.ml.org (0000-Administrator)
Cc:        freebsd-hackers@FreeBSD.ORG, freebsd-stable@FreeBSD.ORG
Subject:   Re: A small buffer question..
Message-ID:  <199708140151.LAA17391@genesis.atrad.adelaide.edu.au>
In-Reply-To: <Pine.BSF.3.96.970813163130.2479A-100000@acromail.ml.org> from 0000-Administrator at "Aug 13, 97 04:37:27 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
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  [[



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199708140151.LAA17391>