Front page | perl.perl5.porters |
Postings from August 2002
Re: Ideas for 5.10
Thread Previous
|
Thread Next
From:
Mark-Jason Dominus
Date:
August 13, 2002 10:24
Subject:
Re: Ideas for 5.10
Message ID:
20020813172328.10149.qmail@plover.com
Perhaps I am late to this discussion, and am repeating something that
has already been said, but:
Nick Ing-Simmons wrote:
> Benjamin Goldberg <goldbb2@earthlink.net> writes:
> > SELECTLOOP: {
> > ((my $nready), $timeout) =
> > CORE::select( (my $ready=$rvec), '', '', $timeout );
> > return if $nready <= 0;
> > while( $ready =~ /[^\0]+/g ) {
> > for my $fd ( $-[0] * 8 .. $+[0] * 8 ) {
> > next unless vec( $ready, $fd, 1 );
> > my $handle = $handles->[$fd];
> > my $bufref = GetPerlIOBuffer( $handle );
> > my $irs = $input_rec_seps->{$fd};
> > $irs = $/ unless exists $input_rec_seps->{$fd};
> > my $m = sysread $handle, $$bufref, LOTS, length $$bufref;
>
> And that sysread hangs. The select() just says a sysread() of one byte
> will not hang - nothing more.
>
> To avoid the hang you either have to sysread one byte (not even one char
> in a Unicode world!) at a time, or put handle into non-blocking mode.
I am confident that you are mistaken. I believe that POSIX semantics
are that when select() indicates a descriptor is ready for reading,
the immediately next read() will *never* block.
That is why read() is allowed to read fewer than the number of bytes
requested, and returns the number of bytes actually read. If you ask
for a million bytes from a terminal, socket, or pipe, and only one is
available, it will not block; instead, it reads the one available byte
and returns 1. read() on a terminal, socket, or pipe will block only
when there is nothing at all available. On files, of course, it never
blocks at all.
It may be that my experience is too limited but I believe that is the
way it has been on every Unix system I have ever used. I just
double-checked it with terminals, pipes, and sockets under Linux 2.4.2
and SunOS 5.8, the two systems I have handy right now.
Unix being Unix, there may be some broken version somewhere on which
it is impossible to read reliably, but this behavior is so old and so
well-established that there might not be. In any case I think more
research should be done before we write off this possibility.
Thread Previous
|
Thread Next