Re: Confused by sysread()

2012-04-10 Thread Dave Mitchell
On Mon, Apr 09, 2012 at 10:32:09PM +0100, Roger Burton West 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.)

Unlikely to be the issue, but have you tested doing a single 16-byte read,
e.g.

dd if=/dev/foo of=/dev/null bs=16 count=1

 Have I missed something important somewhere?

Not that I can see; (well, you don't test the result of the open, but I
doubt that's the problem in this case).

Try running it with strace, to see what underlying system calls are being
performed on the file handle. If its not obvious from that, then strace
the working 5.8.x version too to see what's different. 

-- 
Thank God I'm an atheist.


Re: Confused by sysread()

2012-04-10 Thread Dirk Koopman

On 09/04/12 22:32, Roger Burton West wrote:

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
   }
}



For what it is worth, I am running a similar loop which will call 
sysread, but with an extra offset parameter as in:


 my $y=sysread $fh,$data,16,0;

I believe I did this for similar reasons as early as perl 5.0004. But 
this may be complete misremembering on my part as it was more than 12 
years ago. My version of this code is still running very happily on perl 
5.10.1, but on sockets and in non-blocking mode.

































































Re: Confused by sysread()

2012-04-10 Thread Roger Burton West
On Tue, Apr 10, 2012 at 10:51:27AM +0100, Dave Mitchell wrote:

Unlikely to be the issue, but have you tested doing a single 16-byte read,
e.g.
dd if=/dev/foo of=/dev/null bs=16 count=1

dd: reading `/dev/input/event8': Invalid argument

...but open() doesn't fail, and cat still works.

OK, so it's not something Perl-specific? This is running off the end of
the Unix I know, but there are people I can ask... thanks.

Try running it with strace, to see what underlying system calls are being
performed on the file handle.

[...]
select(8, [3 4], NULL, NULL, {0, 50}) = 0 (Timeout)
select(8, [3 4], NULL, NULL, {0, 50}) = 0 (Timeout)
select(8, [3 4], NULL, NULL, {0, 50}) = 1 (in [4], left {0, 490567})
read(4, 0xa2a5e0, 16)   = -1 EINVAL (Invalid argument)
write(2, Invalid argument at ./tmp line 5..., 35) = 35
close(3)= 0
close(4)= 0
[...]

If its not obvious from that, then strace
the working 5.8.x version too to see what's different. 

That would be the version from before the system upgrade; I don't have
any 5.8.x boxes left.

On Tue, Apr 10, 2012 at 11:02:31AM +0100, Dirk Koopman wrote:
 my $y=sysread $fh,$data,16,0;

Makes no difference.

R


Re: Confused by sysread()

2012-04-10 Thread Roger Burton West
On Mon, Apr 09, 2012 at 10:32:09PM +0100, Roger Burton West 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.

The answer appears to be that the structure returned by evdev_read() is
larger for 64-bit processes - changing from a 16- to a 24-byte read has
solved the problem. Thanks for the suggestions here.

R


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