use of io.netty.handler.codec.http2.Http2Flags in project netty by netty.
the class DefaultHttp2FrameWriter method writeFrame.
@Override
public ChannelFuture writeFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags, ByteBuf payload, ChannelPromise promise) {
boolean releaseData = true;
SimpleChannelPromiseAggregator promiseAggregator = new SimpleChannelPromiseAggregator(promise, ctx.channel(), ctx.executor());
try {
verifyStreamOrConnectionId(streamId, STREAM_ID);
ByteBuf buf = ctx.alloc().buffer(FRAME_HEADER_LENGTH);
writeFrameHeaderInternal(buf, payload.readableBytes(), frameType, flags, streamId);
ctx.write(buf, promiseAggregator.newPromise());
releaseData = false;
ctx.write(payload, promiseAggregator.newPromise());
} catch (Throwable t) {
if (releaseData) {
payload.release();
}
promiseAggregator.setFailure(t);
}
return promiseAggregator.doneAllocatingPromises();
}
use of io.netty.handler.codec.http2.Http2Flags in project netty by netty.
the class DefaultHttp2FrameWriter method writeGoAway.
@Override
public ChannelFuture writeGoAway(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData, ChannelPromise promise) {
boolean releaseData = true;
SimpleChannelPromiseAggregator promiseAggregator = new SimpleChannelPromiseAggregator(promise, ctx.channel(), ctx.executor());
try {
verifyStreamOrConnectionId(lastStreamId, "Last Stream ID");
verifyErrorCode(errorCode);
int payloadLength = 8 + debugData.readableBytes();
ByteBuf buf = ctx.alloc().buffer(GO_AWAY_FRAME_HEADER_LENGTH);
writeFrameHeaderInternal(buf, payloadLength, GO_AWAY, new Http2Flags(), 0);
buf.writeInt(lastStreamId);
writeUnsignedInt(errorCode, buf);
ctx.write(buf, promiseAggregator.newPromise());
releaseData = false;
ctx.write(debugData, promiseAggregator.newPromise());
} catch (Throwable t) {
if (releaseData) {
debugData.release();
}
promiseAggregator.setFailure(t);
}
return promiseAggregator.doneAllocatingPromises();
}
Aggregations