From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id BC02C7ED7A for ; Fri, 14 Sep 2012 17:21:54 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of Jerome.Vouillon@pps.jussieu.fr) identity=pra; client-ip=134.157.0.129; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="Jerome.Vouillon@pps.jussieu.fr"; x-sender="Jerome.Vouillon@pps.jussieu.fr"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of Jerome.Vouillon@pps.jussieu.fr) identity=mailfrom; client-ip=134.157.0.129; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="Jerome.Vouillon@pps.jussieu.fr"; x-sender="Jerome.Vouillon@pps.jussieu.fr"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@shiva.jussieu.fr) identity=helo; client-ip=134.157.0.129; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="Jerome.Vouillon@pps.jussieu.fr"; x-sender="postmaster@shiva.jussieu.fr"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlABAApLU1CGnQCBkWdsb2JhbABFi1uwIiIBAQEBCQsLBxQDJIIgAQEFDCYBICYQCxguFEkTiA27XosVhghgA5Vgkwo X-IronPort-AV: E=Sophos;i="4.80,423,1344204000"; d="scan'208";a="155776962" Received: from shiva.jussieu.fr ([134.157.0.129]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Sep 2012 17:21:54 +0200 Received: from hydrogene.pps.jussieu.fr (hydrogene.pps.jussieu.fr [134.157.168.1]) by shiva.jussieu.fr (8.14.4/jtpda-5.4) with ESMTP id q8EFLQPH011722 ; Fri, 14 Sep 2012 17:21:40 +0200 (CEST) X-Ids:168 Received: from strontium.pps.jussieu.fr (strontium.pps.jussieu.fr [134.157.168.38]) by hydrogene.pps.jussieu.fr (Postfix) with ESMTPS id EC663C0F63; Fri, 14 Sep 2012 17:21:25 +0200 (CEST) Received: from vouillon by strontium.pps.jussieu.fr with local (Exim 4.77) (envelope-from ) id 1TCXht-0004nt-PC; Fri, 14 Sep 2012 17:21:25 +0200 Date: Fri, 14 Sep 2012 17:21:25 +0200 From: Jerome Vouillon To: Romain Bardou Cc: caml-list@inria.fr, =?iso-8859-1?Q?J=E9r=E9mie?= Dimino Message-ID: <20120914152125.GA18300@pps.jussieu.fr> References: <505336D4.7010700@inria.fr> <20120914162717.0527b04b@arrakis> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20120914162717.0527b04b@arrakis> User-Agent: Mutt/1.5.21 (2010-09-15) X-Miltered: at jchkmail.jussieu.fr with ID 50534B77.001 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-j-chkmail-Enveloppe: 50534B77.001/134.157.168.1/hydrogene.pps.jussieu.fr/hydrogene.pps.jussieu.fr/ X-Validation-by: jerome.vouillon@pps.jussieu.fr Subject: Re: [Caml-list] Unix.connect for non-blocking sockets on Windows Hi Jérémie, On Fri, Sep 14, 2012 at 04:27:17PM +0200, Jérémie Dimino wrote: > Le Fri, 14 Sep 2012 15:53:24 +0200, > Romain Bardou a écrit : > > > open Unix > > let address = "xxx.xxx.xxx.xxx" in (* some IP for IPv4 *) > > let port = 9543 in > > let fd = socket PF_INET SOCK_STREAM 0 in > > set_nonblock fd; > > connect fd (ADDR_INET (Unix.inet_addr_of_string address, port)) > > If the socket is in non-blocking mode and connect blocks, then you get > a Unix.EWOULDBLOCK error. According to the MSDN documentation, if > connect fails with EWOULDBLOCK, you have to wait for the socket to > become writeable then call connect again which will fail with EISCONN > if the connection succeeded. This is not quite what I can read in the MSDN documentation... "[...] it is not recommended that applications use multiple calls to connect to detect connection completion. If they do, they must be prepared to handle WSAEINVAL and WSAEWOULDBLOCK error values the same way that they handle WSAEALREADY, to assure robust operation" You should use Unix.getsockopt_error (just like under Unix) to check for errors when the socket becomes writable, rather than call connect again. -- Jérôme