Confused by sysread()

2012-04-09 Thread Roger Burton West
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


Re: Confused by sysread()

2012-04-09 Thread Yitzchak Scott-Thoennes
On Mon, Apr 9, 2012 at 2:32 PM, Roger Burton West ro...@firedrake.org wrote:
 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.

You've probably switched from perl using stdio to using perlio.  You
could compile 5.10.1 with usestdio to see if that makes a difference.
Or you could try a newer perl and see if this is a bug that perhaps
has been fixed?

Which strikes a vague bell...does it help to say: my $data = '';


Re: Confused by sysread()

2012-04-09 Thread Yitzchak Scott-Thoennes
On Mon, Apr 9, 2012 at 2:52 PM, Yitzchak Scott-Thoennes
sthoe...@gmail.com wrote:
 Which strikes a vague bell...

Sorry, ring bells, strike chords.


Re: Confused by sysread()

2012-04-09 Thread Roger Burton West
On Mon, Apr 09, 2012 at 02:52:10PM -0700, Yitzchak Scott-Thoennes wrote:

You've probably switched from perl using stdio to using perlio.

The perl I have certainly has USE_PERLIO set.

You
could compile 5.10.1 with usestdio to see if that makes a difference.
Or you could try a newer perl and see if this is a bug that perhaps
has been fixed?

Oh dear. I could, but it's rather a slog.

Which strikes a vague bell...does it help to say: my $data = '';

No. Nor to initialise it to the size of the buffer.

R