< prev index next >

src/java.base/unix/native/libnet/Inet6AddressImpl.c

Print this page
rev 14618 : 8158023: SocketExceptions contain too little information sometimes


 773 
 774         switch (errno) {
 775         case ENETUNREACH: /* Network Unreachable */
 776         case EAFNOSUPPORT: /* Address Family not supported */
 777         case EADDRNOTAVAIL: /* address is not available on  the  remote machine */
 778 #ifdef __linux__
 779         case EINVAL:
 780         case EHOSTUNREACH:
 781           /*
 782            * On some Linux versions, when  a socket is bound to the
 783            * loopback interface, connect will fail and errno will
 784            * be set to EINVAL or EHOSTUNREACH.  When that happens,
 785            * don't throw an exception, just return false.
 786            */
 787 #endif /* __linux__ */
 788           close(fd);
 789           return JNI_FALSE;
 790         }
 791 
 792         if (errno != EINPROGRESS) {
 793             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
 794                                          "connect failed");
 795             close(fd);
 796             return JNI_FALSE;
 797         }
 798 
 799         timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
 800 
 801         if (timeout >= 0) {
 802           /* has connection been established */
 803           if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
 804                          &optlen) <0) {
 805             connect_rv = errno;
 806           }
 807           if (connect_rv == 0 || ECONNREFUSED) {
 808             close(fd);
 809             return JNI_TRUE;
 810           }
 811         }
 812         close(fd);
 813         return JNI_FALSE;


 773 
 774         switch (errno) {
 775         case ENETUNREACH: /* Network Unreachable */
 776         case EAFNOSUPPORT: /* Address Family not supported */
 777         case EADDRNOTAVAIL: /* address is not available on  the  remote machine */
 778 #ifdef __linux__
 779         case EINVAL:
 780         case EHOSTUNREACH:
 781           /*
 782            * On some Linux versions, when  a socket is bound to the
 783            * loopback interface, connect will fail and errno will
 784            * be set to EINVAL or EHOSTUNREACH.  When that happens,
 785            * don't throw an exception, just return false.
 786            */
 787 #endif /* __linux__ */
 788           close(fd);
 789           return JNI_FALSE;
 790         }
 791 
 792         if (errno != EINPROGRESS) {
 793             JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
 794                                          "connect failed");
 795             close(fd);
 796             return JNI_FALSE;
 797         }
 798 
 799         timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
 800 
 801         if (timeout >= 0) {
 802           /* has connection been established */
 803           if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
 804                          &optlen) <0) {
 805             connect_rv = errno;
 806           }
 807           if (connect_rv == 0 || ECONNREFUSED) {
 808             close(fd);
 809             return JNI_TRUE;
 810           }
 811         }
 812         close(fd);
 813         return JNI_FALSE;
< prev index next >