From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 89B277F747 for ; Mon, 18 Aug 2014 18:16:02 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of edouardevangelisti@gmail.com) identity=pra; client-ip=209.85.217.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="edouardevangelisti@gmail.com"; x-sender="edouardevangelisti@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of edouardevangelisti@gmail.com designates 209.85.217.174 as permitted sender) identity=mailfrom; client-ip=209.85.217.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="edouardevangelisti@gmail.com"; x-sender="edouardevangelisti@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-lb0-f174.google.com) identity=helo; client-ip=209.85.217.174; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="edouardevangelisti@gmail.com"; x-sender="postmaster@mail-lb0-f174.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvQBAFIm8lPRVdmum2dsb2JhbABZg2BXBIJ4r0oHhCyUH4Fjh1iBGQgWEAEBAQEBBgsLCRQphAQBAQMBEhEdAS0LAQMBCwEFAwIEBxodAgIiEgEFAQoSBhMSEIgMAwkIDY9EkCdriyuFAoojJwMKV4RcEQEFDo86gwSBUwWFBAWKCYMOgyuGd4FXkToYKYFrgyQ8L4JPAQEB X-IPAS-Result: AvQBAFIm8lPRVdmum2dsb2JhbABZg2BXBIJ4r0oHhCyUH4Fjh1iBGQgWEAEBAQEBBgsLCRQphAQBAQMBEhEdAS0LAQMBCwEFAwIEBxodAgIiEgEFAQoSBhMSEIgMAwkIDY9EkCdriyuFAoojJwMKV4RcEQEFDo86gwSBUwWFBAWKCYMOgyuGd4FXkToYKYFrgyQ8L4JPAQEB X-IronPort-AV: E=Sophos;i="5.01,887,1400018400"; d="scan'208";a="75136469" Received: from mail-lb0-f174.google.com ([209.85.217.174]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 18 Aug 2014 18:15:43 +0200 Received: by mail-lb0-f174.google.com with SMTP id c11so4317496lbj.19 for ; Mon, 18 Aug 2014 09:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=q5eSfPIe1snzxieCsi6+QSIUV9ko8y32WDckhhmCT2Y=; b=nGRx2sCz5Nq8xgg+uy9mqP/WbxqNb5W/PcgekeC/qYsrm/AMM3tmLYUpbEMrFJGEZW stSObZPAQI1LcxO3t8hiEauVQ8g2Z97b3pY6roLHI6IjxuK+h8V4dDYXMhROOnudxUmQ c1dSIElz6lB/AdHcnKG3PAd9E1tHsWZXmusIeMYxs0WhVz5Jzg2AWEEgJa5ISgVzSRSH +lhk4aNL9Tu+NUh3aCly8VZjdByLalVCxnWdi2MGmDLTVIYDhLVy/w3sAgWAuQQfwdzg y9ccuv/3kuJmSWIOfIFWwRjIPWmyftEfXBYaFioQMn2ZtoWQ9Ny9xNx61EDfJt286q7/ X6Qg== MIME-Version: 1.0 X-Received: by 10.152.25.170 with SMTP id d10mr29983454lag.37.1408378542893; Mon, 18 Aug 2014 09:15:42 -0700 (PDT) Sender: edouardevangelisti@gmail.com Received: by 10.112.141.67 with HTTP; Mon, 18 Aug 2014 09:15:42 -0700 (PDT) In-Reply-To: <20140818161029.GA13445@notk.org> References: <20140818161029.GA13445@notk.org> Date: Mon, 18 Aug 2014 17:15:42 +0100 X-Google-Sender-Auth: x3d1YhUYE52UuOHWA13GCAXALJs Message-ID: From: Edouard Evangelisti To: Adrien Nader Cc: Thomas Braibant , OCaML Mailing List Content-Type: multipart/alternative; boundary=089e0158b738c230fa0500e9ae21 X-Validation-by: edouard.evangelisti@slcu.cam.ac.uk Subject: Re: [Caml-list] Unix file descriptors vs. in/out channels --089e0158b738c230fa0500e9ae21 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable =E2=80=8B=E2=80=8BDear Paolo and Anders, Thank you for your messages. I tried to use Paolo's code and the exception Timeout was raised. I was not able to read char by char without O_NONBLOCK : the program is just waiting forever for something to read. I was able to retrieve some data using Unix.in_channel_of_descr, but the data are not transmitted synchronously, which is required in my case. Thus, I will probably rewrite this part in C using the same strategy and see if it works. I cannot understand why this strategy works for HyperTerminal and not for me with the same material. Thank you again. Edouard 2014-08-18 17:10 GMT+01:00 Adrien Nader : > Hi, > > You cannot safely mix buffered (in/out_channel) and un-buffered > (file_descr) uses of the same underlying resource. > > IIRC an in_channel or out_channel has a buffer in OCaml memory. > If you close the underlying file_descr of an out_channel with > functions operating on file desriptors directly, it is possible that > some data will still be buffered. > If you read alternatively through file_descr and in_channel, you might > skip some data if reading with the in_channel reads more than just "n > chars" (it could read 4K for instance, I'm not completely sure). > > As for using in/out_channel_of_descr more than once, I don't know > offhand: if it creates new buffers each time (likely), it will be an > issue. > > -- > Adrien Nader > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --=20 Edouard Evangelisti Post doctoral Research Associate Sainsbury Laboratory, Cambridge University (SLCU) Bateman Street Cambridge CB2 1LR (United Kingdom) --089e0158b738c230fa0500e9ae21 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
=E2=80=8B=E2=80=8BDear Paolo and Anders,

Thank you for yo= ur messages. I tried to use Paolo's code and the exception Timeout was = raised. I was not able to read char by char without O_NONBLOCK : the progra= m is just waiting forever for something to read.

I was able to retrieve some data using Unix.in_channel_of_descr, but th= e data are not transmitted synchronously, which is required in my case. Thu= s, I will probably rewrite this part in C using the same strategy and see i= f it works. I cannot understand why this strategy works for HyperTerminal a= nd not for me with the same material.

Thank you again.

Edouard

2014-08-18 17:10 GMT+01:00 Adrien Nader <adrien@notk.org>:
=
Hi,

You cannot safely mix buffered (in/out_channel) and un-buffered
(file_descr) uses of the same underlying resource.

IIRC an in_channel or out_channel has a buffer in OCaml memory.
If you close the underlying file_descr of an out_channel with
functions operating on file desriptors directly, it is possible that
some data will still be buffered.
If you read alternatively through file_descr and in_channel, you might
skip some data if reading with the in_channel reads more than just "n<= br> chars" (it could read 4K for instance, I'm not completely sure).
As for using in/out_channel_of_descr more than once, I don't know
offhand: if it creates new buffers each time (likely), it will be an
issue.

--
Adrien Nader

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



--
Edouard Evangelisti
Post doctoral Research Associate
Sainsbury Labora= tory, Cambridge University (SLCU)
Bateman Street
Cambridge CB2 1LR (United Kingdom)
--089e0158b738c230fa0500e9ae21--