8338142: (dc) DatagramChannelImpl.blockingReceive can use untimed-park when no timeout set

Reviewed-by: dfuchs
This commit is contained in:
Alan Bateman 2024-08-13 16:05:38 +00:00
parent 6af1d6ff21
commit 58b9570544

View file

@ -674,7 +674,6 @@ class DatagramChannelImpl
configureSocketNonBlocking();
} else {
configureSocketNonBlockingIfVirtualThread();
nanos = Long.MAX_VALUE;
}
// p.bufLength is the maximum size of the datagram that can be received
@ -689,7 +688,9 @@ class DatagramChannelImpl
SocketAddress remote = beginRead(true, false);
boolean connected = (remote != null);
do {
long remainingNanos = nanos - (System.nanoTime() - startNanos);
long remainingNanos = (nanos > 0)
? nanos - (System.nanoTime() - startNanos)
: 0;
ByteBuffer dst = tryBlockingReceive(connected, bufLength, remainingNanos);
// if datagram received then get sender and copy to DatagramPacket
@ -756,11 +757,15 @@ class DatagramChannelImpl
Util.offerFirstTemporaryDirectBuffer(dst);
dst = null;
}
long remainingNanos = nanos - (System.nanoTime() - startNanos);
if (remainingNanos <= 0) {
throw new SocketTimeoutException("Receive timed out");
if (nanos > 0) {
long remainingNanos = nanos - (System.nanoTime() - startNanos);
if (remainingNanos <= 0) {
throw new SocketTimeoutException("Receive timed out");
}
park(Net.POLLIN, remainingNanos);
} else {
park(Net.POLLIN);
}
park(Net.POLLIN, remainingNanos);
// virtual thread needs to re-allocate temporary direct buffer after parking
if (Thread.currentThread().isVirtual()) {
dst = Util.getTemporaryDirectBuffer(len);