Ensure we null out the previous set InetAddress on java.net.DatagramPacket when using OioDatagramChannel.

Motivation:

We need to ensure we always null out (or set) the address on the java.net.DatagramPacket when doing read or write operation as the same instance is used across different calls.

Modifications:

Null out the address if needed.

Result:

Ensure the correct remote address is used when connect / disconnect between calls and also mix these with calls that directly specify the remote address for adatagram packets.
This commit is contained in:
Norman Maurer 2017-08-08 09:19:03 +02:00
parent fc0acefe30
commit e4c85537ae

View File

@ -216,6 +216,8 @@ public class OioDatagramChannel extends AbstractOioMessageChannel
ByteBuf data = config.getAllocator().heapBuffer(allocHandle.guess());
boolean free = true;
try {
// Ensure we null out the address which may have been set before.
tmpPacket.setAddress(null);
tmpPacket.setData(data.array(), data.arrayOffset(), data.capacity());
socket.receive(tmpPacket);
@ -274,6 +276,8 @@ public class OioDatagramChannel extends AbstractOioMessageChannel
// NioDatagramChannel
throw new NotYetConnectedException();
}
// Ensure we null out the address which may have been set before.
tmpPacket.setAddress(null);
}
if (data.hasArray()) {
tmpPacket.setData(data.array(), data.arrayOffset() + data.readerIndex(), length);