Only parse the packet length one time per packet. See #382

This commit is contained in:
norman 2012-06-06 08:42:36 +02:00
parent 977ce4e645
commit 784722eff4

View File

@ -199,6 +199,8 @@ public class SslHandler extends FrameDecoder
private final SSLEngineInboundCloseFuture sslEngineCloseFuture = new SSLEngineInboundCloseFuture();
private int packetLength = -1;
/**
* Creates a new instance.
*
@ -572,12 +574,11 @@ public class SslHandler extends FrameDecoder
protected Object decode(
final ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
if (packetLength == -1) {
if (buffer.readableBytes() < 5) {
return null;
}
int packetLength = 0;
// SSLv3 or TLS - Check ContentType
boolean tls;
switch (buffer.getUnsignedByte(buffer.readerIndex())) {
@ -639,6 +640,8 @@ public class SslHandler extends FrameDecoder
}
assert packetLength > 0;
}
if (buffer.readableBytes() < packetLength) {
return null;
@ -660,7 +663,11 @@ public class SslHandler extends FrameDecoder
// before calling the user code.
final int packetOffset = buffer.readerIndex();
buffer.skipBytes(packetLength);
try {
return unwrap(ctx, channel, buffer, packetOffset, packetLength);
} finally {
packetLength = -1;
}
}
/**