--- a/src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java Thu Feb 08 11:44:21 2018 +0800
+++ b/src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java Thu Feb 08 10:55:21 2018 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,10 +25,22 @@
package sun.nio.ch;
-import java.io.*;
-import java.net.*;
-import java.nio.*;
-import java.nio.channels.*;
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.DatagramSocketImpl;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.NetworkInterface;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketOption;
+import java.net.SocketTimeoutException;
+import java.net.StandardSocketOptions;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.IllegalBlockingModeException;
// Make a datagram-socket channel look like a datagram socket.
@@ -178,7 +190,6 @@
dc.configureBlocking(false);
try {
- int n;
SocketAddress sender;
if ((sender = dc.receive(bb)) != null)
return sender;
@@ -188,19 +199,18 @@
throw new ClosedChannelException();
long st = System.currentTimeMillis();
int result = dc.poll(Net.POLLIN, to);
- if (result > 0 &&
- ((result & Net.POLLIN) != 0)) {
+ if (result > 0 && ((result & Net.POLLIN) != 0)) {
if ((sender = dc.receive(bb)) != null)
return sender;
}
to -= System.currentTimeMillis() - st;
if (to <= 0)
throw new SocketTimeoutException();
-
}
} finally {
- if (dc.isOpen())
+ try {
dc.configureBlocking(true);
+ } catch (ClosedChannelException e) { }
}
}