From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id D52187ED92 for ; Fri, 14 Sep 2012 17:26:03 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of romain.bardou@inria.fr) identity=pra; client-ip=178.33.109.111; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="romain.bardou@inria.fr"; x-sender="romain.bardou@inria.fr"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of romain.bardou@inria.fr) identity=mailfrom; client-ip=178.33.109.111; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="romain.bardou@inria.fr"; x-sender="romain.bardou@inria.fr"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mo5.mail-out.ovh.net) identity=helo; client-ip=178.33.109.111; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="romain.bardou@inria.fr"; x-sender="postmaster@mo5.mail-out.ovh.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoMBAARMU1CyIW1vnGdsb2JhbABFvB8BAQEBAQgLCQkUJ4IgAQEFDCYBBUABEAsYCRYPCQMCAQIBRQYNAQUCAogJBLtZixWGaAOVYYYCjQc X-IronPort-AV: E=Sophos;i="4.80,423,1344204000"; d="scan'208";a="173229567" Received: from 2.mo5.mail-out.ovh.net (HELO mo5.mail-out.ovh.net) ([178.33.109.111]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Sep 2012 17:26:03 +0200 Received: from mail30.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with SMTP id E9D5FFFAE77 for ; Fri, 14 Sep 2012 17:31:41 +0200 (CEST) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 14 Sep 2012 17:26:02 +0200 Received: from unknown (HELO ?138.231.81.39?) (romain%bardou.fr@138.231.81.39) by ns0.ovh.net with SMTP; 14 Sep 2012 17:26:00 +0200 Message-ID: <50534CBF.4080608@inria.fr> Date: Fri, 14 Sep 2012 17:26:55 +0200 From: Romain Bardou User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.6esrpre) Gecko/20120817 Icedove/10.0.6 MIME-Version: 1.0 To: Jerome Vouillon CC: caml-list@inria.fr, =?ISO-8859-1?Q?J=E9r=E9mie_Dimino?= X-Ovh-Mailout: 178.32.228.5 (mo5.mail-out.ovh.net) References: <505336D4.7010700@inria.fr> <20120914162717.0527b04b@arrakis> <20120914152125.GA18300@pps.jussieu.fr> In-Reply-To: <20120914152125.GA18300@pps.jussieu.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Ovh-Tracer-Id: 5514657744252603032 X-Ovh-Remote: 138.231.81.39 () X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: -100 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehtddrieehucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfhrhhomheptfhomhgrihhnuceurghrughouhcuoehrohhmrghinhdrsggrrhguohhusehinhhrihgrrdhfrheqnecujfgurhepkfffhfgfggfvufhfjggtgfesthekrgdttdefud X-Spam-Check: DONE|U 0.5/N X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehtddrieeiucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfhrhhomheptfhomhgrihhnuceurghrughouhcuoehrohhmrghinhdrsggrrhguohhusehinhhrihgrrdhfrheqnecujfgurhepkfffhfgfggfvufhfjggtgfesthekrgdttdefud X-Validation-by: romain.bardou@inria.fr Subject: Re: [Caml-list] Unix.connect for non-blocking sockets on Windows Le 14/09/2012 17:21, Jerome Vouillon a écrit : > 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. Oh so actually it's even easier than I thought. From what you're saying I just need to treat the EWOULDBLOCK case as if it was EINPROGRESS (which is what is returned by connect on Linux) and the rest is the same. Thanks to both of you! -- Romain Bardou