Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: James Lamanna <jamesl@appliedminds.com>
To: caml-list@inria.fr
Subject: Need help! - Unix.read always returning 0
Date: Mon, 08 Nov 2004 10:17:03 -0800	[thread overview]
Message-ID: <418FB81F.7050100@appliedminds.com> (raw)

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


                 reply	other threads:[~2004-11-08 18:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=418FB81F.7050100@appliedminds.com \
    --to=jamesl@appliedminds.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox