8267256: Extend minimal retry for loopback connections on Windows to PlainSocketImpl

Backport-of: df332ff6e8bcee2cb5eeac1eefbc5c55a3fe8170
diff --git a/src/java.base/windows/native/libnet/PlainSocketImpl.c b/src/java.base/windows/native/libnet/PlainSocketImpl.c
index 65aa212..144d872 100644
--- a/src/java.base/windows/native/libnet/PlainSocketImpl.c
+++ b/src/java.base/windows/native/libnet/PlainSocketImpl.c
@@ -118,6 +118,9 @@
   (JNIEnv *env, jclass clazz, jint fd, jobject iaObj, jint port) {
     SOCKETADDRESS sa;
     int rv, sa_len = 0;
+    int so_rv;
+    SOCKET s = (SOCKET)fd;
+    int type = 0, optlen = sizeof(type);
     jboolean v4MappedAddress = ipv6_available() ? JNI_TRUE : JNI_FALSE;
 
     if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
@@ -125,6 +128,16 @@
         return -1;
     }
 
+    so_rv = getsockopt(s, SOL_SOCKET, SO_TYPE, (char*)&type, &optlen);
+
+    /**
+     * Windows has a very long socket connect timeout of 2 seconds.
+     * If it's the loopback adapter we can shorten the wait interval.
+     */
+    if (so_rv == 0 && type == SOCK_STREAM && IS_LOOPBACK_ADDRESS(&sa)) {
+        NET_EnableFastTcpLoopbackConnect(fd);
+    }
+
     rv = connect(fd, &sa.sa, sa_len);
     if (rv == SOCKET_ERROR) {
         int err = WSAGetLastError();