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=1.7 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 33028BBAF for ; Wed, 25 Mar 2009 14:42:33 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlkBANDRyUnRVdq0kGdsb2JhbACVLj8BAQEBCQkMBxEDrD+PagEDAQODcgaFcQ X-IronPort-AV: E=Sophos;i="4.38,419,1233529200"; d="scan'208";a="37182764" Received: from mail-bw0-f180.google.com ([209.85.218.180]) by mail4-smtp-sop.national.inria.fr with ESMTP; 25 Mar 2009 14:42:32 +0100 Received: by bwz28 with SMTP id 28so39820bwz.9 for ; Wed, 25 Mar 2009 06:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=LFr5YAQFAmdAjGY1yr5ChyEmwwMrP2LC1RaT4zcM2vo=; b=h4mF/5MQ8AqPJHB2HOBLaD2uhKFBSzr5gE2yXBRNJoQFZoW42kwyKZbjnh3iEOA7pg VZ/aIX2F/+DFXeX+tLXkfbBIbC4enjcgJIF4likqCdAlmdtFLH+rhHFaQpjgIJPNIExZ s7QJJrRk8IjiVc8leIPpMCRZC+LbMRGhLXnyc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=niKLGTMFim+bnfdKDMPCwNF/5m1UZx4h5d96VEX3Tbtx7i5exSFCiSc1oNuoSamzp5 1W4/nlgQAZnT4E4lQJ96YFGTlbsqFz+HgvS1lm3xlZD/iyuwDQup3Ft8R+PRz5bXR060 gRlprRF6U25Qfi1RLqisTf4j4u0xmwDOpMkIE= MIME-Version: 1.0 Sender: oandrieu@gmail.com Received: by 10.239.135.210 with SMTP id e18mr195261hbe.135.1237988552053; Wed, 25 Mar 2009 06:42:32 -0700 (PDT) In-Reply-To: References: Date: Wed, 25 Mar 2009 14:42:32 +0100 X-Google-Sender-Auth: 8fcca42fdec03491 Message-ID: <95513600903250642h17618274sa79970e82234d00f@mail.gmail.com> Subject: Re: [Caml-list] in_channel_of_descr questions From: Olivier Andrieu To: Christoph Bauer Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; andrieu:01 oandrieu:01 sockets:01 sockets:01 allocates:01 runtime:01 2009:98 stays:98 wrote:01 unix:01 unix:01 integer:01 caml-list:01 nerim:01 descriptor:02 Hi, On Wed, Mar 25, 2009 at 13:37, Christoph Bauer wrote: > Hello, > > I have some questions concerning in_channel_of_descr: my program > has a list of sockets. I need the sockets itself for a select-Loop > and an in_channel for the convenient input_line function. At the end, > which one should i close? Just the socket, just the channel or both? On unix, you should close either one of them, but not both. The filedescriptor is shared, so closing the socket or the channel will close the file descriptor. > On Windows I tried to create many in_channels, one for each block > I read. Then I get soon an =A0"Too many open files in the system" error. > In win32unix/channels.c I see an _open_osfhandle() call for each > in_channel_of_descr. On unix the same program runs fine (as expected). > So is there a different approach needed for windows e.g. close just > the socket on unix, but close socket and in_channel > on windows? (In any case I'll remove the repeated call of > in_channel_of_descr...). yes on windows, you need to close the channel. Calling in_channel_of_descr will indeed call _open_osfhandle() which allocates an integer fd in the C runtime to represent the Win32 handle. If you close the socket and not the channel, this CRT fd stays allocated and you eventually run out of fd. If you close the channel, the CRT fd will be closed, and that will close the Win32 handle too. --=20 Olivier