< prev index next >
src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java
Print this page
rev 48757 : [mq]: nio-cleanup
*** 1,7 ****
/*
! * Copyright (c) 2001, 2012, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 23,36 ****
* questions.
*/
package sun.nio.ch;
! import java.io.*;
! import java.net.*;
! import java.nio.*;
! import java.nio.channels.*;
// Make a datagram-socket channel look like a datagram socket.
//
// The methods in this class are defined in exactly the same order as in
--- 23,48 ----
* questions.
*/
package sun.nio.ch;
! 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.
//
// The methods in this class are defined in exactly the same order as in
*** 176,208 ****
return dc.receive(bb);
}
dc.configureBlocking(false);
try {
- int n;
SocketAddress sender;
if ((sender = dc.receive(bb)) != null)
return sender;
long to = timeout;
for (;;) {
if (!dc.isOpen())
throw new ClosedChannelException();
long st = System.currentTimeMillis();
int result = dc.poll(Net.POLLIN, to);
! 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())
dc.configureBlocking(true);
}
}
public void receive(DatagramPacket p) throws IOException {
synchronized (dc.blockingLock()) {
--- 188,218 ----
return dc.receive(bb);
}
dc.configureBlocking(false);
try {
SocketAddress sender;
if ((sender = dc.receive(bb)) != null)
return sender;
long to = timeout;
for (;;) {
if (!dc.isOpen())
throw new ClosedChannelException();
long st = System.currentTimeMillis();
int result = dc.poll(Net.POLLIN, to);
! 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 {
! try {
dc.configureBlocking(true);
+ } catch (ClosedChannelException e) { }
}
}
public void receive(DatagramPacket p) throws IOException {
synchronized (dc.blockingLock()) {
< prev index next >