Skip to content

Commit

Permalink
Fix: wrong assumption about buffer movement when splitting packets
Browse files Browse the repository at this point in the history
  • Loading branch information
unverbraucht committed Jan 24, 2024
1 parent 5b39e6f commit 084ae1d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ private Packet decode(ClientHead head, ByteBuf frame) throws IOException {

final int separatorPos = frame.bytesBefore((byte) 0x1E);
final ByteBuf packetBuf;
if (separatorPos != -1) {
if (separatorPos > 0) {
// Multiple packets in one, copy out the next packet to parse
packetBuf = frame.copy(frame.readerIndex(), separatorPos);
frame.readerIndex(separatorPos + 1);
frame.readerIndex(frame.readerIndex() + separatorPos + 1);
} else {
packetBuf = frame;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ public void testMultipleMessages() throws URISyntaxException, IOException, Inter
final ArrayList<String> events = new ArrayList<>();
events.add("420[\"hello\", \"world\"]");
events.add("421[\"hello\", \"socketio\"]");
events.add("422[\"hello\", \"socketio\"]");
postMessage(sessionId, events.stream().collect(Collectors.joining(packetSeparator)));
final String[] responses = pollForListOfResponses(sessionId);
Assert.assertEquals(responses.length, 2);
Assert.assertEquals(responses.length, 3);
}

/**
Expand Down

0 comments on commit 084ae1d

Please sign in to comment.