package net.openhft.chronicle.network.internal;

import java.io.IOException;
import java.net.SocketException;

public final class SocketExceptionUtil {

    private SocketExceptionUtil() {
    }

    /**
     * Is the passed exception one that results from reading from or writing to a reset
     * connection?
     * <p>
     * NOTE: This is not reliable and shouldn't be used for anything critical. We use it
     * to make logging less noisy, false negatives are acceptable and expected. It should
     * not produce false positives, but there's no guarantees it doesn't.
     *
     * @param e The exception
     * @return true if the exception is one that signifies the connection was reset
     */
    public static boolean isAConnectionResetException(IOException e) {
        return isALinuxJava12OrLessConnectionResetException(e)
                || isAWindowsConnectionResetException(e)
                || isALinuxJava13OrGreaterConnectionResetException(e);
    }

    private static boolean isALinuxJava13OrGreaterConnectionResetException(IOException e) {
        return e.getClass().equals(SocketException.class) && "Connection reset".equals(e.getMessage());
    }

    private static boolean isAWindowsConnectionResetException(IOException e) {
        return e.getClass().equals(IOException.class) && "An existing connection was forcibly closed by the remote host".equals(e.getMessage());
    }

    private static boolean isALinuxJava12OrLessConnectionResetException(IOException e) {
        return e.getClass().equals(IOException.class) && "Connection reset by peer".equals(e.getMessage());
    }
}

@@ -42,16 +42,56 @@
 ernal;%0A%0A
+import net.openhft.chronicle.core.Jvm;%0A%0A
 import j
@@ -110,16 +110,16 @@
 eption;%0A
-
 import j
@@ -142,16 +142,41 @@
 ception;
+%0Aimport java.util.Locale;
 %0A%0Apublic
@@ -825,32 +825,62 @@
 OException e) %7B%0A
+        Language.warnOnce();%0A%0A
         return i
@@ -1576,32 +1576,32 @@
 OException e) %7B%0A
-
         return e
@@ -1697,11 +1697,525 @@
 );%0A    %7D
+%0A%0A    private static final class Language %7B%0A        static %7B%0A            if (!Locale.getDefault().getLanguage().equals(Locale.ENGLISH.getLanguage())) %7B%0A                Jvm.warn().on(SocketExceptionUtil.class,%0A                        %22Running under non-English locale '%22 + Locale.getDefault().getLanguage() +%0A                                %22', transient exceptions will be reported with higher level than necessary.%22);%0A            %7D%0A        %7D%0A%0A        static void warnOnce() %7B%0A            // No-op.%0A        %7D%0A    %7D
 %0A%7D%0A

Add warning when transient exception suppression is unavailable due to locale