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 57550BC48 for ; Tue, 5 Apr 2005 07:49:07 +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 j355n6Gj007441 for ; Tue, 5 Apr 2005 07:49:06 +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 HAA19009 for ; Tue, 5 Apr 2005 07:49:06 +0200 (MET DST) Received: from alex.barettalocal.com (h213-255-109-130.albacom.net [213.255.109.130] (may be forged)) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j355n5o6007438 for ; Tue, 5 Apr 2005 07:49:05 +0200 Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by alex.barettalocal.com (Postfix) with ESMTP id D75672BAAD0; Tue, 5 Apr 2005 07:49:04 +0200 (CEST) Message-ID: <425226CF.80708@barettadeit.com> Date: Tue, 05 Apr 2005 07:49:03 +0200 From: Alex Baretta User-Agent: Debian Thunderbird 1.0 (X11/20050116) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Eijiro Sumii , Ocaml Subject: Re: [Caml-list] select (or polling) on in_channel? References: <20050331.182855.07449233.eijiro_sumii@anet.ne.jp> <20050404.162414.18571932.eijiro_sumii@anet.ne.jp> In-Reply-To: <20050404.162414.18571932.eijiro_sumii@anet.ne.jp> X-Enigmail-Version: 0.90.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 425226D2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 425226D1.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; baretta:01 caml-list:01 eijiro:01 sumii:01 pervasives:01 low-level:01 high-level:01 buffered:01 pervasives:01 api:01 model:01 threads:01 trivial:01 buf:01 buf:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: Eijiro Sumii wrote: > Thanks to everyone for ideas on how to "select" Pervasives.in_channel. > Since there seems to be no better solution than > > (1) hacking the low-level structure by using external C, or > > (2) reinventing the high-level library on top of Unix I/O, > ... I have not been following this thread closely, so I did not answer earlier. My impression is that select and buffered IO are concepts that do not live well together. I This is probably the reason the Caml team has for not implementing such a feature in the Pervasives channels API. I would attempt to model the problem in a multithreaded paradigm, where the the "selecting" is implicit in the thread scheduling mechanism. Of course, if you allow the use of threads, the selecting on channels becomes fairly trivial. let (++) x f = f x let input_string = let buf = String.create 1024 in fun ic -> let bytes = input ic buf 0 1024 in String.sub buf 0 bytes module IO_manager = struct type tio_manager = string Event.channel let wrap_in_channel (evch : io_manager) (ic : input_channel)= let rec cycle () = ic ++ input_string ++ Event.send ++ Event.sync; cycle () in Thread.create cycle () end Of course, this is a very rough sketch of message_passing API based on the Event module, encapsulating the select facility on top of an input_channel. Actually, ic could be any resource the program might need to synchronize on. Let me add that Baretta DE&IT is using this paradigm to multiplex IO from/to different field buses in its Ocaml based, SoftPLC / SoftCNC kernel. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project