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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 2C2A1BBAF for ; Wed, 16 Jun 2010 11:08:53 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArACABUxGEzRVaE0mGdsb2JhbACSXIwVCBUBAQEBAQgJDAcRIq8JggWFKS6ITwEBAwWFFQSDTQ X-IronPort-AV: E=Sophos;i="4.53,425,1272837600"; d="scan'208";a="61438648" Received: from mail-fx0-f52.google.com ([209.85.161.52]) by mail1-smtp-roc.national.inria.fr with ESMTP; 16 Jun 2010 11:08:52 +0200 Received: by fxm4 with SMTP id 4so3911869fxm.39 for ; Wed, 16 Jun 2010 02:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :x-enigmail-version:openpgp:content-type:content-transfer-encoding; bh=rT6GEl6A+NH39pzS86P/5V0/rGqw6/KBS+a5PjIvvOc=; b=Pqx3tbaHEIYogDsuBC3HmwK0fHS+gS8tqXeYUCpIhjTjd7XUw1gh7qyKRGXy8gXW1+ Au7eYn0toWnqWQaRxAwyRkCvB4U/rSBpa+DUAt1+md3VEHl/syANTv1/bkarHtL8WiKQ Fq4eLsLWu9lOAUDQNIUH2nm9bXZVWqJ1fMvoc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:openpgp:content-type :content-transfer-encoding; b=sRGfpb+d++2NYGVyIZa4KrU8J88fBpkV7PqSHpWmnLneNfZXqLt3QkYPHOnaCO9dhk aUlpVdJhgQlDEe4zQz1d81TPqOFQcyItwOe7NpS40UsM3ZsRHgOiuivSOrhvzTUIFbFy V1ouEYT0Pvz4eXR7XpS90H2DswPCLsGfPgWPw= Received: by 10.223.5.89 with SMTP id 25mr8685790fau.87.1276679332418; Wed, 16 Jun 2010 02:08:52 -0700 (PDT) Received: from debian ([79.114.65.73]) by mx.google.com with ESMTPS id u12sm17499494fah.4.2010.06.16.02.08.51 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 16 Jun 2010 02:08:51 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by debian (Postfix) with ESMTP id 689B526323 for ; Wed, 16 Jun 2010 12:08:50 +0300 (EEST) Message-ID: <4C1894A2.3020805@gmail.com> Date: Wed, 16 Jun 2010 12:08:50 +0300 From: =?ISO-8859-1?Q?T=F6r=F6k_Edwin?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100515 Icedove/3.0.4 MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Unix.send blocks References: <2EB36A07AAE8C44BBB1986425E7A22D0127E01BE32@atp-mbx1.in.nicta.com.au> In-Reply-To: <2EB36A07AAE8C44BBB1986425E7A22D0127E01BE32@atp-mbx1.in.nicta.com.au> X-Enigmail-Version: 1.0.1 OpenPGP: id=5379965D Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; steckler:01 ocaml:01 ocamlopt:01 mingw:01 ocaml:01 buffer:01 manpage:01 nonblock:01 buffered:01 edwin:98 queued:98 wrote:01 unix:01 unix:01 stack:01 On 06/16/2010 10:32 AM, Paul Steckler wrote: > I've written a wee Web server in OCaml that's compiled using the ocamlopt from the > Fedora MinGW distribution of ocaml. I'm running the server in Windows 7. > > Sometimes after receiving several requests, the Unix.send call that sends a response > back to a Web client just blocks. Why is a blocking send() a problem? Isn't your application multithreaded? > The send buffer is pretty large (64k), and the data > to be sent is always much less than that. >>From the manpage of send: "If space is not available at the sending socket to hold the message to be transmitted, and the socket file descriptor does not have O_NONBLOCK set, send() shall block until space is available." I think this occurs if the client has a slow/high latency connection, and it doesn't acknowledge the TCP packets in time. The packets you send are queued up in the kernel's TCP stack until they are acknowledged or time out. There is only a limited amount of data that can be buffered up like this per connection, when that is hit send() blocks. You could set the socket to nonblocking mode (and check with 'select' whether you can send), but according to the manual that doesn't work on the native windows port of OCaml. Best regards, --Edwin