Skip to content

Commit

Permalink
Wrap payload bytes in an unpooled buffer rather than copying to a poo…
Browse files Browse the repository at this point in the history
…led buffer.
  • Loading branch information
jchambers committed Feb 13, 2020
1 parent 72a1d94 commit 96227fe
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.gson.GsonBuilder;
import com.turo.pushy.apns.util.DateAsTimeSinceEpochTypeAdapter;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
Expand Down Expand Up @@ -72,8 +73,6 @@ class ApnsClientHandler extends Http2ConnectionHandler implements Http2FrameList
private static final AsciiString APNS_ID_HEADER = new AsciiString("apns-id");
private static final AsciiString APNS_PUSH_TYPE_HEADER = new AsciiString("apns-push-type");

private static final int INITIAL_PAYLOAD_BUFFER_CAPACITY = 4096;

private static final IOException STREAMS_EXHAUSTED_EXCEPTION =
new IOException("HTTP/2 streams exhausted; closing connection.");

Expand Down Expand Up @@ -196,8 +195,8 @@ private void writePushNotification(final ChannelHandlerContext context, final Pu
this.encoder().writeHeaders(context, streamId, headers, 0, false, headersPromise);
log.trace("Wrote headers on stream {}: {}", streamId, headers);

final ByteBuf payloadBuffer = context.alloc().ioBuffer(INITIAL_PAYLOAD_BUFFER_CAPACITY);
payloadBuffer.writeBytes(pushNotification.getPayload().getBytes(StandardCharsets.UTF_8));
final ByteBuf payloadBuffer =
Unpooled.wrappedBuffer(pushNotification.getPayload().getBytes(StandardCharsets.UTF_8));

final ChannelPromise dataPromise = context.newPromise();
this.encoder().writeData(context, streamId, payloadBuffer, 0, true, dataPromise);
Expand Down

0 comments on commit 96227fe

Please sign in to comment.