From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 52273BB81 for ; Tue, 27 Sep 2005 18:02:34 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j8RG2XOQ007325 for ; Tue, 27 Sep 2005 18:02:33 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA31751 for ; Tue, 27 Sep 2005 18:02:33 +0200 (MET DST) Received: from shiva.jussieu.fr (shiva.jussieu.fr [134.157.0.129]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j8RG2WOl007640 for ; Tue, 27 Sep 2005 18:02:32 +0200 Received: from hydrogene.pps.jussieu.fr (hydrogene.pps.jussieu.fr [134.157.168.1]) by shiva.jussieu.fr (8.13.5/jtpda-5.4) with ESMTP id j8RG2UEY068733 ; Tue, 27 Sep 2005 18:02:30 +0200 (CEST) X-Ids: 168 Received: from strontium (strontium.pps.jussieu.fr [134.157.168.38]) by hydrogene.pps.jussieu.fr (8.13.4/jtpda-5.4) with ESMTP id j8RG2Hlh000670 ; Tue, 27 Sep 2005 18:02:17 +0200 Received: from vouillon by strontium with local (Exim 4.52) id 1EKHuK-0003M0-SQ; Tue, 27 Sep 2005 18:02:16 +0200 Date: Tue, 27 Sep 2005 18:02:16 +0200 To: Vsevolod Fedorov Cc: caml-list@inria.fr Subject: Re: [Caml-list] Unix module API: nonblocking connect's errors retrieving Message-ID: <20050927160216.GA12864@strontium.pps.jussieu.fr> References: <00de01c5bf7c$b9113610$670aa8c0@seva> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <00de01c5bf7c$b9113610$670aa8c0@seva> User-Agent: Mutt/1.5.9i From: Jerome Vouillon X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.7.2 (shiva.jussieu.fr [134.157.0.168]); Tue, 27 Sep 2005 18:02:32 +0200 (CEST) X-Antivirus: scanned by sophie at shiva.jussieu.fr X-Miltered: at nez-perce with ID 43396D19.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43396D18.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at shiva.jussieu.fr with ID 43396D16.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 api:01 vouillon:01 vouillon:01 int':01 'int':01 workarounds:01 work-around:01 getpeername:01 wrote:01 unix:01 unix:01 jerome:01 jerome:01 jussieu:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Hello, On Thu, Sep 22, 2005 at 05:51:25PM +0400, Vsevolod Fedorov wrote: > I have the following problem when using Unix module: > > I issuing 'connect' for nonblocked-mode socket. > This can raise EINPROGRESS error meaning connect is not yet > complete. Then (as I taught by manuals) I use 'select' method and > then 'getsockopt_int sock SO_ERROR' to retreive connect results. > The problem is: 'getsockopt_int' returns 'int' while I need > Unix.error type. I can't map int to error in good way. > > Of couse, I can use some workarounds (and I had to use one), but > they all are not look good. I'm using the following piece of code as a work-around: begin try (* This succeeds only if the socket is connected *) ignore (Unix.getpeername fd) with Unix.Unix_error (Unix.ENOTCONN, _, _) -> (* This returns the right error message *) ignore (Unix.read fd " " 0 1)) end -- Jerome