Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle EHOSTUNREACH errors in io.netty.channel.unix.Errors (#13317) #13318

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions transport-native-unix-common/src/main/c/netty_unix_errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ static jint netty_unix_errors_errorENETUNREACH(JNIEnv* env, jclass clazz) {
return ENETUNREACH;
}

static jint netty_unix_errors_errorEHOSTUNREACH(JNIEnv* env, jclass clazz) {
return EHOSTUNREACH;
}

static jstring netty_unix_errors_strError(JNIEnv* env, jclass clazz, jint error) {
return (*env)->NewStringUTF(env, strerror(error));
}
Expand All @@ -207,6 +211,7 @@ static const JNINativeMethod statically_referenced_fixed_method_table[] = {
{ "errorEISCONN", "()I", (void *) netty_unix_errors_errorEISCONN },
{ "errorEALREADY", "()I", (void *) netty_unix_errors_errorEALREADY },
{ "errorENETUNREACH", "()I", (void *) netty_unix_errors_errorENETUNREACH },
{ "errorEHOSTUNREACH", "()I", (void *) netty_unix_errors_errorEHOSTUNREACH },
{ "strError", "(I)Ljava/lang/String;", (void *) netty_unix_errors_strError }
};
static const jint statically_referenced_fixed_method_table_size = sizeof(statically_referenced_fixed_method_table) / sizeof(statically_referenced_fixed_method_table[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.errnoEWOULDBLOCK;
import static io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.errorEALREADY;
import static io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.errorECONNREFUSED;
import static io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.errorEHOSTUNREACH;
import static io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.errorEISCONN;
import static io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.errorENETUNREACH;
import static io.netty.channel.unix.ErrorsStaticallyReferencedJniMethods.strError;
Expand All @@ -58,6 +59,7 @@ public final class Errors {
public static final int ERROR_EISCONN_NEGATIVE = -errorEISCONN();
public static final int ERROR_EALREADY_NEGATIVE = -errorEALREADY();
public static final int ERROR_ENETUNREACH_NEGATIVE = -errorENETUNREACH();
public static final int ERROR_EHOSTUNREACH_NEGATIVE = -errorEHOSTUNREACH();

/**
* Holds the mappings for errno codes to String messages.
Expand Down Expand Up @@ -152,7 +154,7 @@ private static String errnoString(int err) {
}

private static IOException newConnectException0(String method, int err) {
if (err == ERROR_ENETUNREACH_NEGATIVE) {
if (err == ERROR_ENETUNREACH_NEGATIVE || err == ERROR_EHOSTUNREACH_NEGATIVE) {
return new NoRouteToHostException();
}
if (err == ERROR_EISCONN_NEGATIVE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ private ErrorsStaticallyReferencedJniMethods() { }
static native int errorEISCONN();
static native int errorEALREADY();
static native int errorENETUNREACH();
static native int errorEHOSTUNREACH();
static native String strError(int err);
}