Fix heap corruption in nio select(2) code.
The active ingredient in this change is that we now test that the fd isn't -1,
used to represent an invalid fd. There's a race condition where a socket can be
closed between SelectorImpl.prepareChannels and the native code. This caused us
to write to the -1th element of a heap-allocated structure, leading to SIGSEGV.
I've also removed the check for an empty fd_set. It was broken before and will
never have fired, but I don't think it makes sense to fix it, given this race
condition.
The race can't be fixed because the implementation is documented to close the
socket channel and *then* cancel the selection key.
This patch also removes various dead functions and tidies up timeval usage.
Bug:
2093094