package io.netty.channel.kqueue;

import g.a.a.a.a;
import io.netty.channel.DefaultFileRegion;
import io.netty.channel.unix.Errors;
import io.netty.channel.unix.PeerCredentials;
import io.netty.channel.unix.Socket;
import java.nio.channels.ClosedChannelException;

/* JADX INFO: loaded from: classes.dex */
public final class BsdSocket extends Socket {
    private static final int FREEBSD_SND_LOW_AT_MAX = 32768;
    private static final ClosedChannelException SENDFILE_CLOSED_CHANNEL_EXCEPTION = (ClosedChannelException) a.N(Native.class, "sendfile(..)");
    private static final int APPLE_SND_LOW_AT_MAX = 131072;
    public static final int BSD_SND_LOW_AT_MAX = Math.min(APPLE_SND_LOW_AT_MAX, 32768);
    private static final Errors.NativeIoException SENDFILE_CONNECTION_RESET_EXCEPTION = Errors.newConnectionResetException("syscall:sendfile", Errors.ERRNO_EPIPE_NEGATIVE);

    public BsdSocket(int i2) {
        super(i2);
    }

    private static native String[] getAcceptFilter(int i2);

    private static native PeerCredentials getPeerCredentials(int i2);

    private static native int getSndLowAt(int i2);

    private static native int getTcpNoPush(int i2);

    public static BsdSocket newSocketDgram() {
        return new BsdSocket(Socket.newSocketDgram0());
    }

    public static BsdSocket newSocketDomain() {
        return new BsdSocket(Socket.newSocketDomain0());
    }

    public static BsdSocket newSocketStream() {
        return new BsdSocket(Socket.newSocketStream0());
    }

    private static native long sendFile(int i2, DefaultFileRegion defaultFileRegion, long j2, long j3, long j4);

    private static native void setAcceptFilter(int i2, String str, String str2);

    private static native void setSndLowAt(int i2, int i3);

    private static native void setTcpNoPush(int i2, int i3);

    public AcceptFilter getAcceptFilter() {
        String[] acceptFilter = getAcceptFilter(intValue());
        return acceptFilter == null ? AcceptFilter.PLATFORM_UNSUPPORTED : new AcceptFilter(acceptFilter[0], acceptFilter[1]);
    }

    public PeerCredentials getPeerCredentials() {
        return getPeerCredentials(intValue());
    }

    public int getSndLowAt() {
        return getSndLowAt(intValue());
    }

    public boolean isTcpNoPush() {
        return getTcpNoPush(intValue()) != 0;
    }

    public long sendFile(DefaultFileRegion defaultFileRegion, long j2, long j3, long j4) {
        defaultFileRegion.open();
        long jSendFile = sendFile(intValue(), defaultFileRegion, j2, j3, j4);
        return jSendFile >= 0 ? jSendFile : Errors.ioResult("sendfile", (int) jSendFile, SENDFILE_CONNECTION_RESET_EXCEPTION, SENDFILE_CLOSED_CHANNEL_EXCEPTION);
    }

    public void setAcceptFilter(AcceptFilter acceptFilter) {
        setAcceptFilter(intValue(), acceptFilter.filterName(), acceptFilter.filterArgs());
    }

    public void setSndLowAt(int i2) {
        setSndLowAt(intValue(), i2);
    }

    public void setTcpNoPush(boolean z2) {
        setTcpNoPush(intValue(), z2 ? 1 : 0);
    }
}
