Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Unix.send blocks
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Török_Edwin <edwintorok@g...>
Subject: Re: [Caml-list] Unix.send blocks
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,