package io.netty.channel.unix;

import g.a.a.a.a;
import io.netty.util.internal.EmptyArrays;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.ConnectException;
import java.net.NoRouteToHostException;
import java.nio.channels.AlreadyConnectedException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ConnectionPendingException;
import java.nio.channels.NotYetConnectedException;

/* JADX INFO: loaded from: classes.dex */
public final class Errors {
    public static final int ERRNO_ENOENT_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errnoENOENT();
    public static final int ERRNO_ENOTCONN_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errnoENOTCONN();
    public static final int ERRNO_EBADF_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errnoEBADF();
    public static final int ERRNO_EPIPE_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errnoEPIPE();
    public static final int ERRNO_ECONNRESET_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errnoECONNRESET();
    public static final int ERRNO_EAGAIN_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errnoEAGAIN();
    public static final int ERRNO_EWOULDBLOCK_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errnoEWOULDBLOCK();
    public static final int ERRNO_EINPROGRESS_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errnoEINPROGRESS();
    public static final int ERROR_ECONNREFUSED_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errorECONNREFUSED();
    public static final int ERROR_EISCONN_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errorEISCONN();
    public static final int ERROR_EALREADY_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errorEALREADY();
    public static final int ERROR_ENETUNREACH_NEGATIVE = -ErrorsStaticallyReferencedJniMethods.errorENETUNREACH();
    private static final String[] ERRORS = new String[512];

    public static final class NativeConnectException extends ConnectException {
        private static final long serialVersionUID = -5532328671712318161L;
        private final int expectedErr;

        /* JADX WARN: Illegal instructions before constructor call */
        public NativeConnectException(String str, int i2) {
            StringBuilder sbJ = a.J(str, "(..) failed: ");
            sbJ.append(Errors.ERRORS[-i2]);
            super(sbJ.toString());
            this.expectedErr = i2;
        }

        public int expectedErr() {
            return this.expectedErr;
        }
    }

    public static final class NativeIoException extends IOException {
        private static final long serialVersionUID = 8222160204268655526L;
        private final int expectedErr;

        /* JADX WARN: Illegal instructions before constructor call */
        public NativeIoException(String str, int i2) {
            StringBuilder sbJ = a.J(str, "(..) failed: ");
            sbJ.append(Errors.ERRORS[-i2]);
            super(sbJ.toString());
            this.expectedErr = i2;
        }

        public int expectedErr() {
            return this.expectedErr;
        }
    }

    static {
        int i2 = 0;
        while (true) {
            String[] strArr = ERRORS;
            if (i2 >= strArr.length) {
                return;
            }
            strArr[i2] = ErrorsStaticallyReferencedJniMethods.strError(i2);
            i2++;
        }
    }

    private Errors() {
    }

    public static int ioResult(String str, int i2, NativeIoException nativeIoException, ClosedChannelException closedChannelException) throws NativeIoException, ClosedChannelException, FileNotFoundException {
        if (i2 == ERRNO_EAGAIN_NEGATIVE || i2 == ERRNO_EWOULDBLOCK_NEGATIVE) {
            return 0;
        }
        if (i2 == nativeIoException.expectedErr()) {
            throw nativeIoException;
        }
        if (i2 == ERRNO_EBADF_NEGATIVE) {
            throw closedChannelException;
        }
        if (i2 == ERRNO_ENOTCONN_NEGATIVE) {
            throw new NotYetConnectedException();
        }
        if (i2 == ERRNO_ENOENT_NEGATIVE) {
            throw new FileNotFoundException();
        }
        throw newIOException(str, i2);
    }

    public static NativeIoException newConnectionResetException(String str, int i2) {
        NativeIoException nativeIoExceptionNewIOException = newIOException(str, i2);
        nativeIoExceptionNewIOException.setStackTrace(EmptyArrays.EMPTY_STACK_TRACE);
        return nativeIoExceptionNewIOException;
    }

    public static NativeIoException newIOException(String str, int i2) {
        return new NativeIoException(str, i2);
    }

    public static void throwConnectException(String str, NativeConnectException nativeConnectException, int i2) throws ConnectException, FileNotFoundException, NoRouteToHostException {
        if (i2 == nativeConnectException.expectedErr()) {
            throw nativeConnectException;
        }
        if (i2 == ERROR_EALREADY_NEGATIVE) {
            throw new ConnectionPendingException();
        }
        if (i2 == ERROR_ENETUNREACH_NEGATIVE) {
            throw new NoRouteToHostException();
        }
        if (i2 == ERROR_EISCONN_NEGATIVE) {
            throw new AlreadyConnectedException();
        }
        if (i2 == ERRNO_ENOENT_NEGATIVE) {
            throw new FileNotFoundException();
        }
        StringBuilder sbJ = a.J(str, "(..) failed: ");
        sbJ.append(ERRORS[-i2]);
        throw new ConnectException(sbJ.toString());
    }
}
