Search in sources :

Example 26 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project vert.x by eclipse.

the class FileStreamChannel method doWrite.

@Override
protected void doWrite(ChannelOutboundBuffer in) throws Exception {
    ByteBuf chunk;
    while (!stream.isNotWritable() && (chunk = (ByteBuf) in.current()) != null) {
        bytesWritten += chunk.readableBytes();
        stream.writeData(chunk.retain(), false);
        stream.handlerContext.flush();
        in.remove();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf)

Example 27 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project vert.x by eclipse.

the class Http2ConnectionBase method safeBuffer.

/**
   * Return a buffer from HTTP/2 codec that Vert.x can use:
   *
   * - if it's a direct buffer (coming likely from OpenSSL) : we get a heap buffer version
   * - if it's a composite buffer we do the same
   * - otherwise we increase the ref count
   */
static ByteBuf safeBuffer(ByteBuf buf, ByteBufAllocator allocator) {
    if (buf == Unpooled.EMPTY_BUFFER) {
        return buf;
    }
    if (buf.isDirect() || buf instanceof CompositeByteBuf) {
        if (buf.isReadable()) {
            ByteBuf buffer = allocator.heapBuffer(buf.readableBytes());
            buffer.writeBytes(buf);
            return buffer;
        } else {
            return Unpooled.EMPTY_BUFFER;
        }
    }
    return buf.retain();
}
Also used : CompositeByteBuf(io.netty.buffer.CompositeByteBuf) ByteBuf(io.netty.buffer.ByteBuf) CompositeByteBuf(io.netty.buffer.CompositeByteBuf)

Example 28 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project vert.x by eclipse.

the class VertxHttpHandler method write.

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (msg instanceof WebSocketFrameInternal) {
        WebSocketFrameInternal frame = (WebSocketFrameInternal) msg;
        ByteBuf buf = frame.getBinaryData();
        if (buf != Unpooled.EMPTY_BUFFER) {
            buf = safeBuffer(buf, ctx.alloc());
        }
        switch(frame.type()) {
            case BINARY:
                msg = new BinaryWebSocketFrame(frame.isFinal(), 0, buf);
                break;
            case TEXT:
                msg = new TextWebSocketFrame(frame.isFinal(), 0, buf);
                break;
            case CLOSE:
                msg = new CloseWebSocketFrame(true, 0, buf);
                break;
            case CONTINUATION:
                msg = new ContinuationWebSocketFrame(frame.isFinal(), 0, buf);
                break;
            case PONG:
                msg = new PongWebSocketFrame(buf);
                break;
            case PING:
                msg = new PingWebSocketFrame(buf);
                break;
            default:
                throw new IllegalStateException("Unsupported websocket msg " + msg);
        }
    }
    ctx.write(msg, promise);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) WebSocketFrameInternal(io.vertx.core.http.impl.ws.WebSocketFrameInternal)

Example 29 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project vert.x by eclipse.

the class WebSocketImplBase method writeBinaryFrameInternal.

private void writeBinaryFrameInternal(Buffer data) {
    ByteBuf buf = data.getByteBuf();
    WebSocketFrame frame = new WebSocketFrameImpl(FrameType.BINARY, buf);
    writeFrame(frame);
}
Also used : WebSocketFrameImpl(io.vertx.core.http.impl.ws.WebSocketFrameImpl) WebSocketFrame(io.vertx.core.http.WebSocketFrame) ByteBuf(io.netty.buffer.ByteBuf)

Example 30 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project vert.x by eclipse.

the class Http2ServerTest method testServerSendGoAway.

private void testServerSendGoAway(Handler<HttpServerRequest> requestHandler, int expectedError) throws Exception {
    server.requestHandler(requestHandler);
    startServer();
    TestClient client = new TestClient();
    ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
        request.decoder.frameListener(new Http2EventAdapter() {

            @Override
            public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception {
                vertx.runOnContext(v -> {
                    assertEquals(expectedError, errorCode);
                    complete();
                });
            }
        });
        Http2ConnectionEncoder encoder = request.encoder;
        int id1 = request.nextStreamId();
        encoder.writeHeaders(request.context, id1, GET("/"), 0, true, request.context.newPromise());
        int id2 = request.nextStreamId();
        encoder.writeHeaders(request.context, id2, GET("/"), 0, true, request.context.newPromise());
        request.context.flush();
    });
    fut.sync();
    await();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) HttpServer(io.vertx.core.http.HttpServer) MultiMap(io.vertx.core.MultiMap) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Context(io.vertx.core.Context) Unpooled(io.netty.buffer.Unpooled) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Exception(io.netty.handler.codec.http2.Http2Exception) Map(java.util.Map) ApplicationProtocolNegotiationHandler(io.netty.handler.ssl.ApplicationProtocolNegotiationHandler) ReadStream(io.vertx.core.streams.ReadStream) AbstractHttp2ConnectionHandlerBuilder(io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder) Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) StreamResetException(io.vertx.core.http.StreamResetException) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ChannelInitializer(io.netty.channel.ChannelInitializer) Http2Flags(io.netty.handler.codec.http2.Http2Flags) Set(java.util.Set) ChannelPipeline(io.netty.channel.ChannelPipeline) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) Future(io.vertx.core.Future) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) SslHandler(io.netty.handler.ssl.SslHandler) Http2Headers(io.netty.handler.codec.http2.Http2Headers) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Http2Error(io.netty.handler.codec.http2.Http2Error) HttpClient(io.vertx.core.http.HttpClient) NetSocket(io.vertx.core.net.NetSocket) Trust(io.vertx.test.core.tls.Trust) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Http2EventAdapter(io.netty.handler.codec.http2.Http2EventAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ByteBuf(io.netty.buffer.ByteBuf) WriteStream(io.vertx.core.streams.WriteStream) Http2Stream(io.netty.handler.codec.http2.Http2Stream) BiConsumer(java.util.function.BiConsumer) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) EventLoopGroup(io.netty.channel.EventLoopGroup) VertxInternal(io.vertx.core.impl.VertxInternal) ClosedChannelException(java.nio.channels.ClosedChannelException) Vertx(io.vertx.core.Vertx) FileOutputStream(java.io.FileOutputStream) ApplicationProtocolNames(io.netty.handler.ssl.ApplicationProtocolNames) Test(org.junit.Test) IOException(java.io.IOException) SSLHelper(io.vertx.core.net.impl.SSLHelper) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) Http2Settings(io.netty.handler.codec.http2.Http2Settings) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Bootstrap(io.netty.bootstrap.Bootstrap) AtomicLong(java.util.concurrent.atomic.AtomicLong) Http2Connection(io.netty.handler.codec.http2.Http2Connection) HttpMethod(io.vertx.core.http.HttpMethod) HttpUtils(io.vertx.core.http.impl.HttpUtils) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Handler(io.vertx.core.Handler) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) Http2Exception(io.netty.handler.codec.http2.Http2Exception) Http2EventAdapter(io.netty.handler.codec.http2.Http2EventAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)5135 Test (org.junit.Test)1813 Test (org.junit.jupiter.api.Test)717 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)392 ArrayList (java.util.ArrayList)312 IOException (java.io.IOException)309 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)209 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)183 ByteBuffer (java.nio.ByteBuffer)174 InetSocketAddress (java.net.InetSocketAddress)156 List (java.util.List)146 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)144 Channel (io.netty.channel.Channel)141 Test (org.testng.annotations.Test)140 ChannelFuture (io.netty.channel.ChannelFuture)132 Map (java.util.Map)118 CountDownLatch (java.util.concurrent.CountDownLatch)108 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)107 Position (org.traccar.model.Position)105 DeviceSession (org.traccar.DeviceSession)100