package io.netty.channel.kqueue;

import g.a.a.a.a;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.AbstractChannel;
import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import io.netty.channel.ConnectTimeoutException;
import io.netty.channel.EventLoop;
import io.netty.channel.RecvByteBufAllocator;
import io.netty.channel.socket.ChannelInputShutdownEvent;
import io.netty.channel.socket.ChannelInputShutdownReadComplete;
import io.netty.channel.socket.SocketChannelConfig;
import io.netty.channel.unix.Errors;
import io.netty.channel.unix.FileDescriptor;
import io.netty.channel.unix.UnixChannel;
import io.netty.channel.unix.UnixChannelUtil;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.internal.ObjectUtil;
import java.io.IOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AlreadyConnectedException;
import java.nio.channels.ConnectionPendingException;
import java.nio.channels.NotYetConnectedException;
import java.nio.channels.UnresolvedAddressException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractKQueueChannel extends AbstractChannel implements UnixChannel {
    private static final ChannelMetadata METADATA = new ChannelMetadata(false);
    public volatile boolean active;
    private ChannelPromise connectPromise;
    private ScheduledFuture<?> connectTimeoutFuture;
    public boolean inputClosedSeenErrorOnRead;
    public long jniSelfPtr;
    private volatile SocketAddress local;
    private boolean readFilterEnabled;
    public boolean readReadyRunnablePending;
    private volatile SocketAddress remote;
    private SocketAddress requestedRemoteAddress;
    public final BsdSocket socket;
    private boolean writeFilterEnabled;

    public abstract class AbstractKQueueUnsafe extends AbstractChannel.AbstractUnsafe {
        public static final /* synthetic */ boolean $assertionsDisabled = false;
        private KQueueRecvByteAllocatorHandle allocHandle;
        public boolean maybeMoreDataToRead;
        public boolean readPending;
        private final Runnable readReadyRunnable;

        public AbstractKQueueUnsafe() {
            super();
            this.readReadyRunnable = new Runnable() { // from class: io.netty.channel.kqueue.AbstractKQueueChannel.AbstractKQueueUnsafe.1
                @Override // java.lang.Runnable
                public void run() {
                    AbstractKQueueUnsafe abstractKQueueUnsafe = AbstractKQueueUnsafe.this;
                    AbstractKQueueChannel.this.readReadyRunnablePending = false;
                    abstractKQueueUnsafe.readReady(abstractKQueueUnsafe.recvBufAllocHandle());
                }
            };
        }

        private boolean doFinishConnect() {
            if (!AbstractKQueueChannel.this.socket.finishConnect()) {
                AbstractKQueueChannel.this.writeFilter(true);
                return false;
            }
            AbstractKQueueChannel.this.writeFilter(false);
            if (AbstractKQueueChannel.this.requestedRemoteAddress instanceof InetSocketAddress) {
                AbstractKQueueChannel abstractKQueueChannel = AbstractKQueueChannel.this;
                abstractKQueueChannel.remote = UnixChannelUtil.computeRemoteAddr((InetSocketAddress) abstractKQueueChannel.requestedRemoteAddress, AbstractKQueueChannel.this.socket.remoteAddress());
            }
            AbstractKQueueChannel.this.requestedRemoteAddress = null;
            return true;
        }

        private void finishConnect() {
            boolean zIsActive;
            try {
                zIsActive = AbstractKQueueChannel.this.isActive();
            } catch (Throwable th) {
                try {
                    fulfillConnectPromise(AbstractKQueueChannel.this.connectPromise, annotateConnectException(th, AbstractKQueueChannel.this.requestedRemoteAddress));
                    if (AbstractKQueueChannel.this.connectTimeoutFuture != null) {
                    }
                } finally {
                    if (AbstractKQueueChannel.this.connectTimeoutFuture != null) {
                        AbstractKQueueChannel.this.connectTimeoutFuture.cancel(false);
                    }
                    AbstractKQueueChannel.this.connectPromise = null;
                }
            }
            if (doFinishConnect()) {
                fulfillConnectPromise(AbstractKQueueChannel.this.connectPromise, zIsActive);
            }
        }

        private void fireEventAndClose(Object obj) {
            AbstractKQueueChannel.this.pipeline().fireUserEventTriggered(obj);
            close(voidPromise());
        }

        private void fulfillConnectPromise(ChannelPromise channelPromise, Throwable th) {
            if (channelPromise == null) {
                return;
            }
            channelPromise.tryFailure(th);
            closeIfClosed();
        }

        private void fulfillConnectPromise(ChannelPromise channelPromise, boolean z2) {
            if (channelPromise == null) {
                return;
            }
            AbstractKQueueChannel.this.active = true;
            boolean zIsActive = AbstractKQueueChannel.this.isActive();
            boolean zTrySuccess = channelPromise.trySuccess();
            if (!z2 && zIsActive) {
                AbstractKQueueChannel.this.pipeline().fireChannelActive();
            }
            if (zTrySuccess) {
                return;
            }
            close(voidPromise());
        }

        public final void clearReadFilter0() {
            try {
                this.readPending = false;
                AbstractKQueueChannel.this.readFilter(false);
            } catch (IOException e2) {
                AbstractKQueueChannel.this.pipeline().fireExceptionCaught((Throwable) e2);
                AbstractKQueueChannel.this.unsafe().close(AbstractKQueueChannel.this.unsafe().voidPromise());
            }
        }

        @Override // io.netty.channel.Channel.Unsafe
        public void connect(final SocketAddress socketAddress, SocketAddress socketAddress2, ChannelPromise channelPromise) {
            if (channelPromise.setUncancellable() && ensureOpen(channelPromise)) {
                try {
                    if (AbstractKQueueChannel.this.connectPromise != null) {
                        throw new ConnectionPendingException();
                    }
                    boolean zIsActive = AbstractKQueueChannel.this.isActive();
                    if (AbstractKQueueChannel.this.doConnect(socketAddress, socketAddress2)) {
                        fulfillConnectPromise(channelPromise, zIsActive);
                        return;
                    }
                    AbstractKQueueChannel.this.connectPromise = channelPromise;
                    AbstractKQueueChannel.this.requestedRemoteAddress = socketAddress;
                    int connectTimeoutMillis = AbstractKQueueChannel.this.config().getConnectTimeoutMillis();
                    if (connectTimeoutMillis > 0) {
                        AbstractKQueueChannel abstractKQueueChannel = AbstractKQueueChannel.this;
                        abstractKQueueChannel.connectTimeoutFuture = abstractKQueueChannel.eventLoop().schedule(new Runnable() { // from class: io.netty.channel.kqueue.AbstractKQueueChannel.AbstractKQueueUnsafe.2
                            @Override // java.lang.Runnable
                            public void run() {
                                ChannelPromise channelPromise2 = AbstractKQueueChannel.this.connectPromise;
                                StringBuilder sbF = a.F("connection timed out: ");
                                sbF.append(socketAddress);
                                ConnectTimeoutException connectTimeoutException = new ConnectTimeoutException(sbF.toString());
                                if (channelPromise2 == null || !channelPromise2.tryFailure(connectTimeoutException)) {
                                    return;
                                }
                                AbstractKQueueUnsafe abstractKQueueUnsafe = AbstractKQueueUnsafe.this;
                                abstractKQueueUnsafe.close(abstractKQueueUnsafe.voidPromise());
                            }
                        }, connectTimeoutMillis, TimeUnit.MILLISECONDS);
                    }
                    channelPromise.addListener((GenericFutureListener<? extends Future<? super Void>>) new ChannelFutureListener() { // from class: io.netty.channel.kqueue.AbstractKQueueChannel.AbstractKQueueUnsafe.3
                        @Override // io.netty.util.concurrent.GenericFutureListener
                        public void operationComplete(ChannelFuture channelFuture) {
                            if (channelFuture.isCancelled()) {
                                if (AbstractKQueueChannel.this.connectTimeoutFuture != null) {
                                    AbstractKQueueChannel.this.connectTimeoutFuture.cancel(false);
                                }
                                AbstractKQueueChannel.this.connectPromise = null;
                                AbstractKQueueUnsafe abstractKQueueUnsafe = AbstractKQueueUnsafe.this;
                                abstractKQueueUnsafe.close(abstractKQueueUnsafe.voidPromise());
                            }
                        }
                    });
                } catch (Throwable th) {
                    closeIfClosed();
                    channelPromise.tryFailure(annotateConnectException(th, socketAddress));
                }
            }
        }

        public final void executeReadReadyRunnable(ChannelConfig channelConfig) {
            AbstractKQueueChannel abstractKQueueChannel = AbstractKQueueChannel.this;
            if (abstractKQueueChannel.readReadyRunnablePending || !abstractKQueueChannel.isActive() || AbstractKQueueChannel.this.shouldBreakReadReady(channelConfig)) {
                return;
            }
            AbstractKQueueChannel abstractKQueueChannel2 = AbstractKQueueChannel.this;
            abstractKQueueChannel2.readReadyRunnablePending = true;
            abstractKQueueChannel2.eventLoop().execute(this.readReadyRunnable);
        }

        public final boolean failConnectPromise(Throwable th) {
            if (AbstractKQueueChannel.this.connectPromise == null) {
                return false;
            }
            ChannelPromise channelPromise = AbstractKQueueChannel.this.connectPromise;
            AbstractKQueueChannel.this.connectPromise = null;
            if (!(th instanceof ConnectException)) {
                th = new ConnectException("failed to connect").initCause(th);
            }
            if (!channelPromise.tryFailure(th)) {
                return false;
            }
            closeIfClosed();
            return true;
        }

        @Override // io.netty.channel.AbstractChannel.AbstractUnsafe
        public final void flush0() {
            if (AbstractKQueueChannel.this.writeFilterEnabled) {
                return;
            }
            super.flush0();
        }

        public final void readEOF() {
            KQueueRecvByteAllocatorHandle kQueueRecvByteAllocatorHandleRecvBufAllocHandle = recvBufAllocHandle();
            kQueueRecvByteAllocatorHandleRecvBufAllocHandle.readEOF();
            if (AbstractKQueueChannel.this.isActive()) {
                readReady(kQueueRecvByteAllocatorHandleRecvBufAllocHandle);
            } else {
                shutdownInput(true);
            }
        }

        public final void readReady(long j2) {
            KQueueRecvByteAllocatorHandle kQueueRecvByteAllocatorHandleRecvBufAllocHandle = recvBufAllocHandle();
            kQueueRecvByteAllocatorHandleRecvBufAllocHandle.numberBytesPending(j2);
            readReady(kQueueRecvByteAllocatorHandleRecvBufAllocHandle);
        }

        public abstract void readReady(KQueueRecvByteAllocatorHandle kQueueRecvByteAllocatorHandle);

        public final void readReadyBefore() {
            this.maybeMoreDataToRead = false;
        }

        public final void readReadyFinally(ChannelConfig channelConfig) {
            this.maybeMoreDataToRead = this.allocHandle.maybeMoreDataToRead();
            if (!this.readPending && !channelConfig.isAutoRead()) {
                clearReadFilter0();
            } else if (this.readPending && this.maybeMoreDataToRead) {
                executeReadReadyRunnable(channelConfig);
            }
        }

        @Override // io.netty.channel.AbstractChannel.AbstractUnsafe, io.netty.channel.Channel.Unsafe
        public KQueueRecvByteAllocatorHandle recvBufAllocHandle() {
            if (this.allocHandle == null) {
                this.allocHandle = new KQueueRecvByteAllocatorHandle((RecvByteBufAllocator.ExtendedHandle) super.recvBufAllocHandle());
            }
            return this.allocHandle;
        }

        public void shutdownInput(boolean z2) {
            ChannelPipeline channelPipelinePipeline;
            Object obj;
            if (z2 && AbstractKQueueChannel.this.connectPromise != null) {
                finishConnect();
            }
            if (AbstractKQueueChannel.this.socket.isInputShutdown()) {
                if (z2) {
                    return;
                }
                AbstractKQueueChannel abstractKQueueChannel = AbstractKQueueChannel.this;
                abstractKQueueChannel.inputClosedSeenErrorOnRead = true;
                channelPipelinePipeline = abstractKQueueChannel.pipeline();
                obj = ChannelInputShutdownReadComplete.INSTANCE;
            } else {
                if (!AbstractKQueueChannel.isAllowHalfClosure(AbstractKQueueChannel.this.config())) {
                    close(voidPromise());
                    return;
                }
                try {
                    AbstractKQueueChannel.this.socket.shutdown(true, false);
                } catch (IOException unused) {
                    fireEventAndClose(ChannelInputShutdownEvent.INSTANCE);
                    return;
                } catch (NotYetConnectedException unused2) {
                }
                channelPipelinePipeline = AbstractKQueueChannel.this.pipeline();
                obj = ChannelInputShutdownEvent.INSTANCE;
            }
            channelPipelinePipeline.fireUserEventTriggered(obj);
        }

        public final void writeReady() {
            if (AbstractKQueueChannel.this.connectPromise != null) {
                finishConnect();
            } else {
                if (AbstractKQueueChannel.this.socket.isOutputShutdown()) {
                    return;
                }
                super.flush0();
            }
        }
    }

    public AbstractKQueueChannel(Channel channel, BsdSocket bsdSocket, SocketAddress socketAddress) {
        super(channel);
        this.readFilterEnabled = true;
        this.socket = (BsdSocket) ObjectUtil.checkNotNull(bsdSocket, "fd");
        this.active = true;
        this.remote = socketAddress;
        this.local = bsdSocket.localAddress();
    }

    public AbstractKQueueChannel(Channel channel, BsdSocket bsdSocket, boolean z2) {
        super(channel);
        this.readFilterEnabled = true;
        this.socket = (BsdSocket) ObjectUtil.checkNotNull(bsdSocket, "fd");
        this.active = z2;
        if (z2) {
            this.local = bsdSocket.localAddress();
            this.remote = bsdSocket.remoteAddress();
        }
    }

    public static void checkResolvable(InetSocketAddress inetSocketAddress) {
        if (inetSocketAddress.isUnresolved()) {
            throw new UnresolvedAddressException();
        }
    }

    private boolean doConnect0(SocketAddress socketAddress) throws Errors.NativeIoException {
        try {
            boolean zConnect = this.socket.connect(socketAddress);
            if (!zConnect) {
                writeFilter(true);
            }
            return zConnect;
        } catch (Throwable th) {
            doClose();
            throw th;
        }
    }

    private void evSet(short s2, short s3) {
        if (isOpen() && isRegistered()) {
            evSet0(s2, s3);
        }
    }

    private void evSet0(short s2, short s3) {
        evSet0(s2, s3, 0);
    }

    private void evSet0(short s2, short s3, int i2) {
        ((KQueueEventLoop) eventLoop()).evSet(this, s2, s3, i2);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static boolean isAllowHalfClosure(ChannelConfig channelConfig) {
        return (channelConfig instanceof SocketChannelConfig) && ((SocketChannelConfig) channelConfig).isAllowHalfClosure();
    }

    public static boolean isSoErrorZero(BsdSocket bsdSocket) {
        try {
            return bsdSocket.getSoError() == 0;
        } catch (IOException e2) {
            throw new ChannelException(e2);
        }
    }

    private static ByteBuf newDirectBuffer0(Object obj, ByteBuf byteBuf, ByteBufAllocator byteBufAllocator, int i2) {
        ByteBuf byteBufDirectBuffer = byteBufAllocator.directBuffer(i2);
        byteBufDirectBuffer.writeBytes(byteBuf, byteBuf.readerIndex(), i2);
        ReferenceCountUtil.safeRelease(obj);
        return byteBufDirectBuffer;
    }

    public final void clearReadFilter() {
        if (!isRegistered()) {
            this.readFilterEnabled = false;
            return;
        }
        EventLoop eventLoop = eventLoop();
        final AbstractKQueueUnsafe abstractKQueueUnsafe = (AbstractKQueueUnsafe) unsafe();
        if (eventLoop.inEventLoop()) {
            abstractKQueueUnsafe.clearReadFilter0();
        } else {
            eventLoop.execute(new Runnable() { // from class: io.netty.channel.kqueue.AbstractKQueueChannel.2
                @Override // java.lang.Runnable
                public void run() {
                    if (abstractKQueueUnsafe.readPending || AbstractKQueueChannel.this.config().isAutoRead()) {
                        return;
                    }
                    abstractKQueueUnsafe.clearReadFilter0();
                }
            });
        }
    }

    @Override // io.netty.channel.Channel
    public abstract KQueueChannelConfig config();

    @Override // io.netty.channel.AbstractChannel
    public final void doBeginRead() {
        AbstractKQueueUnsafe abstractKQueueUnsafe = (AbstractKQueueUnsafe) unsafe();
        abstractKQueueUnsafe.readPending = true;
        readFilter(true);
        if (abstractKQueueUnsafe.maybeMoreDataToRead) {
            abstractKQueueUnsafe.executeReadReadyRunnable(config());
        }
    }

    @Override // io.netty.channel.AbstractChannel
    public void doBind(SocketAddress socketAddress) {
        if (socketAddress instanceof InetSocketAddress) {
            checkResolvable((InetSocketAddress) socketAddress);
        }
        this.socket.bind(socketAddress);
        this.local = this.socket.localAddress();
    }

    @Override // io.netty.channel.AbstractChannel
    public void doClose() throws Errors.NativeIoException {
        this.active = false;
        this.inputClosedSeenErrorOnRead = true;
        try {
            if (isRegistered()) {
                EventLoop eventLoop = eventLoop();
                if (eventLoop.inEventLoop()) {
                    doDeregister();
                } else {
                    eventLoop.execute(new Runnable() { // from class: io.netty.channel.kqueue.AbstractKQueueChannel.1
                        @Override // java.lang.Runnable
                        public void run() {
                            try {
                                AbstractKQueueChannel.this.doDeregister();
                            } catch (Throwable th) {
                                AbstractKQueueChannel.this.pipeline().fireExceptionCaught(th);
                            }
                        }
                    });
                }
            }
        } finally {
            this.socket.close();
        }
    }

    public boolean doConnect(SocketAddress socketAddress, SocketAddress socketAddress2) throws Errors.NativeIoException {
        if (socketAddress2 instanceof InetSocketAddress) {
            checkResolvable((InetSocketAddress) socketAddress2);
        }
        InetSocketAddress inetSocketAddress = socketAddress instanceof InetSocketAddress ? (InetSocketAddress) socketAddress : null;
        if (inetSocketAddress != null) {
            checkResolvable(inetSocketAddress);
        }
        if (this.remote != null) {
            throw new AlreadyConnectedException();
        }
        if (socketAddress2 != null) {
            this.socket.bind(socketAddress2);
        }
        boolean zDoConnect0 = doConnect0(socketAddress);
        if (zDoConnect0) {
            if (inetSocketAddress != null) {
                socketAddress = UnixChannelUtil.computeRemoteAddr(inetSocketAddress, this.socket.remoteAddress());
            }
            this.remote = socketAddress;
        }
        this.local = this.socket.localAddress();
        return zDoConnect0;
    }

    @Override // io.netty.channel.AbstractChannel
    public void doDeregister() {
        readFilter(false);
        writeFilter(false);
        evSet0(Native.EVFILT_SOCK, Native.EV_DELETE, 0);
        ((KQueueEventLoop) eventLoop()).remove(this);
        this.readFilterEnabled = true;
    }

    @Override // io.netty.channel.AbstractChannel
    public void doDisconnect() throws Errors.NativeIoException {
        doClose();
    }

    public final int doReadBytes(ByteBuf byteBuf) {
        int address;
        int iWriterIndex = byteBuf.writerIndex();
        unsafe().recvBufAllocHandle().attemptedBytesRead(byteBuf.writableBytes());
        if (byteBuf.hasMemoryAddress()) {
            address = this.socket.readAddress(byteBuf.memoryAddress(), iWriterIndex, byteBuf.capacity());
        } else {
            ByteBuffer byteBufferInternalNioBuffer = byteBuf.internalNioBuffer(iWriterIndex, byteBuf.writableBytes());
            address = this.socket.read(byteBufferInternalNioBuffer, byteBufferInternalNioBuffer.position(), byteBufferInternalNioBuffer.limit());
        }
        if (address > 0) {
            byteBuf.writerIndex(iWriterIndex + address);
        }
        return address;
    }

    @Override // io.netty.channel.AbstractChannel
    public void doRegister() {
        this.readReadyRunnablePending = false;
        if (this.writeFilterEnabled) {
            evSet0(Native.EVFILT_WRITE, Native.EV_ADD_CLEAR_ENABLE);
        }
        if (this.readFilterEnabled) {
            evSet0(Native.EVFILT_READ, Native.EV_ADD_CLEAR_ENABLE);
        }
        evSet0(Native.EVFILT_SOCK, Native.EV_ADD, Native.NOTE_RDHUP);
    }

    public final int doWriteBytes(ChannelOutboundBuffer channelOutboundBuffer, ByteBuf byteBuf) {
        long j2;
        if (byteBuf.hasMemoryAddress()) {
            int iWriteAddress = this.socket.writeAddress(byteBuf.memoryAddress(), byteBuf.readerIndex(), byteBuf.writerIndex());
            if (iWriteAddress <= 0) {
                return Integer.MAX_VALUE;
            }
            j2 = iWriteAddress;
        } else {
            ByteBuffer byteBufferInternalNioBuffer = byteBuf.nioBufferCount() == 1 ? byteBuf.internalNioBuffer(byteBuf.readerIndex(), byteBuf.readableBytes()) : byteBuf.nioBuffer();
            int iWrite = this.socket.write(byteBufferInternalNioBuffer, byteBufferInternalNioBuffer.position(), byteBufferInternalNioBuffer.limit());
            if (iWrite <= 0) {
                return Integer.MAX_VALUE;
            }
            byteBufferInternalNioBuffer.position(byteBufferInternalNioBuffer.position() + iWrite);
            j2 = iWrite;
        }
        channelOutboundBuffer.removeBytes(j2);
        return 1;
    }

    @Override // io.netty.channel.unix.UnixChannel
    public final FileDescriptor fd() {
        return this.socket;
    }

    @Override // io.netty.channel.Channel
    public boolean isActive() {
        return this.active;
    }

    @Override // io.netty.channel.AbstractChannel
    public boolean isCompatible(EventLoop eventLoop) {
        return eventLoop instanceof KQueueEventLoop;
    }

    @Override // io.netty.channel.Channel
    public boolean isOpen() {
        return this.socket.isOpen();
    }

    @Override // io.netty.channel.AbstractChannel
    public SocketAddress localAddress0() {
        return this.local;
    }

    @Override // io.netty.channel.Channel
    public ChannelMetadata metadata() {
        return METADATA;
    }

    public final ByteBuf newDirectBuffer(ByteBuf byteBuf) {
        return newDirectBuffer(byteBuf, byteBuf);
    }

    public final ByteBuf newDirectBuffer(Object obj, ByteBuf byteBuf) {
        ByteBuf byteBufThreadLocalDirectBuffer;
        int i2 = byteBuf.readableBytes();
        if (i2 == 0) {
            ReferenceCountUtil.release(obj);
            return Unpooled.EMPTY_BUFFER;
        }
        ByteBufAllocator byteBufAllocatorAlloc = alloc();
        if (!byteBufAllocatorAlloc.isDirectBufferPooled() && (byteBufThreadLocalDirectBuffer = ByteBufUtil.threadLocalDirectBuffer()) != null) {
            byteBufThreadLocalDirectBuffer.writeBytes(byteBuf, byteBuf.readerIndex(), i2);
            ReferenceCountUtil.safeRelease(obj);
            return byteBufThreadLocalDirectBuffer;
        }
        return newDirectBuffer0(obj, byteBuf, byteBufAllocatorAlloc, i2);
    }

    @Override // io.netty.channel.AbstractChannel
    public abstract AbstractKQueueUnsafe newUnsafe();

    public void readFilter(boolean z2) {
        if (this.readFilterEnabled != z2) {
            this.readFilterEnabled = z2;
            evSet(Native.EVFILT_READ, z2 ? Native.EV_ADD_CLEAR_ENABLE : Native.EV_DELETE_DISABLE);
        }
    }

    @Override // io.netty.channel.AbstractChannel
    public SocketAddress remoteAddress0() {
        return this.remote;
    }

    public final boolean shouldBreakReadReady(ChannelConfig channelConfig) {
        return this.socket.isInputShutdown() && (this.inputClosedSeenErrorOnRead || !isAllowHalfClosure(channelConfig));
    }

    public void writeFilter(boolean z2) {
        if (this.writeFilterEnabled != z2) {
            this.writeFilterEnabled = z2;
            evSet(Native.EVFILT_WRITE, z2 ? Native.EV_ADD_CLEAR_ENABLE : Native.EV_DELETE_DISABLE);
        }
    }
}
