Re: Catching Break?

From: Ian T Zimmerman (itz@transbay.net)
Date: Sat Feb 06 1999 - 09:24:18 MET


To: Ian T Zimmerman <itz@transbay.net>
Subject: Re: Catching Break?
From: Ian T Zimmerman <itz@transbay.net>
Date: 06 Feb 1999 00:24:18 -0800
In-Reply-To: Ian T Zimmerman's message of Thu, 28 Jan 1999 09:33:20 -0800

Ian T Zimmerman <itz@transbay.net> writes:

> Ok, I see that I'll have to start posting my real code, because I
> still can't make it work despite (imperfect) analogy with the
> example.
> let remove_pair prefix pid =
> let spid = string_of_int pid in let iname = prefix ^ spid ^ ".i"
> and oname = prefix ^ spid ^ ".o" in Sys.remove iname; Sys.remove
> oname
> let open_pair prefix pid respond =
> let spid = string_of_int pid in let iname = prefix ^ spid ^ ".i"
> and oname = prefix ^ spid ^ ".o" and iflags = [Unix.O_RDONLY ;
> Unix.O_NONBLOCK] and oflags = [Unix.O_WRONLY] in let id x = x in
> Sys.catch_break true; let (ind, outd) = try if respond then
> let outd = Unix.openfile iname oflags 0 in let ind =
> Unix.openfile oname iflags 0 in id (ind, outd)
> else
> let ind = Unix.openfile iname iflags 0 in let outd =
> Unix.openfile oname oflags 0 in (* HERE! *) id (ind, outd)
> with Sys.Break ->
> if not respond then remove_pair prefix pid; Sys.catch_break
> false; exit 0; assert false in
> Sys.catch_break false; (ind, outd)
>
> The files referred to by [io]name are named pipes; the write open
> hangs until the other side is opened, which may never happen. So as
> to have a chance to clean up (namely remove the pipes), I must allow
> _and_ catch Control-C as I'm trying to. But it doesn't work; if I
> hit Control-C while blocked in the open marked, I never get into the
> with handler.
>

I tried this:

let remove_pair prefix pid =
  let spid = string_of_int pid in
  let iname = prefix ^ spid ^ ".i"
  and oname = prefix ^ spid ^ ".o" in
  Sys.remove iname; Sys.remove oname

let open_pair prefix pid respond =
  let spid = string_of_int pid in
  let iname = prefix ^ spid ^ ".i"
  and oname = prefix ^ spid ^ ".o"
  and iflags = [Unix.O_RDONLY ; Unix.O_NONBLOCK]
  and oflags = [Unix.O_WRONLY] in
  Sys.catch_break true;
  let (ind, outd) = try if respond then
    let outd = Unix.openfile iname oflags 0 in
    let ind = Unix.openfile oname iflags 0 in
    for i = 0 to 1 do () done; (ind, outd)
  else
    let ind = Unix.openfile iname iflags 0 in
    let outd = Unix.openfile oname oflags 0 in
    for i = 0 to 1 do () done; (ind, outd)
  with Sys.Break ->
    if not respond then remove_pair prefix pid;
    Sys.catch_break false; exit 0;
    assert false in
  Sys.catch_break false; (ind, outd)

... and it doesn't work, either :-(
I am really stumped, please help.

-- 
Ian T Zimmerman                        <itz@transbay.net>
I came to the conclusion that what was wrong about the guillotine
was that the condemned man had no chance at all, absolutely none.
Albert Camus, _The Outsider_



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:19 MET