Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

FreeBSD/socket: user cookie socket option support. #38

Open
wants to merge 2 commits into
base: bsd-port
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/jdk.net/bsd/classes/jdk/net/BsdSocketOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int getTcpKeepAliveIntvl(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 keepAliveOptionsSupported0();
private static native void setUserCookie(int fd, int cookie) throws SocketException;
Copy link
Owner

Choose a reason for hiding this comment

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

I might have been a bit hasty earlier. Please allow me to make some further comments now that I've had a longer look at it.

A minor comment is that all other native methods in this class end with 0. This is mostly because the non-native versions of the methods which call them take up the same name without the 0, but I think it's reasonable to want to be consistent. However, this leads me to the larger concern.

The method you're adding here is a private method. Since it isn't exposed through the public methods of the class it can never be called (other than internally, which is not done in this change). I question the value of adding code that can't actually be called (note that I am ignoring byte manipulation hacks that some mocking packages, for instance, employ that might allow that). Note that I'm not suggesting here that you immediately go and add a public method to call into this. What I'm suggesting is a discussion of how developers may want to utilise this and what changes might make sense to allow for that.

Copy link
Author

Choose a reason for hiding this comment

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

Yes in fact I wanted to test the "appeal" of this idea first and also to see if this is better to call it indirectly from another higher java class or since it is pretty "unique feature" to make it simply public finally...

static {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
System.loadLibrary("extnet");
Expand Down
14 changes: 14 additions & 0 deletions src/jdk.net/bsd/native/libextnet/BsdSocketOptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,17 @@ JNIEXPORT jint JNICALL Java_jdk_net_BsdSocketOptions_getTcpKeepAliveIntvl0
return optval;
#endif
}

JNIEXPORT void JNICALL Java_jdk_net_BsdSocketOptions_setUserCookie
(JNIEnv *env, jobject unused, jint fd, jint cookie) {
#ifndef __FreeBSD__
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
"unsupported socket option");
#else
jint rv;
const uint32_t optval = (const uint32_t)cookie;
socklen_t sz = sizeof (optval);
rv = setsockopt(fd, IPPROTO_TCP, SO_USER_COOKIE, &optval, sz);
handleError(env, rv, "set option SO_USER_COOKIE failed");
#endif
}