Re: select() ?

Alex Belits (abelits@phobos.illtel.denver.co.us)
Sun, 7 Nov 1999 22:50:06 -0800 (PST)


On Mon, 8 Nov 1999, wu_yb wrote:

> Now I accept a new socket, such as sk = 19,
> In thread 3, I detect a condition, and close(19), then I connect server
> again, accept() return 19 (Now 19 is a free file slot).
>
> But in thread2, the select() return, and read(19) return -1, errno is
> "Bad file number".
> It seem that after select(), thread 2 only know 19 is closed, but don't
> know
> a new 19 is open. ( I connect server about 1min after close a previous
> socket,
> so select() return 1 min after 19 is closed ).
>
> Can any one help me !

You can't select() on file descriptor that is closed -- it has to be
finished and called again when new fd is accepted. I recommend to
never split such things between threads (close in the same thread where
you do select()). You can use a pipe between thread that did close() and
thread that does select() to notify thread with select() when fd is
supposed to be closed. Pipe's read fd should be in select() set for read,
so select() will finish after receiving anything from it, select() thread
will close the fd by itself and go into select() again.

In general it's easier to split such things between processes instead
of threads.

-- 
Alex

---------------------------------------------------------------------- Excellent.. now give users the option to cut your hair you hippie! -- Anonymous Coward

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/