< prev index next >

src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java

Print this page
@@ -24,10 +24,11 @@
   */
  
  package sun.nio.ch;
  
  import java.io.IOException;
+ import java.io.InterruptedIOException;
  import java.io.UncheckedIOException;
  import java.lang.invoke.MethodHandle;
  import java.lang.invoke.MethodHandles;
  import java.lang.invoke.MethodHandles.Lookup;
  import java.lang.invoke.MethodType;

@@ -39,10 +40,11 @@
  import java.net.NetworkInterface;
  import java.net.MulticastSocket;
  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.AlreadyConnectedException;
  import java.nio.channels.ClosedChannelException;
  import java.nio.channels.DatagramChannel;

@@ -246,10 +248,19 @@
                  DatagramPackets.setLength(p, len);
  
                  // sender address
                  p.setSocketAddress(sender);
              }
+         } catch (SocketTimeoutException e) {
+             throw e;
+         } catch (InterruptedIOException e) {
+             Thread thread = Thread.currentThread();
+             if (thread.isVirtual() && thread.isInterrupted()) {
+                 close();
+                 throw new SocketException("Closed by interrupt");
+             }
+             throw e;
          } catch (ClosedChannelException e) {
              var exc = new SocketException("Socket closed");
              exc.initCause(e);
              throw exc;
          } finally {

@@ -776,25 +787,23 @@
              }
          }
      }
  
      /**
-      * Provides access to the value of the private static DatagramSocket.NO_DELEGATE
+      * Provides access to non-public constants in DatagramSocket.
       */
      private static class DatagramSockets {
          private static final SocketAddress NO_DELEGATE;
- 
          static {
              try {
                  PrivilegedExceptionAction<Lookup> pa = () ->
-                         MethodHandles.privateLookupIn(DatagramSocket.class, MethodHandles.lookup());
+                     MethodHandles.privateLookupIn(DatagramSocket.class, MethodHandles.lookup());
                  @SuppressWarnings("removal")
                  MethodHandles.Lookup l = AccessController.doPrivileged(pa);
-                 NO_DELEGATE = (SocketAddress)
-                         l.findStaticVarHandle(DatagramSocket.class, "NO_DELEGATE",
-                                 SocketAddress.class).get();
+                 var handle = l.findStaticVarHandle(DatagramSocket.class, "NO_DELEGATE", SocketAddress.class);
+                 NO_DELEGATE = (SocketAddress) handle.get();
              } catch (Exception e) {
                  throw new ExceptionInInitializerError(e);
              }
          }
      }
- }
+ }
< prev index next >