Make sure SslHandler also works if SslBufferPool use non heap ByteBuffers. See #329
Conflicts: handler/src/main/java/io/netty/handler/ssl/SslHandler.java
This commit is contained in:
parent
14b2a0db99
commit
ed357181c0
@ -15,10 +15,22 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.ssl;
|
package io.netty.handler.ssl;
|
||||||
|
|
||||||
import static io.netty.channel.Channels.*;
|
import io.netty.buffer.ChannelBuffer;
|
||||||
|
import io.netty.buffer.ChannelBuffers;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.channel.ChannelPipeline;
|
||||||
|
import io.netty.channel.DefaultChannelFuture;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
import io.netty.util.internal.NonReentrantLock;
|
||||||
|
import io.netty.util.internal.QueueFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@ -32,28 +44,6 @@ import javax.net.ssl.SSLEngineResult.HandshakeStatus;
|
|||||||
import javax.net.ssl.SSLEngineResult.Status;
|
import javax.net.ssl.SSLEngineResult.Status;
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
|
|
||||||
import io.netty.buffer.ChannelBuffer;
|
|
||||||
import io.netty.buffer.ChannelBuffers;
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.ChannelDownstreamHandler;
|
|
||||||
import io.netty.channel.ChannelEvent;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
|
||||||
import io.netty.channel.ChannelFutureListener;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.channel.ChannelPipeline;
|
|
||||||
import io.netty.channel.ChannelStateEvent;
|
|
||||||
import io.netty.channel.Channels;
|
|
||||||
import io.netty.channel.DefaultChannelFuture;
|
|
||||||
import io.netty.channel.DownstreamMessageEvent;
|
|
||||||
import io.netty.channel.ExceptionEvent;
|
|
||||||
import io.netty.channel.LifeCycleAwareChannelHandler;
|
|
||||||
import io.netty.channel.MessageEvent;
|
|
||||||
import io.netty.handler.codec.FrameDecoder;
|
|
||||||
import io.netty.logging.InternalLogger;
|
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
|
||||||
import io.netty.util.internal.NonReentrantLock;
|
|
||||||
import io.netty.util.internal.QueueFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds <a href="http://en.wikipedia.org/wiki/Transport_Layer_Security">SSL
|
* Adds <a href="http://en.wikipedia.org/wiki/Transport_Layer_Security">SSL
|
||||||
* · TLS</a> and StartTLS support to a {@link Channel}. Please refer
|
* · TLS</a> and StartTLS support to a {@link Channel}. Please refer
|
||||||
@ -710,8 +700,14 @@ public class SslHandler extends FrameDecoder
|
|||||||
|
|
||||||
if (result.bytesProduced() > 0) {
|
if (result.bytesProduced() > 0) {
|
||||||
outNetBuf.flip();
|
outNetBuf.flip();
|
||||||
msg = ChannelBuffers.buffer(outNetBuf.remaining());
|
int remaining = outNetBuf.remaining();
|
||||||
msg.writeBytes(outNetBuf.array(), 0, msg.capacity());
|
msg = ChannelBuffers.buffer(remaining);
|
||||||
|
|
||||||
|
// Transfer the bytes to the new ChannelBuffer using some safe method that will also
|
||||||
|
// work with "non" heap buffers
|
||||||
|
//
|
||||||
|
// See https://github.com/netty/netty/issues/329
|
||||||
|
msg.writeBytes(outNetBuf);
|
||||||
outNetBuf.clear();
|
outNetBuf.clear();
|
||||||
|
|
||||||
if (pendingWrite.outAppBuf.hasRemaining()) {
|
if (pendingWrite.outAppBuf.hasRemaining()) {
|
||||||
@ -850,7 +846,12 @@ public class SslHandler extends FrameDecoder
|
|||||||
if (result.bytesProduced() > 0) {
|
if (result.bytesProduced() > 0) {
|
||||||
outNetBuf.flip();
|
outNetBuf.flip();
|
||||||
ChannelBuffer msg = ChannelBuffers.buffer(outNetBuf.remaining());
|
ChannelBuffer msg = ChannelBuffers.buffer(outNetBuf.remaining());
|
||||||
msg.writeBytes(outNetBuf.array(), 0, msg.capacity());
|
|
||||||
|
// Transfer the bytes to the new ChannelBuffer using some safe method that will also
|
||||||
|
// work with "non" heap buffers
|
||||||
|
//
|
||||||
|
// See https://github.com/netty/netty/issues/329
|
||||||
|
msg.writeBytes(outNetBuf);
|
||||||
outNetBuf.clear();
|
outNetBuf.clear();
|
||||||
|
|
||||||
future = future(channel);
|
future = future(channel);
|
||||||
@ -992,8 +993,12 @@ public class SslHandler extends FrameDecoder
|
|||||||
outAppBuf.flip();
|
outAppBuf.flip();
|
||||||
|
|
||||||
if (outAppBuf.hasRemaining()) {
|
if (outAppBuf.hasRemaining()) {
|
||||||
ChannelBuffer frame = ctx.channel().getConfig().getBufferFactory().getBuffer(outAppBuf.remaining());
|
ChannelBuffer frame = ctx.getChannel().getConfig().getBufferFactory().getBuffer(outAppBuf.remaining());
|
||||||
frame.writeBytes(outAppBuf.array(), 0, frame.capacity());
|
// Transfer the bytes to the new ChannelBuffer using some safe method that will also
|
||||||
|
// work with "non" heap buffers
|
||||||
|
//
|
||||||
|
// See https://github.com/netty/netty/issues/329
|
||||||
|
frame.writeBytes(outAppBuf);
|
||||||
return frame;
|
return frame;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user