From 077823f76da889e36312b6a6bb67241ac1753a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=91=E5=99=A8=E8=BF=91?= Date: Wed, 23 Dec 2020 18:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DDelimiterBasedFrameDecoder?= =?UTF-8?q?=E4=B8=AD=E4=BF=9D=E7=95=99=E5=88=86=E9=9A=94=E7=AC=A6=E4=BA=A7?= =?UTF-8?q?=E7=94=9F=E7=9A=84=E7=A9=BA=E6=8A=A5=E6=96=87,=E4=BF=AE?= =?UTF-8?q?=E6=94=B9exceptionCaught=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/github/yezhihao/netmc/TCPServerHandler.java | 2 +- .../yezhihao/netmc/codec/DelimiterBasedFrameDecoder.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/yezhihao/netmc/TCPServerHandler.java b/src/main/java/io/github/yezhihao/netmc/TCPServerHandler.java index 27acb1d..e788f28 100644 --- a/src/main/java/io/github/yezhihao/netmc/TCPServerHandler.java +++ b/src/main/java/io/github/yezhihao/netmc/TCPServerHandler.java @@ -90,7 +90,7 @@ public class TCPServerHandler extends ChannelInboundHandlerAdapter { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) { Session session = ctx.channel().attr(Session.KEY).get(); - log.warn("<<<<<异常断开连接" + session, e); + log.warn("<<<<<消息处理异常" + session, e); } @Override diff --git a/src/main/java/io/github/yezhihao/netmc/codec/DelimiterBasedFrameDecoder.java b/src/main/java/io/github/yezhihao/netmc/codec/DelimiterBasedFrameDecoder.java index 0696a4b..36baeae 100644 --- a/src/main/java/io/github/yezhihao/netmc/codec/DelimiterBasedFrameDecoder.java +++ b/src/main/java/io/github/yezhihao/netmc/codec/DelimiterBasedFrameDecoder.java @@ -84,7 +84,11 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder { } buffer.skipBytes(minDelimLength); } else { - frame = buffer.readRetainedSlice(minFrameLength + minDelimLength); + if (minFrameLength != 0) { + frame = buffer.readRetainedSlice(minFrameLength + minDelimLength); + } else { + buffer.skipBytes(minDelimLength); + } } return frame;