< prev index next >

src/java.base/windows/native/libnet/PlainSocketImpl.c

Print this page
rev 53869 : 8250521: Configure initial RTO to use minimal retry for loopback connections on Windows


 101     if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
 102                                   &sa_len, v4MappedAddress) != 0) {
 103         return;
 104     }
 105 
 106     rv = NET_WinBind(fd, &sa, sa_len, exclBind);
 107 
 108     if (rv == SOCKET_ERROR)
 109         NET_ThrowNew(env, WSAGetLastError(), "NET_Bind");
 110 }
 111 
 112 /*
 113  * Class:     java_net_PlainSocketImpl
 114  * Method:    connect0
 115  * Signature: (ILjava/net/InetAddress;I)I
 116  */
 117 JNIEXPORT jint JNICALL Java_java_net_PlainSocketImpl_connect0
 118   (JNIEnv *env, jclass clazz, jint fd, jobject iaObj, jint port) {
 119     SOCKETADDRESS sa;
 120     int rv, sa_len = 0;



 121     jboolean v4MappedAddress = ipv6_available() ? JNI_TRUE : JNI_FALSE;
 122 
 123     if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
 124                                   &sa_len, v4MappedAddress) != 0) {
 125         return -1;










 126     }
 127 
 128     rv = connect(fd, &sa.sa, sa_len);
 129     if (rv == SOCKET_ERROR) {
 130         int err = WSAGetLastError();
 131         if (err == WSAEWOULDBLOCK) {
 132             return java_net_PlainSocketImpl_WOULDBLOCK;
 133         } else if (err == WSAEADDRNOTAVAIL) {
 134             JNU_ThrowByName(env, JNU_JAVANETPKG "ConnectException",
 135                 "connect: Address is invalid on local machine,"
 136                 " or port is not valid on remote machine");
 137         } else {
 138             NET_ThrowNew(env, err, "connect");
 139         }
 140         // return value not important.
 141     }
 142     return rv;
 143 }
 144 
 145 /*




 101     if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
 102                                   &sa_len, v4MappedAddress) != 0) {
 103         return;
 104     }
 105 
 106     rv = NET_WinBind(fd, &sa, sa_len, exclBind);
 107 
 108     if (rv == SOCKET_ERROR)
 109         NET_ThrowNew(env, WSAGetLastError(), "NET_Bind");
 110 }
 111 
 112 /*
 113  * Class:     java_net_PlainSocketImpl
 114  * Method:    connect0
 115  * Signature: (ILjava/net/InetAddress;I)I
 116  */
 117 JNIEXPORT jint JNICALL Java_java_net_PlainSocketImpl_connect0
 118   (JNIEnv *env, jclass clazz, jint fd, jobject iaObj, jint port) {
 119     SOCKETADDRESS sa;
 120     int rv, sa_len = 0;
 121     int so_rv;
 122     SOCKET s = (SOCKET)fd;
 123     int type = 0, optlen = sizeof(type);
 124     jboolean v4MappedAddress = ipv6_available() ? JNI_TRUE : JNI_FALSE;
 125 
 126     if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
 127                                   &sa_len, v4MappedAddress) != 0) {
 128         return -1;
 129     }
 130 
 131     so_rv = getsockopt(s, SOL_SOCKET, SO_TYPE, (char*)&type, &optlen);
 132 
 133     /**
 134      * Windows has a very long socket connect timeout of 2 seconds.
 135      * If it's the loopback adapter we can shorten the wait interval.
 136      */
 137     if (so_rv == 0 && type == SOCK_STREAM && IS_LOOPBACK_ADDRESS(&sa)) {
 138         NET_EnableFastTcpLoopbackConnect(fd);
 139     }
 140 
 141     rv = connect(fd, &sa.sa, sa_len);
 142     if (rv == SOCKET_ERROR) {
 143         int err = WSAGetLastError();
 144         if (err == WSAEWOULDBLOCK) {
 145             return java_net_PlainSocketImpl_WOULDBLOCK;
 146         } else if (err == WSAEADDRNOTAVAIL) {
 147             JNU_ThrowByName(env, JNU_JAVANETPKG "ConnectException",
 148                 "connect: Address is invalid on local machine,"
 149                 " or port is not valid on remote machine");
 150         } else {
 151             NET_ThrowNew(env, err, "connect");
 152         }
 153         // return value not important.
 154     }
 155     return rv;
 156 }
 157 
 158 /*


< prev index next >