From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 1ED7DBC69 for ; Sat, 15 Sep 2007 18:12:19 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAC6h60bAXQImh2dsb2JhbACBV4w7AQEBCAQGJw X-IronPort-AV: E=Sophos;i="4.20,258,1186351200"; d="scan'208";a="820308" Received: from discorde.inria.fr ([192.93.2.38]) by mail1-smtp-roc.national.inria.fr with ESMTP; 15 Sep 2007 18:13:00 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l8FGCaBZ022203 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sat, 15 Sep 2007 18:12:37 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAC6h60bVhW6V/2dsb2JhbACBVw X-IronPort-AV: E=Sophos;i="4.20,258,1186351200"; d="scan'208";a="2743454" Received: from server2.thinkcrime.de ([213.133.110.149]) by mail3-smtp-sop.national.inria.fr with ESMTP; 15 Sep 2007 18:12:59 +0200 Received: from hod-sarge-2005-10.lan.m-e-leypold.de (dslb-088-072-195-133.pools.arcor-ip.net [88.72.195.133]) (Authenticated sender: hod-sarge-2005-10@server2) by server2.thinkcrime.de (Postfix) with ESMTP id 732AE900245 for ; Sat, 15 Sep 2007 18:12:43 +0200 (CEST) Received: by hod-sarge-2005-10.lan.m-e-leypold.de (Postfix, from userid 1003) id 6A5BB37962; Sat, 15 Sep 2007 18:17:24 +0200 (CEST) To: caml-list@inria.fr Subject: Re: [Caml-list] Closing all open file descriptors References: <006b01c7f699$275fd6d0$017ca8c0@countertenor> <200709141000.l8EA04x12648@virtutech.se> <1189806728.46eb0288d38b8@webmail.in-berlin.de> <1189847741.46eba2bd9d121@webmail.in-berlin.de> <20070915192631.2384ae5a.mle+ocaml@mega-nerd.com> <1189852990.46ebb73e7edc3@webmail.in-berlin.de> <5fps0k9fp4.fsf@hod.lan.m-e-leypold.de> <20070915155816.GC3983@stratocaster.home> From: Markus E L Organization: N/A Date: Sat, 15 Sep 2007 18:17:24 +0200 In-Reply-To: <20070915155816.GC3983@stratocaster.home> (Eric Cooper's message of "Sat, 15 Sep 2007 11:58:16 -0400") Message-ID: <91wczaoob.fsf@hod.lan.m-e-leypold.de> User-Agent: Some cool user agent (SCUG) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at discorde with ID 46EC0475.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; descriptors:01 markus:01 descriptors:01 fstat:01 fstat:01 readdir:01 readdir:01 markus:01 wrote:01 unix:01 unix:01 caml-list:01 int:01 int:01 descriptor:02 Eric Cooper wrote: > I think the right interface for this should be a "fold" over open file > descriptors: > > open Unix > > let descr_of_int n = (Obj.magic (n : int) : file_descr) > > let valid_descr fd = > try ignore (fstat fd); true > with Unix_error (EBADF, "fstat", _) -> false > > let fold_open_fds f init = > let f' x s = > let fd = descr_of_int (int_of_string s) in > if valid_descr fd then f x fd else x > in > Array.fold_left f' init (Sys.readdir "/proc/self/fd") > > Note that the readdir itself opens a file descriptor, which is > included in the result but then closed. So there's a little extra > complexity to filter it out so that the caller's function doesn't get > applied to a bad descriptor. Yes, that's a good idea. This can be used to retrieve a list where needed or to operate on the descriptors immediately. On systems which absolutely don't have a (system dependend) method to pull the filedescriptors from the system, one could just iterate over a predefined range. So this interface could be implemented on a larger range of systems with varying efficiency. Now the price question: Does anyone here have some insights how one gets at the open descriptors under windows? :-) Regards -- Markus