提交 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 ...@@ -171,10 +171,9 @@ public class DatagramSocketAdaptor
// Must hold dc.blockingLock() // Must hold dc.blockingLock()
// //
private void receive(ByteBuffer bb) throws IOException { private SocketAddress receive(ByteBuffer bb) throws IOException {
if (timeout == 0) { if (timeout == 0) {
dc.receive(bb); return dc.receive(bb);
return;
} }
// Implement timeout with a selector // Implement timeout with a selector
...@@ -183,8 +182,9 @@ public class DatagramSocketAdaptor ...@@ -183,8 +182,9 @@ public class DatagramSocketAdaptor
dc.configureBlocking(false); dc.configureBlocking(false);
try { try {
int n; int n;
if (dc.receive(bb) != null) SocketAddress sender;
return; if ((sender = dc.receive(bb)) != null)
return sender;
sel = Util.getTemporarySelector(dc); sel = Util.getTemporarySelector(dc);
sk = dc.register(sel, SelectionKey.OP_READ); sk = dc.register(sel, SelectionKey.OP_READ);
long to = timeout; long to = timeout;
...@@ -194,8 +194,8 @@ public class DatagramSocketAdaptor ...@@ -194,8 +194,8 @@ public class DatagramSocketAdaptor
long st = System.currentTimeMillis(); long st = System.currentTimeMillis();
int ns = sel.select(to); int ns = sel.select(to);
if (ns > 0 && sk.isReadable()) { if (ns > 0 && sk.isReadable()) {
if (dc.receive(bb) != null) if ((sender = dc.receive(bb)) != null)
return; return sender;
} }
sel.selectedKeys().remove(sk); sel.selectedKeys().remove(sk);
to -= System.currentTimeMillis() - st; to -= System.currentTimeMillis() - st;
...@@ -222,7 +222,8 @@ public class DatagramSocketAdaptor ...@@ -222,7 +222,8 @@ public class DatagramSocketAdaptor
ByteBuffer bb = ByteBuffer.wrap(p.getData(), ByteBuffer bb = ByteBuffer.wrap(p.getData(),
p.getOffset(), p.getOffset(),
p.getLength()); p.getLength());
receive(bb); SocketAddress sender = receive(bb);
p.setSocketAddress(sender);
p.setLength(bb.position() - p.getOffset()); p.setLength(bb.position() - p.getOffset());
} }
} catch (IOException x) { } catch (IOException x) {
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
*/ */
/* @test /* @test
* @bug 4313882 4981129
* @summary Unit test for datagram-socket-channel adaptors * @summary Unit test for datagram-socket-channel adaptors
* @library .. * @library ..
*/ */
...@@ -93,6 +94,11 @@ public class AdaptDatagramSocket { ...@@ -93,6 +94,11 @@ public class AdaptDatagramSocket {
if (ip.getData()[ip.getOffset() + i] if (ip.getData()[ip.getOffset() + i]
!= op.getData()[op.getOffset() + i]) != op.getData()[op.getOffset() + i])
throw new Exception("Incorrect data received"); 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, static void test(InetSocketAddress dst,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册