1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-17 17:52:06 +01:00

[tcp] Add code comment why we have to copy the ByteBuffer

This commit is contained in:
Florian Schmaus 2020-09-20 13:11:29 +02:00
parent 08fc0ba0b4
commit 4db7d787f7

View file

@ -1030,12 +1030,15 @@ public class XmppTcpTransportModule extends ModularXmppClientToServerConnectionM
}
}
@SuppressWarnings("ReferenceEquality")
@Override
public ByteBuffer input(ByteBuffer inputData) throws SSLException {
ByteBuffer accumulatedData;
if (pendingInputData == null) {
accumulatedData = inputData;
} else {
assert pendingInputData != inputData;
int accumulatedDataBytes = pendingInputData.remaining() + inputData.remaining();
accumulatedData = ByteBuffer.allocate(accumulatedDataBytes);
accumulatedData.put(pendingInputData)
@ -1116,9 +1119,11 @@ public class XmppTcpTransportModule extends ModularXmppClientToServerConnectionM
}
private void addAsPendingInputData(ByteBuffer byteBuffer) {
// TODO: Why doeesn't simply
// Note that we can not simply write
// pendingInputData = byteBuffer;
// work?
// we have to copy the provided byte buffer, because it is possible that this byteBuffer is re-used by some
// higher layer. That is, here 'byteBuffer' is typically 'incomingBuffer', which is a direct buffer only
// allocated once per connection for performance reasons and hence re-used for read() calls.
pendingInputData = ByteBuffer.allocate(byteBuffer.remaining());
pendingInputData.put(byteBuffer).flip();