提交 47ecaf05 编写于 作者: 如梦技术's avatar 如梦技术 🐛 提交者: Gitee

!1 修正一处粘包时可能产生的错误

Merge pull request !1 from talent-tan/master
......@@ -46,9 +46,9 @@ public final class MqttDecoder {
this.maxBytesInMessage = maxBytesInMessage;
}
public MqttMessage decode(ChannelContext ctx, ByteBuffer buffer) {
public MqttMessage decode(ChannelContext ctx, ByteBuffer buffer, int limit, int position, int readableLength) {
// 1. 首先判断缓存中协议头是否读完(MQTT协议头为2字节)
if (buffer.limit() < MQTT_PROTOCOL_LENGTH) {
if (readableLength < MQTT_PROTOCOL_LENGTH) {
return null;
}
// 2. 解析 FixedHeader
......
......@@ -52,7 +52,7 @@ public class MqttClientAioHandler implements ClientAioHandler {
@Override
public Packet decode(ByteBuffer buffer, int limit, int position, int readableLength, ChannelContext channelContext) throws AioDecodeException {
return mqttDecoder.decode(channelContext, buffer);
return mqttDecoder.decode(channelContext, buffer, limit, position, readableLength);
}
@Override
......
......@@ -59,7 +59,7 @@ public class MqttServerAioHandler implements ServerAioHandler {
*/
@Override
public Packet decode(ByteBuffer buffer, int limit, int position, int readableLength, ChannelContext context) throws AioDecodeException {
return mqttDecoder.decode(context, buffer);
return mqttDecoder.decode(context, buffer, limit, position, readableLength);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册