Search in sources :

Example 11 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class EpollChannelConfig method setEpollMode.

/**
 * Set the {@link EpollMode} used. Default is
 * {@link EpollMode#EDGE_TRIGGERED}. If you want to use {@link #isAutoRead()} {@code false} or
 * {@link #getMaxMessagesPerRead()} and have an accurate behaviour you should use
 * {@link EpollMode#LEVEL_TRIGGERED}.
 *
 * <strong>Be aware this config setting can only be adjusted before the channel was registered.</strong>
 */
public EpollChannelConfig setEpollMode(EpollMode mode) {
    ObjectUtil.checkNotNull(mode, "mode");
    try {
        switch(mode) {
            case EDGE_TRIGGERED:
                checkChannelNotRegistered();
                ((AbstractEpollChannel) channel).setFlag(Native.EPOLLET);
                break;
            case LEVEL_TRIGGERED:
                checkChannelNotRegistered();
                ((AbstractEpollChannel) channel).clearFlag(Native.EPOLLET);
                break;
            default:
                throw new Error();
        }
    } catch (IOException e) {
        throw new ChannelException(e);
    }
    return this;
}
Also used : IOException(java.io.IOException) ChannelException(io.netty.channel.ChannelException)

Example 12 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class EpollDatagramChannelConfig method setNetworkInterface.

@Override
public EpollDatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) {
    try {
        EpollDatagramChannel datagramChannel = (EpollDatagramChannel) channel;
        datagramChannel.socket.setNetworkInterface(networkInterface);
        return this;
    } catch (IOException e) {
        throw new ChannelException(e);
    }
}
Also used : IOException(java.io.IOException) ChannelException(io.netty.channel.ChannelException)

Example 13 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class EpollSocketChannelConfigTest method testSetOptionWhenClosed.

// For this test to pass, we are relying on the sockets file descriptor not being reused after the socket is closed.
// This is inherently racy, so we allow getSoLinger to throw ChannelException a few of times, but eventually we do
// want to see a ClosedChannelException for the test to pass.
@RepeatedIfExceptionsTest(repeats = 4)
public void testSetOptionWhenClosed() {
    ch.close().syncUninterruptibly();
    ChannelException e = assertThrows(ChannelException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            ch.config().setSoLinger(0);
        }
    });
    assertThat(e).hasCauseInstanceOf(ClosedChannelException.class);
}
Also used : Executable(org.junit.jupiter.api.function.Executable) ClosedChannelException(java.nio.channels.ClosedChannelException) ChannelException(io.netty.channel.ChannelException) RepeatedIfExceptionsTest(io.github.artsok.RepeatedIfExceptionsTest)

Example 14 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project rest.li by linkedin.

the class Http2ProtocolUpgradeHandler method processChannelActive.

public static void processChannelActive(ChannelHandlerContext ctx, Logger log, ChannelPromise upgradePromise) {
    // For an upgrade request, clients should use an OPTIONS request for path “*” or a HEAD request for “/”.
    // RFC: https://tools.ietf.org/html/rfc7540#section-3.2
    // Implementation detail: https://http2.github.io/faq/#can-i-implement-http2-without-implementing-http11
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "*");
    final String hostname;
    if (ctx.channel().remoteAddress() instanceof InetSocketAddress) {
        // 1) The documentation of remoteAddress says that it should be down-casted to InetSocketAddress.
        // 2) The getHostString doesn't attempt a reverse lookup
        InetSocketAddress inetAddress = ((InetSocketAddress) ctx.channel().remoteAddress());
        hostname = inetAddress.getHostString() + ":" + inetAddress.getPort();
    } else {
        // if it is not a InetSocketAddress, it is a DomainSocketAddress, a LocalAddress or a EmbeddedSocketAddress.
        // In the R2 stack it should never happen
        hostname = "localhost";
        log.warn("The remoteAddress is not an InetSocketAddress, therefore it has been used '" + hostname + "'" + " for the HOST of the upgrade request", ctx.channel().remoteAddress());
    }
    // The host is required given rfc2616 14.23 also for the upgrade request.
    // Without it, the host the upgrade request fails
    // https://tools.ietf.org/html/rfc2616#section-14.23
    request.headers().add(HttpHeaderNames.HOST, hostname);
    ctx.writeAndFlush(request);
    // Fail the upgrade promise when channel is closed
    ctx.channel().closeFuture().addListener(future -> {
        if (!upgradePromise.isDone()) {
            upgradePromise.setFailure(new ChannelException("HTTP/2 upgrade did not complete before channel closed"));
        }
    });
    ctx.fireChannelActive();
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) InetSocketAddress(java.net.InetSocketAddress) ClosedChannelException(java.nio.channels.ClosedChannelException) ChannelException(io.netty.channel.ChannelException)

Example 15 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project Glowstone by GlowstoneMC.

the class GlowChannelInitializer method initChannel.

@Override
protected void initChannel(SocketChannel c) {
    MessageHandler handler = new MessageHandler(connectionManager);
    CodecsHandler codecs = new CodecsHandler(connectionManager.getProtocolProvider().handshake);
    FramingHandler framing = new FramingHandler();
    try {
        c.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException e) {
        // Not supported on all OSs, like Windows XP and lesser
        GlowServer.logger.warning("Your OS does not support type of service.");
    }
    c.pipeline().addLast("idle_timeout", new IdleStateHandler(READ_IDLE_TIMEOUT, WRITE_IDLE_TIMEOUT, 0)).addLast("legacy_ping", new LegacyPingHandler(connectionManager)).addLast("encryption", NoopHandler.INSTANCE).addLast("framing", framing).addLast("compression", NoopHandler.INSTANCE).addLast("codecs", codecs).addLast("handler", handler);
}
Also used : LegacyPingHandler(net.glowstone.net.handler.legacyping.LegacyPingHandler) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ChannelException(io.netty.channel.ChannelException)

Aggregations

ChannelException (io.netty.channel.ChannelException)23 IOException (java.io.IOException)10 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)4 ClosedChannelException (java.nio.channels.ClosedChannelException)4 JSONObjectDecoder (de.jackwhite20.japs.shared.pipeline.handler.JSONObjectDecoder)3 JSONObjectEncoder (de.jackwhite20.japs.shared.pipeline.handler.JSONObjectEncoder)3 Channel (io.netty.channel.Channel)3 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)3 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)2 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 BindException (java.net.BindException)2 InetSocketAddress (java.net.InetSocketAddress)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Send (com.github.ambry.network.Send)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SessionResumptionSslHandler (com.linkedin.r2.netty.handler.common.SessionResumptionSslHandler)1 Config (com.typesafe.config.Config)1 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 Connection (de.jackwhite20.japs.server.network.Connection)1