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

Re: Meaning of sysread()

Thread Previous | Thread Next
Nick Ing-Simmons
May 22, 2003 00:25
Re: Meaning of sysread()
Message ID:
Mark Mielke <> writes:
>On Wed, May 21, 2003 at 05:54:17PM +0100, Nick Ing-Simmons wrote:
>> Mark Mielke <> writes:
>> >sysread() is documented ('man perlfunc') to '[attempt] to read LENGTH
>> >characters of data ... [bypassing] buffered IO ...'. If Perl sysread()
>> >is actually implemented using C read(), then it would be impossible to
>> >read LENGTH characters of data, and only LENGTH characters of data
>> >without calling C read() once for each byte. Remember - no buffering.
>> You read LENGTH bytes and see how many characters that is.
>> You find it is LENGTH-N chars so you read N more bytes and see where 
>> you are ... 
>What about swallowing an EOF off a TTY by accident? You read 4096, you
>only get 192. You read again, you get 0. EOF is now swallowed, although
>the caller has no idea.


This thread is supposed to be about what it means - not about the 
implementation. I am painfully aware of the implementation issues.

>> >For Perl read(), we don't care, because read() is buffered and is not
>> >affected by the same performance issues mentioned earlier. Reading one
>> >byte at a time is not expensive for buffered PerlIO handles.
>> Nor necessary! as PerlIO can "unread" abitrary amount of data,
>> and :encoding snoops the buffer a perl-ish manner, and ...
>Unless select() is emulated as well to peek at the PerlIO buffers, this
>is not true. 

select() says a read(2) will not block. It says nothing about read(), 
readline() in perl or fread() in stdio world.
>> I started this thread to (A) make sure that I was not alone in that view
>> and (B) to try and collect arguments for the other side as well.
>I don't want to give you arguments for the other side. :-)

So consider your "vote" counted.

Nick Ing-Simmons

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About