mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-15 17:30:24 +00:00
4981129: (dc) DatagramSocket created by DatagramChannel does not provide sender info
Reviewed-by: chegar
This commit is contained in:
parent
eadcba1cd9
commit
0b946fc36e
@ -171,10 +171,9 @@ public class DatagramSocketAdaptor
|
||||
|
||||
// Must hold dc.blockingLock()
|
||||
//
|
||||
private void receive(ByteBuffer bb) throws IOException {
|
||||
private SocketAddress receive(ByteBuffer bb) throws IOException {
|
||||
if (timeout == 0) {
|
||||
dc.receive(bb);
|
||||
return;
|
||||
return dc.receive(bb);
|
||||
}
|
||||
|
||||
// Implement timeout with a selector
|
||||
@ -183,8 +182,9 @@ public class DatagramSocketAdaptor
|
||||
dc.configureBlocking(false);
|
||||
try {
|
||||
int n;
|
||||
if (dc.receive(bb) != null)
|
||||
return;
|
||||
SocketAddress sender;
|
||||
if ((sender = dc.receive(bb)) != null)
|
||||
return sender;
|
||||
sel = Util.getTemporarySelector(dc);
|
||||
sk = dc.register(sel, SelectionKey.OP_READ);
|
||||
long to = timeout;
|
||||
@ -194,8 +194,8 @@ public class DatagramSocketAdaptor
|
||||
long st = System.currentTimeMillis();
|
||||
int ns = sel.select(to);
|
||||
if (ns > 0 && sk.isReadable()) {
|
||||
if (dc.receive(bb) != null)
|
||||
return;
|
||||
if ((sender = dc.receive(bb)) != null)
|
||||
return sender;
|
||||
}
|
||||
sel.selectedKeys().remove(sk);
|
||||
to -= System.currentTimeMillis() - st;
|
||||
@ -222,7 +222,8 @@ public class DatagramSocketAdaptor
|
||||
ByteBuffer bb = ByteBuffer.wrap(p.getData(),
|
||||
p.getOffset(),
|
||||
p.getLength());
|
||||
receive(bb);
|
||||
SocketAddress sender = receive(bb);
|
||||
p.setSocketAddress(sender);
|
||||
p.setLength(bb.position() - p.getOffset());
|
||||
}
|
||||
} catch (IOException x) {
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
/* @test
|
||||
* @bug 4313882 4981129
|
||||
* @summary Unit test for datagram-socket-channel adaptors
|
||||
* @library ..
|
||||
*/
|
||||
@ -93,6 +94,11 @@ public class AdaptDatagramSocket {
|
||||
if (ip.getData()[ip.getOffset() + i]
|
||||
!= op.getData()[op.getOffset() + i])
|
||||
throw new Exception("Incorrect data received");
|
||||
|
||||
if (!(ip.getSocketAddress().equals(dst))) {
|
||||
throw new Exception("Incorrect sender address, expected: " + dst
|
||||
+ " actual: " + ip.getSocketAddress());
|
||||
}
|
||||
}
|
||||
|
||||
static void test(InetSocketAddress dst,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user