caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Need help! - Unix.read always returning 0
@ 2004-11-08 18:17 James Lamanna
  0 siblings, 0 replies; only message in thread
From: James Lamanna @ 2004-11-08 18:17 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-11-08 18:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-08 18:17 Need help! - Unix.read always returning 0 James Lamanna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).