< prev index next >
src/java.base/share/classes/sun/nio/ch/DatagramChannelImpl.java
Print this page
rev 48757 : [mq]: nio-cleanup
@@ -68,13 +68,10 @@
// Used to make native read and write calls
private static NativeDispatcher nd = new DatagramDispatcher();
// Our file descriptor
private final FileDescriptor fd;
-
- // fd value needed for dev/poll. This value will remain valid
- // even after the value in the file descriptor object has been set to -1
private final int fdVal;
// The protocol family of the socket
private final ProtocolFamily family;
@@ -122,11 +119,10 @@
// set true/false when socket is already bound and SO_REUSEADDR is emulated
private boolean isReuseAddress;
// -- End of fields protected by stateLock
-
public DatagramChannelImpl(SelectorProvider sp)
throws IOException
{
super(sp);
ResourceManager.beforeUdpCreate();
@@ -157,20 +153,31 @@
if (family == StandardProtocolFamily.INET6) {
if (!Net.isIPv6Available()) {
throw new UnsupportedOperationException("IPv6 not available");
}
}
+
+ ResourceManager.beforeUdpCreate();
+ try {
this.family = family;
this.fd = Net.socket(family, false);
this.fdVal = IOUtil.fdVal(fd);
this.state = ST_UNCONNECTED;
+ } catch (IOException ioe) {
+ ResourceManager.afterUdpClose();
+ throw ioe;
+ }
}
public DatagramChannelImpl(SelectorProvider sp, FileDescriptor fd)
throws IOException
{
super(sp);
+
+ // increment UDP count to match decrement when closing
+ ResourceManager.beforeUdpCreate();
+
this.family = Net.isIPv6Available() ?
StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;
this.fd = fd;
this.fdVal = IOUtil.fdVal(fd);
this.state = ST_UNCONNECTED;
@@ -788,14 +795,13 @@
// set or refresh local address
localAddress = Net.localAddress(fd);
// flush any packets already received.
- boolean blocking = false;
synchronized (blockingLock()) {
+ boolean blocking = isBlocking();
try {
- blocking = isBlocking();
ByteBuffer tmpBuf = ByteBuffer.allocate(100);
if (blocking) {
configureBlocking(false);
}
do {
< prev index next >