On Sun, May 20, 2007 at 07:48:11PM -0700, David Daney wrote:
It is not socket or java specific. I think of it as a defect in Posix
(reuse of the lowest numbered descriptor possible).
Perhaps exacerbated by POSIX. Unless handles are guaranteed to be
unique throughout the existence of a process, any reduction in re-use
would only narrow the window. It would not eliminate it. Consider the
old malloc() implementation that would purposefully not re-use
recently free()d memory. This allowed people to write code that would
continue to use memory after it had been free()d. Good, or bad? The
same would be true of allowing people to use file descriptors after
they have been closed.
In any case - I appreciated your suggested solution. The dup2() to
perform a close of the socket was clever, leaving a garbage file
descriptor in its place. Still, the overhead appears to be high as
you noted.