public class CustomProtocolDecoder extends CumulativeProtocolDecoder{
byte currentCmd = -1;
int currentSize = -1;
boolean isFirst = false;
@Override
protected boolean doDecode(IoSession is, ByteBuffer bb, ProtocolDecoderOutput pdo) throws Exception {
if(currentCmd == -1)
{
currentCmd = bb.get();
currentSize = Packet.getSize(currentCmd);
isFirst = true;
}
while(bb.remaining() > 0)
{
if(!isFirst)
{
currentCmd = bb.get();
currentSize = Packet.getSize(currentCmd);
}
else
isFirst = false;
//System.err.println(currentCmd + " " + bb.remaining() + " " + currentSize);
if(bb.remaining() >= currentSize - 1)
{
Packet p = PacketDecoder.decodePacket(bb, currentCmd);
pdo.write(p);
}
else
{
bb.flip();
return false;
}
}
if(bb.remaining() == 0)
return true;
else
return false;
}
}이것은 MINA에 ProtocolDecoder를 작성하는 올바른 방법입니까?
사람은이 코드를 잘못 아무것도 볼? 한 번에 많은 패킷을 받으면 하나의 클라이언트 만 연결되어 있어도 그 중 하나가 마지막에 끊어 질 수 있습니다 (예 : 15 바이트 대신 12 바이트). 이는 분명히 나쁩니다.