Confused by sysread()

Roger Burton West roger at firedrake.org
Mon Apr 9 22:32:09 BST 2012


Under Linux amd64 and Perl 5.10.1, I'm trying to read from a pair of
devices which will produce data in 16-byte blocks. (I can cat the device
files - as the same user - and verify that they do this.)

Under Perl 5.8 (and an earlier i386 Linux), this worked. Now sysread()
is failing with an "Invalid argument".

I'm using an IO::Select thus, where @dev contains the device filenames:

my $s=IO::Select->new;
my @fh;
foreach my $device (@dev) {
  my $fh;
  open $fh,'<',$device;
  binmode $fh;
  $s->add(\*$fh);
  push @fh,$fh;
}

while (1) {
  my @ready=$s->can_read(0.5);
  foreach my $fh (@ready) {
    my $data;
    my $y=sysread $fh,$data,16;
    die $! unless defined $y;
    # do stuff with $data
  }
}

I can change the open to

sysopen $fh,$device,O_RDONLY;

with no change in the result; if I add O_DIRECT, the @ready list never
gets filled at all.

Have I missed something important somewhere?

Roger


More information about the london.pm mailing list