From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id CC5D9BC84 for ; Fri, 1 Apr 2005 15:37:09 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j31Db9uo026197 for ; Fri, 1 Apr 2005 15:37:09 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA02562 for ; Fri, 1 Apr 2005 15:37:08 +0200 (MET DST) Received: from saul.cis.upenn.edu (SAUL.CIS.upenn.edu [158.130.12.4]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j31Db6fu026189 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Fri, 1 Apr 2005 15:37:08 +0200 Received: from localhost (localhost [127.0.0.1]) by saul.cis.upenn.edu (8.12.10/8.12.9) with ESMTP id j31Db0CP028791; Fri, 1 Apr 2005 08:37:01 -0500 (EST) Date: Fri, 01 Apr 2005 08:37:00 -0500 (EST) Message-Id: <20050401.083700.125103382.eijiro_sumii@anet.ne.jp> To: caml-list@inria.fr Cc: gerd@gerd-stolpmann.de, sumii@saul.cis.upenn.edu Subject: Re: [Caml-list] select (or polling) on in_channel? From: Eijiro Sumii In-Reply-To: <1112353164.6180.10.camel@localhost.localdomain> References: <20050331.182855.07449233.eijiro_sumii@anet.ne.jp> <1112353164.6180.10.camel@localhost.localdomain> X-Mailer: Mew version 3.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 424D4E85.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 424D4E82.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 polling:01 eijiro:01 sumii:01 eijiro:01 sumii:01 gerd:01 stolpmann:01 gerd:01 buffer:01 buffer:01 polling:01 binary:01 pervasives:01 pervasives:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Thanks for the reply! From: "Gerd Stolpmann" > Yes. The point is that you cannot interpret the result of Unix.select in > a reasonable manner. When Unix.select says the descriptor has no data, > it might still the case that there are data in the buffer. Yes, this is what I thought. > If the descriptor has data, you don't know when they are exactly > read into the buffer. Here I don't quite understand what you mean - does this issue per se prevent us from polling an in_channel? > I don't understand why you mention in_channel_length here. If the channel were a (binary) file, I could use in_channel_length to know how many bytes I should read (by Pervasives.really_input, for example). > What is your real problem? In my program, I need to wait _only for 60 seconds_ for data from a channel created by Unix.open_connection. For this purpose, something like Unix.select would be the best if it worked. Assuming that no such function like Unix.select exists for Pervasives.in_channel, I've written the following ad hoc external function, which can be used (in combination with Unix.select) to achieve similar effects. Of course, it might be unsafe if the channel structure is different in other versions of OCaml. Any better idea, anyone...? Eijiro ---------------------------------------------------------------------- #include #include /* adapted from ocaml-3.08.3/byterun/io.h */ struct channel { int fd; off_t offset; char * end; char * curr; char * max; void * mutex; struct channel * next; int revealed; int old_revealed; int refcount; char buff[0]; }; #define Channel(v) (*((struct channel **) (Data_custom_val(v)))) value in_channel_is_empty(value vc) { struct channel *c = Channel(vc); return Val_int((c->curr >= c->max) ? 1 : 0); }