Re: Problem closing a socket while thread blocks in read()

From: Sean Burke (foobar_at_mystery.org)
Date: 03/02/04


Date: Tue, 02 Mar 2004 21:38:52 GMT


Joe Halpin <jhalpin@nortelnetworks.com_.nospam> writes:

> Peter Ammon <peter_ammon@rocketmail.com> writes:
>
> > I have a child thread that's blocking in a read() on a TCP socket. At
> > the same time, my main thread closes the socket via close(). When this
> > happens, read() never returns in the child thread and the socket is not
> > reported as closed to the other end until the program exits.
>
> I suspect that if the socket is already involved in a blocking read,
> the close won't get processed until the read returns something.
>
> Why would you do that though? If you want to timeout the read, why not
> put the select() in the reading thread?

On every unix I've used lately, closing a socket
while another thread is blocked in read will cause
that read call to return. Even shutdown() is enough
to cause blocked reads to return.

So either the OP is using an unusual unix, or the
term "child thread" actually means "child process".

-SEan



Relevant Pages