Search in sources :

Example 6 with Http2Flags

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();
}
Also used : SimpleChannelPromiseAggregator(io.netty.handler.codec.http2.Http2CodecUtil.SimpleChannelPromiseAggregator) ByteBuf(io.netty.buffer.ByteBuf)

Example 7 with Http2Flags

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();
}
Also used : SimpleChannelPromiseAggregator(io.netty.handler.codec.http2.Http2CodecUtil.SimpleChannelPromiseAggregator) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)6 SimpleChannelPromiseAggregator (io.netty.handler.codec.http2.Http2CodecUtil.SimpleChannelPromiseAggregator)5 Http2Flags (io.netty.handler.codec.http2.Http2Flags)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 Unpooled (io.netty.buffer.Unpooled)1 Channel (io.netty.channel.Channel)1 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)1 AbstractHttp2ConnectionHandlerBuilder (io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder)1 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)1 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)1 Http2Connection (io.netty.handler.codec.http2.Http2Connection)1 Http2ConnectionDecoder (io.netty.handler.codec.http2.Http2ConnectionDecoder)1