develooper Front page | perl.perl5.porters | Postings from May 2003

Re: [perl #22339] IO::Handle::setvbuf not defined properly

Thread Previous
From:
Nicholas Clark
Date:
May 28, 2003 06:27
Subject:
Re: [perl #22339] IO::Handle::setvbuf not defined properly
Message ID:
20030528142646.P1149@plum.flirble.org
On Wed, May 28, 2003 at 08:58:21AM -0400, Mark Jason Dominus wrote:
> Rafael Garcia-Suarez <rgarciasuarez@free.fr>:
> > setbuf/setvbuf aren't available with a PerlIO-enabled perl.
> 
> Thanks.
> 
> Here's my problem.  I want two processes to access the same (small)
> file concurrently.  Process A reads part of the file.  Process B
> modifies part of the file.  Then process A wants to see the change.
> But it can't, because the block it just read is buffered, and
> subsequent reads are all coming from the buffer, which records the
> state of the file before the change, instead of from the real file.
> 
> I thought my choices were
> 
> a) use setvbuf() to discard the buffer, perhaps temporarily, or
> 
> b) discard the buffered I/O system entirely and rewrite everything in
> terms of sysread(), effectively reimplementing the entire buffered I/O
> subsystem in Perl.
> 
> But now it appears that my only choice is (b).  This isn't very
> attractive.  Is there some other option I've overlooked?

My understanding is that one never was allowed to call setvbuf() midway on a
stream:

C99 (spit, but all I have access to) section 7.19.5.6 paragraph 2:

2    The setvbuf function may be used only after the stream pointed to by
     stream has been associated with an open file and before any other
     operation (other than an unsuccessful call to setvbuf) is performed on
     the stream.

The fact that it always seems to work is undefined behaviour.
I only know this as a side effect of this thread:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&th=6a3278c9c3b3534e&rnum=1 

(the code that generated the test output called setvbuf() on an already
used stream, and someone politely pointed out my error. I thought that it
was in public, but I can't find it in the thread)

Nicholas Clark

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About