mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8241072: Reimplement the Legacy DatagramSocket API
Replace the underlying implementations of the java.net.DatagramSocket and java.net.MulticastSocket APIs with simpler and more modern implementations that are easy to maintain and debug. Co-authored-by: Alan Bateman <alan.bateman@oracle.com> Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com> Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com> Reviewed-by: alanb, chegar, dfuchs
This commit is contained in:
parent
3930460af5
commit
fad2cf51ba
34 changed files with 1478 additions and 909 deletions
|
@ -74,7 +74,7 @@ public class DatagramSocketAdaptor
|
|||
private volatile int timeout;
|
||||
|
||||
private DatagramSocketAdaptor(DatagramChannelImpl dc) throws IOException {
|
||||
super(/*SocketAddress*/null);
|
||||
super(/*SocketAddress*/ DatagramSockets.NO_DELEGATE);
|
||||
this.dc = dc;
|
||||
}
|
||||
|
||||
|
@ -769,4 +769,24 @@ public class DatagramSocketAdaptor
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the value of the private static DatagramSocket.NO_DELEGATE
|
||||
*/
|
||||
private static class DatagramSockets {
|
||||
private static final SocketAddress NO_DELEGATE;
|
||||
|
||||
static {
|
||||
try {
|
||||
PrivilegedExceptionAction<Lookup> pa = () ->
|
||||
MethodHandles.privateLookupIn(DatagramSocket.class, MethodHandles.lookup());
|
||||
MethodHandles.Lookup l = AccessController.doPrivileged(pa);
|
||||
NO_DELEGATE = (SocketAddress)
|
||||
l.findStaticVarHandle(DatagramSocket.class, "NO_DELEGATE",
|
||||
SocketAddress.class).get();
|
||||
} catch (Exception e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue