2002-10-30 12:38:35

by Miquel van Smoorenburg

[permalink] [raw]
Subject: Re: TCP hangs in 2.4 - blocking write() in wait_for_tcp_memory

In article <[email protected]>,
bert hubert <[email protected]> wrote:
>On Wed, Oct 30, 2002 at 10:44:20AM +0000, Miquel van Smoorenburg wrote:
>
>> This makes both socket programs hang in write(), in wait_for_tcp_memory.
>> Shouldn't the kernel return a short write, instead of hanging
>> both processes ? select() returned writeability.
>
>write(2) is allowed to do a short write on a blocking socket, but not
>mandated to do so. In fact I've only seen short writes under
>linux on non-blocking sockets.
>
>SuSv3 says:

Ah, that's interesting:

> Blocking/immediate: Blocking is only possible with O_NONBLOCK clear. If
> there is enough space for all the data requested to be written immediately,
> the implementation should do so. Otherwise, the process may block; that is,

Okay, _may_ block. That's what I needed to know. So it's not a kernel
bug, but a bug in applications like socket(1) and nc(1).

With squid I see corrupted downloads, that probably means squid does
use non-blocking sockets but doesn't handle short writes correctly.

> Partial and deferred writes are only possible with O_NONBLOCK set.

Thanks for the clarification.

Now I must go fix all those programs :/

Mike.