2002-07-18 16:37:40

by Kevin Curtis

[permalink] [raw]
Subject: Closing a socket

Hi,
I have implemented a new socket address family and have noted that
from a multi-threaded application, if a thread calls close(fd) while a
second thread has a blocking read outstanding, the sockets release() is not
called. Is this correct? How can one unblock the read in order to do the
close.


Thanks

Kevin


2002-07-18 18:00:44

by James Stevenson

[permalink] [raw]
Subject: Re: Closing a socket

Hi

either use non-blocking sockets
or send a signal to the other process
to make it exit from the read.

> I have implemented a new socket address family and have noted that
> from a multi-threaded application, if a thread calls close(fd) while a
> second thread has a blocking read outstanding, the sockets release() is
not
> called. Is this correct? How can one unblock the read in order to do the
> close.
>



2002-07-18 19:48:03

by Max Krasnyansky

[permalink] [raw]
Subject: Re: Closing a socket


> > I have implemented a new socket address family and have noted that
> > from a multi-threaded application, if a thread calls close(fd) while a
> > second thread has a blocking read outstanding, the sockets release() is not
> > called. Is this correct? How can one unblock the read in order to do the
> > close.
You might want to implement shutdown(). Thread #1 will call shutdown()
instead of
the close(). Your shutdown() implementation can do something like:
sk->shutdown |= RCV_SHUTDOWN;
sk->state_change(sk);
So, reader will wakeup, check shutdown mask and return error because socket was
shut down.

Max