elecharny commented on PR #28:
URL: https://github.com/apache/mina/pull/28#issuecomment-4568284811
Checking the {{CumulativeProtocolDecoder}} again, the code is under
optimal...
Here what I suggest:
```
diff --git
a/mina-core/src/main/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
b/mina-core/src/main/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
index 2750a1b44..7283d4b84 100644
---
a/mina-core/src/main/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
+++
b/mina-core/src/main/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java
@@ -142,20 +142,15 @@ public abstract class CumulativeProtocolDecoder
extends ProtocolDecoderAdapter {
// If we have a session buffer, append data to that; otherwise
// use the buffer read from the network directly.
if (buf != null) {
- boolean appended = false;
// Make sure that the buffer is auto-expanded.
if (buf.isAutoExpand()) {
try {
buf.put(in);
- appended = true;
+ buf.flip();
} catch (IllegalStateException | IndexOutOfBoundsException
e) {
// A user called derivation method (e.g. slice()),
// which disables auto-expansion of the parent buffer.
}
- }
-
- if (appended) {
- buf.flip();
} else {
// Reallocate the buffer if append operation failed due to
// derivation or disabled auto-expansion.
@@ -232,14 +227,14 @@ public abstract class CumulativeProtocolDecoder
extends ProtocolDecoderAdapter {
@Override
public void dispose(IoSession session) throws Exception {
IoBuffer oldBuf = (IoBuffer) session.removeAttribute(BUFFER);
-
+
if (oldBuf != null) {
oldBuf.free();
}
}
private void removeSessionBuffer(IoSession session) {
- IoBuffer oldBuf = (IoBuffer) session.getAttribute(BUFFER);
+ IoBuffer oldBuf = (IoBuffer) session.removeAttribute(BUFFER);
if (oldBuf != null) {
oldBuf.free();
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]