Skip to content

Commit

Permalink
8308593: Add KEEPALIVE Extended Socket Options Support for Windows
Browse files Browse the repository at this point in the history
Backport-of: f3ade388dac0b882e671462caa762138f44817fb
  • Loading branch information
tkyc authored and jerboaa committed Sep 11, 2023
1 parent 3973d5e commit 1927930
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 41 deletions.
12 changes: 6 additions & 6 deletions src/jdk.net/aix/classes/jdk/net/AIXSocketOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ boolean peerCredentialsSupported() {
}

@Override
void setTcpkeepAliveProbes(int fd, final int value) throws SocketException {
setTcpkeepAliveProbes0(fd, value);
void setTcpKeepAliveProbes(int fd, final int value) throws SocketException {
setTcpKeepAliveProbes0(fd, value);
}

@Override
Expand All @@ -83,8 +83,8 @@ void setTcpKeepAliveIntvl(int fd, final int value) throws SocketException {
}

@Override
int getTcpkeepAliveProbes(int fd) throws SocketException {
return getTcpkeepAliveProbes0(fd);
int getTcpKeepAliveProbes(int fd) throws SocketException {
return getTcpKeepAliveProbes0(fd);
}

@Override
Expand Down Expand Up @@ -117,11 +117,11 @@ UnixDomainPrincipal getSoPeerCred(int fd) throws SocketException {
return new UnixDomainPrincipal(user, group);
}

private static native void setTcpkeepAliveProbes0(int fd, int value) throws SocketException;
private static native void setTcpKeepAliveProbes0(int fd, int value) throws SocketException;
private static native void setTcpKeepAliveTime0(int fd, int value) throws SocketException;
private static native void setTcpKeepAliveIntvl0(int fd, int value) throws SocketException;
private static native void setIpDontFragment0(int fd, boolean value, boolean isIPv6) throws SocketException;
private static native int getTcpkeepAliveProbes0(int fd) throws SocketException;
private static native int getTcpKeepAliveProbes0(int fd) throws SocketException;
private static native int getTcpKeepAliveTime0(int fd) throws SocketException;
private static native int getTcpKeepAliveIntvl0(int fd) throws SocketException;
private static native boolean getIpDontFragment0(int fd, boolean isIPv6) throws SocketException;
Expand Down
8 changes: 4 additions & 4 deletions src/jdk.net/aix/native/libextnet/AIXSocketOptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ JNIEXPORT jboolean JNICALL Java_jdk_net_AIXSocketOptions_keepAliveOptionsSupport

/*
* Class: jdk_net_AIXSocketOptions
* Method: setTcpkeepAliveProbes0
* Method: setTcpKeepAliveProbes0
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_jdk_net_AIXSocketOptions_setTcpkeepAliveProbes0
JNIEXPORT void JNICALL Java_jdk_net_AIXSocketOptions_setTcpKeepAliveProbes0
(JNIEnv *env, jobject unused, jint fd, jint optval) {
jint rv = setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &optval, sizeof (optval));
handleError(env, rv, "set option TCP_KEEPCNT failed");
Expand Down Expand Up @@ -183,10 +183,10 @@ JNIEXPORT void JNICALL Java_jdk_net_AIXSocketOptions_setTcpKeepAliveIntvl0

/*
* Class: jdk_net_AIXSocketOptions
* Method: getTcpkeepAliveProbes0
* Method: getTcpKeepAliveProbes0
* Signature: (I)I;
*/
JNIEXPORT jint JNICALL Java_jdk_net_AIXSocketOptions_getTcpkeepAliveProbes0
JNIEXPORT jint JNICALL Java_jdk_net_AIXSocketOptions_getTcpKeepAliveProbes0
(JNIEnv *env, jobject unused, jint fd) {
jint optval, rv;
socklen_t sz = sizeof (optval);
Expand Down
12 changes: 6 additions & 6 deletions src/jdk.net/linux/classes/jdk/net/LinuxSocketOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ boolean peerCredentialsSupported() {
}

@Override
void setTcpkeepAliveProbes(int fd, final int value) throws SocketException {
setTcpkeepAliveProbes0(fd, value);
void setTcpKeepAliveProbes(int fd, final int value) throws SocketException {
setTcpKeepAliveProbes0(fd, value);
}

@Override
Expand All @@ -83,8 +83,8 @@ void setTcpKeepAliveIntvl(int fd, final int value) throws SocketException {
}

@Override
int getTcpkeepAliveProbes(int fd) throws SocketException {
return getTcpkeepAliveProbes0(fd);
int getTcpKeepAliveProbes(int fd) throws SocketException {
return getTcpKeepAliveProbes0(fd);
}

@Override
Expand Down Expand Up @@ -127,11 +127,11 @@ UnixDomainPrincipal getSoPeerCred(int fd) throws SocketException {
return new UnixDomainPrincipal(user, group);
}

private static native void setTcpkeepAliveProbes0(int fd, int value) throws SocketException;
private static native void setTcpKeepAliveProbes0(int fd, int value) throws SocketException;
private static native void setTcpKeepAliveTime0(int fd, int value) throws SocketException;
private static native void setTcpKeepAliveIntvl0(int fd, int value) throws SocketException;
private static native void setIpDontFragment0(int fd, boolean value, boolean isIPv6) throws SocketException;
private static native int getTcpkeepAliveProbes0(int fd) throws SocketException;
private static native int getTcpKeepAliveProbes0(int fd) throws SocketException;
private static native int getTcpKeepAliveTime0(int fd) throws SocketException;
private static native int getTcpKeepAliveIntvl0(int fd) throws SocketException;
private static native boolean getIpDontFragment0(int fd, boolean isIPv6) throws SocketException;
Expand Down
8 changes: 4 additions & 4 deletions src/jdk.net/linux/native/libextnet/LinuxSocketOptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ JNIEXPORT jboolean JNICALL Java_jdk_net_LinuxSocketOptions_keepAliveOptionsSuppo

/*
* Class: jdk_net_LinuxSocketOptions
* Method: setTcpkeepAliveProbes0
* Method: setTcpKeepAliveProbes0
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_jdk_net_LinuxSocketOptions_setTcpkeepAliveProbes0
JNIEXPORT void JNICALL Java_jdk_net_LinuxSocketOptions_setTcpKeepAliveProbes0
(JNIEnv *env, jobject unused, jint fd, jint optval) {
jint rv = setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &optval, sizeof (optval));
handleError(env, rv, "set option TCP_KEEPCNT failed");
Expand Down Expand Up @@ -186,10 +186,10 @@ JNIEXPORT void JNICALL Java_jdk_net_LinuxSocketOptions_setTcpKeepAliveIntvl0

/*
* Class: jdk_net_LinuxSocketOptions
* Method: getTcpkeepAliveProbes0
* Method: getTcpKeepAliveProbes0
* Signature: (I)I;
*/
JNIEXPORT jint JNICALL Java_jdk_net_LinuxSocketOptions_getTcpkeepAliveProbes0
JNIEXPORT jint JNICALL Java_jdk_net_LinuxSocketOptions_getTcpKeepAliveProbes0
(JNIEnv *env, jobject unused, jint fd) {
jint optval, rv;
socklen_t sz = sizeof (optval);
Expand Down
12 changes: 6 additions & 6 deletions src/jdk.net/macosx/classes/jdk/net/MacOSXSocketOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ boolean ipDontFragmentSupported() {
}

@Override
void setTcpkeepAliveProbes(int fd, final int value) throws SocketException {
setTcpkeepAliveProbes0(fd, value);
void setTcpKeepAliveProbes(int fd, final int value) throws SocketException {
setTcpKeepAliveProbes0(fd, value);
}

@Override
Expand All @@ -69,8 +69,8 @@ void setTcpKeepAliveIntvl(int fd, final int value) throws SocketException {
}

@Override
int getTcpkeepAliveProbes(int fd) throws SocketException {
return getTcpkeepAliveProbes0(fd);
int getTcpKeepAliveProbes(int fd) throws SocketException {
return getTcpKeepAliveProbes0(fd);
}

@Override
Expand Down Expand Up @@ -103,11 +103,11 @@ UnixDomainPrincipal getSoPeerCred(int fd) throws SocketException {
return new UnixDomainPrincipal(user, group);
}

private static native void setTcpkeepAliveProbes0(int fd, int value) throws SocketException;
private static native void setTcpKeepAliveProbes0(int fd, int value) throws SocketException;
private static native void setTcpKeepAliveTime0(int fd, int value) throws SocketException;
private static native void setTcpKeepAliveIntvl0(int fd, int value) throws SocketException;
private static native void setIpDontFragment0(int fd, boolean value, boolean isIPv6) throws SocketException;
private static native int getTcpkeepAliveProbes0(int fd) throws SocketException;
private static native int getTcpKeepAliveProbes0(int fd) throws SocketException;
private static native int getTcpKeepAliveTime0(int fd) throws SocketException;
private static native int getTcpKeepAliveIntvl0(int fd) throws SocketException;
private static native boolean getIpDontFragment0(int fd, boolean isIPv6) throws SocketException;
Expand Down
8 changes: 4 additions & 4 deletions src/jdk.net/macosx/native/libextnet/MacOSXSocketOptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ JNIEXPORT jboolean JNICALL Java_jdk_net_MacOSXSocketOptions_keepAliveOptionsSupp

/*
* Class: jdk_net_MacOSXSocketOptions
* Method: setTcpkeepAliveProbes0
* Method: setTcpKeepAliveProbes0
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_jdk_net_MacOSXSocketOptions_setTcpkeepAliveProbes0
JNIEXPORT void JNICALL Java_jdk_net_MacOSXSocketOptions_setTcpKeepAliveProbes0
(JNIEnv *env, jobject unused, jint fd, jint optval) {
jint rv = setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &optval, sizeof (optval));
handleError(env, rv, "set option TCP_KEEPCNT failed");
Expand Down Expand Up @@ -129,10 +129,10 @@ JNIEXPORT void JNICALL Java_jdk_net_MacOSXSocketOptions_setTcpKeepAliveIntvl0

/*
* Class: jdk_net_MacOSXSocketOptions
* Method: getTcpkeepAliveProbes0
* Method: getTcpKeepAliveProbes0
* Signature: (I)I;
*/
JNIEXPORT jint JNICALL Java_jdk_net_MacOSXSocketOptions_getTcpkeepAliveProbes0
JNIEXPORT jint JNICALL Java_jdk_net_MacOSXSocketOptions_getTcpKeepAliveProbes0
(JNIEnv *env, jobject unused, jint fd) {
jint optval, rv;
socklen_t sz = sizeof (optval);
Expand Down
16 changes: 8 additions & 8 deletions src/jdk.net/share/classes/jdk/net/ExtendedSocketOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public void setOption(FileDescriptor fd,
if (option == TCP_QUICKACK) {
setQuickAckOption(fd, (boolean) value);
} else if (option == TCP_KEEPCOUNT) {
setTcpkeepAliveProbes(fd, (Integer) value);
setTcpKeepAliveProbes(fd, (Integer) value);
} else if (option == IP_DONTFRAGMENT) {
setIpDontFragment(fd, (Boolean) value, isIPv6);
} else if (option == TCP_KEEPIDLE) {
Expand Down Expand Up @@ -307,7 +307,7 @@ public Object getOption(FileDescriptor fd,
if (option == TCP_QUICKACK) {
return getQuickAckOption(fd);
} else if (option == TCP_KEEPCOUNT) {
return getTcpkeepAliveProbes(fd);
return getTcpKeepAliveProbes(fd);
} else if (option == IP_DONTFRAGMENT) {
return getIpDontFragment(fd, isIPv6);
} else if (option == TCP_KEEPIDLE) {
Expand Down Expand Up @@ -343,9 +343,9 @@ private static Object getQuickAckOption(FileDescriptor fd)
return platformSocketOptions.getQuickAck(fdAccess.get(fd));
}

private static void setTcpkeepAliveProbes(FileDescriptor fd, int value)
private static void setTcpKeepAliveProbes(FileDescriptor fd, int value)
throws SocketException {
platformSocketOptions.setTcpkeepAliveProbes(fdAccess.get(fd), value);
platformSocketOptions.setTcpKeepAliveProbes(fdAccess.get(fd), value);
}

private static void setTcpKeepAliveTime(FileDescriptor fd, int value)
Expand All @@ -363,8 +363,8 @@ private static void setTcpKeepAliveIntvl(FileDescriptor fd, int value)
platformSocketOptions.setTcpKeepAliveIntvl(fdAccess.get(fd), value);
}

private static int getTcpkeepAliveProbes(FileDescriptor fd) throws SocketException {
return platformSocketOptions.getTcpkeepAliveProbes(fdAccess.get(fd));
private static int getTcpKeepAliveProbes(FileDescriptor fd) throws SocketException {
return platformSocketOptions.getTcpKeepAliveProbes(fdAccess.get(fd));
}

private static boolean getIpDontFragment(FileDescriptor fd, boolean isIPv6) throws SocketException {
Expand Down Expand Up @@ -438,7 +438,7 @@ boolean ipDontFragmentSupported() {
return false;
}

void setTcpkeepAliveProbes(int fd, final int value) throws SocketException {
void setTcpKeepAliveProbes(int fd, final int value) throws SocketException {
throw new UnsupportedOperationException("unsupported TCP_KEEPCNT option");
}

Expand All @@ -462,7 +462,7 @@ boolean getIpDontFragment(int fd, boolean isIPv6) throws SocketException {
throw new UnsupportedOperationException("unsupported IP_DONTFRAGMENT option");
}

int getTcpkeepAliveProbes(int fd) throws SocketException {
int getTcpKeepAliveProbes(int fd) throws SocketException {
throw new UnsupportedOperationException("unsupported TCP_KEEPCNT option");
}

Expand Down
44 changes: 43 additions & 1 deletion src/jdk.net/windows/classes/jdk/net/WindowsSocketOptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -41,6 +41,11 @@ boolean ipDontFragmentSupported() {
return true;
}

@Override
boolean keepAliveOptionsSupported() {
return keepAliveOptionsSupported0();
}

@Override
void setIpDontFragment(int fd, final boolean value, boolean isIPv6) throws SocketException {
setIpDontFragment0(fd, value, isIPv6);
Expand All @@ -51,8 +56,45 @@ boolean getIpDontFragment(int fd, boolean isIPv6) throws SocketException {
return getIpDontFragment0(fd, isIPv6);
}

@Override
void setTcpKeepAliveProbes(int fd, final int value) throws SocketException {
setTcpKeepAliveProbes0(fd, value);
}

@Override
int getTcpKeepAliveProbes(int fd) throws SocketException {
return getTcpKeepAliveProbes0(fd);
}

@Override
void setTcpKeepAliveTime(int fd, final int value) throws SocketException {
setTcpKeepAliveTime0(fd, value);
}

@Override
int getTcpKeepAliveTime(int fd) throws SocketException {
return getTcpKeepAliveTime0(fd);
}

@Override
void setTcpKeepAliveIntvl(int fd, final int value) throws SocketException {
setTcpKeepAliveIntvl0(fd, value);
}

@Override
int getTcpKeepAliveIntvl(int fd) throws SocketException {
return getTcpKeepAliveIntvl0(fd);
}

private static native boolean keepAliveOptionsSupported0();
private static native void setIpDontFragment0(int fd, boolean value, boolean isIPv6) throws SocketException;
private static native boolean getIpDontFragment0(int fd, boolean isIPv6) throws SocketException;
private static native void setTcpKeepAliveProbes0(int fd, int value) throws SocketException;
private static native int getTcpKeepAliveProbes0(int fd) throws SocketException;
private static native void setTcpKeepAliveTime0(int fd, int value) throws SocketException;
private static native int getTcpKeepAliveTime0(int fd) throws SocketException;
private static native void setTcpKeepAliveIntvl0(int fd, int value) throws SocketException;
private static native int getTcpKeepAliveIntvl0(int fd) throws SocketException;

static {
if (System.getSecurityManager() == null) {
Expand Down
Loading

1 comment on commit 1927930

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.