develooper Front page | perl.perl5.porters | Postings from April 2004

[perl #29277] eof() on non-blocking filehandle

Thread Next
From:
perl-5 . 8 . 0 @ ton . iguana . be
Date:
April 30, 2004 06:17
Subject:
[perl #29277] eof() on non-blocking filehandle
Message ID:
rt-3.0.9-29277-86530.16.998825074622@perl.org
# New Ticket Created by  perl-5.8.0@ton.iguana.be 
# Please include the string:  [perl #29277]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=29277 >



This is a bug report for perl from perl-5.8.0@ton.iguana.be,
generated with the help of perlbug 1.34 running under perl v5.8.2.


-----------------------------------------------------------------
[Please enter your report here]

Using this testprogram:

#! /usr/bin/perl -wl
use strict;
use IO::Socket::INET;
use POSIX qw(F_GETFL F_SETFL O_NONBLOCK);

pipe(my $rd, my $wr) || die "Could not create pipe: $!";
my $flags = fcntl($rd, F_GETFL, 0) || die "Can't get fcntl flags: $!\n";
fcntl($rd, F_SETFL, $flags | O_NONBLOCK) || die "Can't set fcntl flags: $!\n";
select($wr);
$|=1;
close($wr) if @ARGV;
my $rc = eof($rd);
print STDERR defined($rc) ? $rc : "undef", "/$!";

Running it with an argument:
1/Illegal seek

In an strace near the end I see:

pipe([3, 4])                            = 0
ioctl(3, SNDCTL_TMR_TIMEBASE, 0xbfffeb30) = -1 EINVAL (Invalid argument)
_llseek(3, 0, 0xbfffeb80, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
ioctl(4, SNDCTL_TMR_TIMEBASE, 0xbfffeb30) = -1 EINVAL (Invalid argument)
_llseek(4, 0, 0xbfffeb80, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
fcntl64(4, F_SETFD, FD_CLOEXEC)         = 0
fcntl64(3, F_GETFL)                     = 0 (flags O_RDONLY)
fcntl64(3, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
close(4)                                = 0
read(3, "", 4096)                       = 0
brk(0)                                  = 0x82bc800
brk(0x82be000)                          = 0x82be000
write(2, "1", 11)                        = 1
write(2, "/Illegal seek", 13/Illegal seek)           = 13
write(2, "\n", 1
)                       = 1
close(3)                                = 0

So the code indeed saw the EOF, but it reports it with errno set 
to a bit strange value, but ok.

Now without argument (not closing the write side of the pipe):
1/Illegal seek

mm, but there is no EOF this time....

Again looking at the strace:

pipe([3, 4])                            = 0
ioctl(3, SNDCTL_TMR_TIMEBASE, 0xbfffeb40) = -1 EINVAL (Invalid argument)
_llseek(3, 0, 0xbfffeb90, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
ioctl(4, SNDCTL_TMR_TIMEBASE, 0xbfffeb40) = -1 EINVAL (Invalid argument)
_llseek(4, 0, 0xbfffeb90, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
fcntl64(4, F_SETFD, FD_CLOEXEC)         = 0
fcntl64(3, F_GETFL)                     = 0 (flags O_RDONLY)
fcntl64(3, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
read(3, 0x8175804, 4096)                = -1 EAGAIN (Resource temporarily unavailable)
brk(0)                                  = 0x82bc800
brk(0x82be000)                          = 0x82be000
write(2, "1", 11)                        = 1
write(2, "/Illegal seek", 13/Illegal seek)           = 13
write(2, "\n", 1
)                       = 1
close(3)                                = 0
close(4)                                = 0

So the read got EAGAIN (so perl should know it's not really EOF),
but eof() still returns true, but i think it should have returned
something false here. The errno is also strange (seemingly that old
ESPIPE got saved and later restored, overwriting the EAGAIN).

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl v5.8.2:

Configured by ton at Sun Jan  4 19:19:06 CET 2004.

Summary of my perl5 (revision 5.0 version 8 subversion 2) configuration:
  Platform:
    osname=linux, osvers=2.6.0, archname=i686-linux-64int-ld
    uname='linux quasar 2.6.0 #3 thu dec 18 18:22:48 cet 2003 i686 gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=define
    usemymalloc=y, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -fomit-frame-pointer',
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='3.4.0 20031231 (experimental)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.8.2:
    /usr/lib/perl5/5.8.2/i686-linux-64int-ld
    /usr/lib/perl5/5.8.2
    /usr/lib/perl5/site_perl/5.8.2/i686-linux-64int-ld
    /usr/lib/perl5/site_perl/5.8.2
    /usr/lib/perl5/site_perl
    .

---
Environment for perl v5.8.2:
    HOME=/home/ton
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/ton/bin.Linux:/home/ton/bin:/home/ton/bin.SampleSetup:/usr/local/bin:/usr/local/sbin:/usr/local/jre/bin:/home/oracle/product/9.0.1/bin:/usr/local/ar/bin:/usr/games/bin:/usr/X11R6/bin:/usr/share/bin:/usr/bin:/usr/sbin:/bin:/sbin:.
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Next


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