< prev index next >
src/java.base/windows/classes/java/net/DualStackPlainSocketImpl.java
Print this page
rev 49147 : imported patch 8198358-Change-DualStackPlainSocketImpl-to-align-its-organization-with-TwoStacksPlainSocketImp-13-socketGetOption
*** 24,49 ****
*/
package java.net;
import java.io.IOException;
import java.io.FileDescriptor;
- import jdk.internal.misc.SharedSecrets;
- import jdk.internal.misc.JavaIOFileDescriptorAccess;
! /**
! * This class defines the plain SocketImpl that is used on Windows platforms
! * greater or equal to Windows Vista. These platforms have a dual
! * layer TCP/IP stack and can handle both IPv4 and IPV6 through a
! * single file descriptor.
*
* @author Chris Hegarty
*/
! class DualStackPlainSocketImpl extends AbstractPlainSocketImpl
! {
! static JavaIOFileDescriptorAccess fdAccess = SharedSecrets.getJavaIOFileDescriptorAccess();
!
// true if this socket is exclusively bound
private final boolean exclusiveBind;
// emulates SO_REUSEADDR when exclusiveBind is true
--- 24,42 ----
*/
package java.net;
import java.io.IOException;
import java.io.FileDescriptor;
! /*
! * This class defines the plain SocketImpl that is used when
! * the System property java.net.preferIPv4Stack is set to false.
*
* @author Chris Hegarty
*/
! class DualStackPlainSocketImpl extends AbstractPlainSocketImpl {
// true if this socket is exclusively bound
private final boolean exclusiveBind;
// emulates SO_REUSEADDR when exclusiveBind is true
*** 81,117 ****
socketNativeSetOption(opt, on, value);
}
}
@Override
! int socketGetOption(int opt, Object iaContainerObj) throws SocketException {
! int nativefd = checkAndReturnNativeFD();
!
! // SO_BINDADDR is not a socket option.
! if (opt == SO_BINDADDR) {
! localAddress(nativefd, (InetAddressContainer)iaContainerObj);
! return 0; // return value doesn't matter.
! }
// SO_REUSEPORT is not supported on Windows.
- if (opt == SO_REUSEPORT) {
throw new UnsupportedOperationException("unsupported option");
}
-
- // SO_REUSEADDR emulated when using exclusive bind
- if (opt == SO_REUSEADDR && exclusiveBind)
- return isReuseAddress? 1 : -1;
-
- int value = getIntOption(nativefd, opt);
-
- switch (opt) {
- case TCP_NODELAY :
- case SO_OOBINLINE :
- case SO_KEEPALIVE :
- case SO_REUSEADDR :
- return (value == 0) ? -1 : 1;
- }
- return value;
}
/* Native methods */
static native void initProto();
--- 74,95 ----
socketNativeSetOption(opt, on, value);
}
}
@Override
! int socketGetOption(int opt, Object iaContainerObj)
! throws SocketException
! {
! if (opt == SO_REUSEADDR && exclusiveBind) {
! // SO_REUSEADDR emulated when using exclusive bind
! return isReuseAddress ? 1 : -1;
! } else if (opt == SO_REUSEPORT) {
// SO_REUSEPORT is not supported on Windows.
throw new UnsupportedOperationException("unsupported option");
+ } else {
+ return socketNativeGetOption(opt, iaContainerObj);
}
}
/* Native methods */
static native void initProto();
*** 132,154 ****
native void socketClose0(boolean useDeferredClose) throws IOException;
native void socketShutdown(int howto) throws IOException;
- static native int getIntOption(int fd, int cmd) throws SocketException;
- static native void localAddress(int fd, InetAddressContainer in) throws SocketException;
-
native void socketNativeSetOption(int cmd, boolean on, Object value)
throws SocketException;
native int socketNativeGetOption(int opt, Object iaContainerObj)
throws SocketException;
native void socketSendUrgentData(int data) throws IOException;
-
- private int checkAndReturnNativeFD() throws SocketException {
- if (fd == null || !fd.valid())
- throw new SocketException("Socket closed");
-
- return fdAccess.get(fd);
- }
}
--- 110,122 ----
< prev index next >