Skip to content

Commit

Permalink
Make sure SslHandler also works if SslBufferPool use non heap ByteBuf…
Browse files Browse the repository at this point in the history
…fers. See #329
  • Loading branch information
normanmaurer committed May 28, 2012
1 parent a3ad6e2 commit 9726e80
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/main/java/org/jboss/netty/handler/ssl/SslHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import javax.net.ssl.SSLEngineResult.Status;
import javax.net.ssl.SSLException;

import org.ietf.jgss.ChannelBinding;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
Expand Down Expand Up @@ -726,8 +727,14 @@ private ChannelFuture wrap(ChannelHandlerContext context, Channel channel)

if (result.bytesProduced() > 0) {
outNetBuf.flip();
msg = ChannelBuffers.buffer(outNetBuf.remaining());
msg.writeBytes(outNetBuf.array(), 0, msg.capacity());
int remaining = outNetBuf.remaining();
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();

if (pendingWrite.outAppBuf.hasRemaining()) {
Expand Down Expand Up @@ -866,7 +873,12 @@ private ChannelFuture wrapNonAppData(ChannelHandlerContext ctx, Channel channel)
if (result.bytesProduced() > 0) {
outNetBuf.flip();
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();

future = future(channel);
Expand Down Expand Up @@ -1009,7 +1021,12 @@ private ChannelBuffer unwrap(

if (outAppBuf.hasRemaining()) {
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;
} else {
return null;
Expand Down

0 comments on commit 9726e80

Please sign in to comment.