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

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

From:
Nick Ing-Simmons
Date:
June 2, 2003 01:11
Subject:
Re: [perl #22339] IO::Handle::setvbuf not defined properly
Message ID:
20030602081047.1891.2@bactrian.elixent.com
Kurt Starsinic <kstar@cpan.org> writes:
>On May 28, 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

As Nick C has said, as far as I know once you have called setvbuf()
it is done and all future reads are unbuffered (if that is what you set).

>> 
>> 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?

seek(FH,0,1);  # re-position here

Will discard the buffer contents on a read stream.

>
>    How about mmap(), or closing and re-opening the read() filehandle?

I wonder if :mmap layer has finaly found a use?


>
>    - Kurt
-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/




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