caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Sheets <sheets@alum.mit.edu>
To: Thomas Braibant <thomas.braibant@gmail.com>
Cc: Xavier Leroy <Xavier.Leroy@inria.fr>,
	OCaML Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Unix file descriptors vs. in/out channels
Date: Mon, 18 Aug 2014 18:55:44 +0100	[thread overview]
Message-ID: <CAAWM5TyyEZmdfV4Xq6HjZ3W0XAxYGR7N6=XVa==RTx7izhQi2g@mail.gmail.com> (raw)
In-Reply-To: <CAHR=Vkw9qbsaG7attOqud6F761mLvetytT5URVFm2Jwb+55R9g@mail.gmail.com>

On Mon, Aug 18, 2014 at 6:18 PM, Thomas Braibant
<thomas.braibant@gmail.com> wrote:
> Ah, my bad, sorry for the noise!
>
> Le 18 août 2014 18:58, "Xavier Leroy" <Xavier.Leroy@inria.fr> a écrit :
>
>> On 18/08/14 18:52, Thomas Braibant wrote:
>>
>> > Well, I was thinking about the following situation
>> >
>> >   let open Unix in
>> >   let fd = openfile "foo.bar" [O_RDWR; O_TRUNC; O_CREAT] 0o640 in
>> >   let o = out_channel_of_descr fd in
>> >   let i = in_channel_of_descr fd in
>> >   let i2 = in_channel_of_descr fd in
>> >   Printf.printf "1\n%!";
>> >   close_in i;
>> >   Printf.printf "2\n%!";
>> >   close_in i2;
>> >   Printf.printf "3\n%!";
>> >   close_out o;
>> >   Printf.printf "Ok\n%!"
>> >
>> > that raises the fatal error: exception Sys_error("Bad file
>> > descriptor"), and now, I do not understand your remark either :(.
>>
>> I said "close all your channels at once when you're done with the
>> underlying file descriptor".  What you observe is that after the first
>> close_in, all the other channels are unusable, because the underlying
>> FD is closed.

I'm sorry. I still don't understand. The following raises on the first close_in:

let open Unix in
let fd = openfile "foo.bar" [O_RDWR; O_TRUNC; O_CREAT] 0o640 in
let o = out_channel_of_descr fd in
let i = in_channel_of_descr fd in
let i2 = in_channel_of_descr fd in
Printf.printf "1\n%!";
close_out o;
close_in i;
close_in i2;
Printf.printf "Ok\n%!"

To get the error ignoring property, I think you have to use
close_out_noerr (not in this case) and close_in_noerr.

Maybe I've missed some subtlety here, though. I'm a little uneasy
ignoring *all* errors...

David

>> - Xavier Leroy
>>
>> --
>> 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

      reply	other threads:[~2014-08-18 17:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-18 14:42 Thomas Braibant
2014-08-18 16:10 ` Adrien Nader
2014-08-18 16:15   ` Edouard Evangelisti
2014-08-18 16:29   ` Thomas Braibant
2014-08-18 16:33 ` Xavier Leroy
2014-08-18 16:52   ` Thomas Braibant
2014-08-18 16:57     ` Xavier Leroy
2014-08-18 17:18       ` Thomas Braibant
2014-08-18 17:55         ` David Sheets [this message]

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='CAAWM5TyyEZmdfV4Xq6HjZ3W0XAxYGR7N6=XVa==RTx7izhQi2g@mail.gmail.com' \
    --to=sheets@alum.mit.edu \
    --cc=Xavier.Leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=thomas.braibant@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).