Bill commented on a change in pull request #5666:
URL: https://github.com/apache/geode/pull/5666#discussion_r512967980
##########
File path:
geode-core/src/main/java/org/apache/geode/internal/net/NioSslEngine.java
##########
@@ -315,50 +317,48 @@ public ByteBuffer ensureWrappedCapacity(int amount,
ByteBuffer wrappedBuffer,
}
@Override
- public ByteBuffer readAtLeast(SocketChannel channel, int bytes,
+ public ByteBufferSharing readAtLeast(SocketChannel channel, int bytes,
ByteBuffer wrappedBuffer) throws IOException {
- if (peerAppData.capacity() > bytes) {
- // we already have a buffer that's big enough
- if (peerAppData.capacity() - peerAppData.position() < bytes) {
- peerAppData.compact();
- peerAppData.flip();
- }
- }
+ try (final ByteBufferSharing inputSharing = shareInputBuffer()) {
- while (peerAppData.remaining() < bytes) {
- wrappedBuffer.limit(wrappedBuffer.capacity());
- int amountRead = channel.read(wrappedBuffer);
- if (amountRead < 0) {
- throw new EOFException();
+ ByteBuffer peerAppData = inputSharing.getBuffer();
+
+ if (peerAppData.capacity() > bytes) {
+ // we already have a buffer that's big enough
+ if (peerAppData.capacity() - peerAppData.position() < bytes) {
+ peerAppData.compact();
+ peerAppData.flip();
+ }
}
- if (amountRead > 0) {
- wrappedBuffer.flip();
- // prep the decoded buffer for writing
- peerAppData.compact();
- peerAppData = unwrap(wrappedBuffer);
- // done writing to the decoded buffer - prep it for reading again
- peerAppData.flip();
+
+ while (peerAppData.remaining() < bytes) {
+ wrappedBuffer.limit(wrappedBuffer.capacity());
+ int amountRead = channel.read(wrappedBuffer);
+ if (amountRead < 0) {
+ throw new EOFException();
+ }
+ if (amountRead > 0) {
+ wrappedBuffer.flip();
+ // prep the decoded buffer for writing
+ peerAppData.compact();
+ try (final ByteBufferSharing inputSharing2 = unwrap(wrappedBuffer)) {
+ // done writing to the decoded buffer - prep it for reading again
+ final ByteBuffer peerAppDataNew = inputSharing2.getBuffer();
+ peerAppDataNew.flip();
+ peerAppData = peerAppDataNew; // loop needs new reference!
+ }
+ }
}
+ return shareInputBuffer();
}
- return peerAppData;
}
@Override
- public ByteBuffer getUnwrappedBuffer(ByteBuffer wrappedBuffer) {
- return peerAppData;
- }
-
- /**
- * ensures that the unwrapped buffer associated with the given wrapped
buffer has
- * sufficient capacity for the given amount of bytes. This may compact the
- * buffer or it may return a new buffer.
- */
- public ByteBuffer ensureUnwrappedCapacity(int amount) {
- // for TTLS the app-data buffers do not need to be tracked direct-buffers
since we
- // do not use them for I/O operations
- peerAppData =
- bufferPool.expandReadBufferIfNeeded(TRACKED_RECEIVER, peerAppData,
amount);
- return peerAppData;
+ public ByteBufferSharing getUnwrappedBuffer(ByteBuffer wrappedBuffer) {
+ /*
+ * TODO: it can't be right that we ignore the wrappedBuffer parameter here!
Review comment:
Resolved and removed. We eliminated the parameter entirely.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]