{
resetWakeupSocket();
return 0;
}
ArrayList read = new ArrayList();
ArrayList write = new ArrayList();
ArrayList error = new ArrayList();
for (int i = 0; i < channelArray.get_Count(); i++)
{
SelectionKeyImpl ski = (SelectionKeyImpl)channelArray.get_Item(i);
int ops = ski.interestOps();
if (ski.channel() instanceof SocketChannelImpl)
{
// TODO there's a race condition here...
if (((SocketChannelImpl)ski.channel()).isConnected())
{
ops &= SelectionKey.OP_READ | SelectionKey.OP_WRITE;
}
else
{
ops &= SelectionKey.OP_CONNECT;
}
}
if ((ops & (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0)
{
read.Add(ski.getSocket());
}
if ((ops & (SelectionKey.OP_WRITE | SelectionKey.OP_CONNECT)) != 0)
{
write.Add(ski.getSocket());
}
if ((ops & SelectionKey.OP_CONNECT) != 0)
{
error.Add(ski.getSocket());
}
}
read.Add(wakeupSourceFd);
try
{
begin();
int microSeconds = 1000 * (int)Math.min(Integer.MAX_VALUE / 1000, timeout);
try
{
if (false) throw new SocketException();
// FXBUG docs say that -1 is infinite timeout, but that doesn't appear to work
Socket.Select(read, write, error, timeout < 0 ? Integer.MAX_VALUE : microSeconds);
}
catch (SocketException _)
{
read.Clear();
write.Clear();
error.Clear();
}
}
finally
{
end();