Browse thread
Need help! - Unix.read always returning 0
- James Lamanna
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | James Lamanna <jamesl@a...> |
| Subject: | Need help! - Unix.read always returning 0 |
I really can't explain this, but Unix.read is always returning 0.
I have the following simple Ocaml program:
let buffer_length = 16 in
let buffer = ref (String.create buffer_length) in
let j = Unix.openfile "/dev/stick" [Unix.O_RDONLY] 0o666 in
try
while true do
let n = Unix.read j !buffer 0 buffer_length in
print_int n;
print_string "\n";
flush stdout
done
with
End_of_file -> ()
/dev/stick is a linux event device, so it should block.
However, it does not block, and Unix.read consistently returns 0.
However, the corresponding C program:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
int main(int argc, char **argv)
{
struct input_event ev;
int fd = open("/dev/stick", O_RDONLY);
while(1) {
int r = read(fd, &ev, sizeof(ev));
printf("%d\n", r);
}
return 0;
}
Exhibits the desired behavior and reads correctly from the device.
Any help? I'm kinda in a crunch on this.
This behavior started when I moved to an AMD64 platform.
Thank you.
--
James Lamanna