Committed by
Gerrit Code Review
Process protocol message read partially from the buffer.
Change-Id: I1888dce82bea566796bc222329650582cba5a276
Showing
1 changed file
with
20 additions
and
6 deletions
... | @@ -48,13 +48,27 @@ public class BgpMessageDecoder extends FrameDecoder { | ... | @@ -48,13 +48,27 @@ public class BgpMessageDecoder extends FrameDecoder { |
48 | HexDump.dump(buffer); | 48 | HexDump.dump(buffer); |
49 | 49 | ||
50 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); | 50 | BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); |
51 | - List<BgpMessage> msgList = new LinkedList<BgpMessage>(); | 51 | + List<BgpMessage> msgList = (List<BgpMessage>) ctx.getAttachment(); |
52 | 52 | ||
53 | - while (buffer.readableBytes() > 0) { | 53 | + if (msgList == null) { |
54 | - BgpHeader bgpHeader = new BgpHeader(); | 54 | + msgList = new LinkedList<>(); |
55 | - BgpMessage message = reader.readFrom(buffer, bgpHeader); | ||
56 | - msgList.add(message); | ||
57 | } | 55 | } |
58 | - return msgList; | 56 | + |
57 | + try { | ||
58 | + while (buffer.readableBytes() > 0) { | ||
59 | + buffer.markReaderIndex(); | ||
60 | + BgpHeader bgpHeader = new BgpHeader(); | ||
61 | + BgpMessage message = reader.readFrom(buffer, bgpHeader); | ||
62 | + msgList.add(message); | ||
63 | + } | ||
64 | + | ||
65 | + return msgList; | ||
66 | + } catch (Exception e) { | ||
67 | + log.debug("Bgp protocol message decode error"); | ||
68 | + buffer.resetReaderIndex(); | ||
69 | + buffer.discardReadBytes(); | ||
70 | + ctx.setAttachment(msgList); | ||
71 | + } | ||
72 | + return null; | ||
59 | } | 73 | } |
60 | } | 74 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment