}
void attemptReceive(long timeout, TimeUnit unit) throws SuspendExecution, InterruptedException, TimeoutException {
if (isClosed())
throw new EOFException();
final Condition sync = channel.sync;
final long start = System.nanoTime();
long left = unit.toNanos(timeout);
sync.register();
try {
for (int i = 0; !consumer.hasNext(); i++) {
if (channel.isSendClosed()) {
setReceiveClosed();
throw new EOFException();
}
sync.await(i, left, TimeUnit.NANOSECONDS);
left = start + unit.toNanos(timeout) - System.nanoTime();
if (left <= 0)
throw new TimeoutException();
}
consumer.poll0();
} finally {
sync.unregister();
}
}