提交 b31257d1 编写于 作者: A alanb

4981129: (dc) DatagramSocket created by DatagramChannel does not provide sender info

Reviewed-by: chegar
上级 966fa731
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册