688 /* 689 * accept connection but ignore ECONNABORTED indicating that 690 * connection was eagerly accepted by the OS but was reset 691 * before accept() was called. 692 * 693 * If accept timeout in place and timeout is adjusted with 694 * each ECONNABORTED or EWOULDBLOCK to ensure that semantics 695 * of timeout are preserved. 696 */ 697 for (;;) { 698 int ret; 699 700 /* first usage pick up current time */ 701 if (prevTime == 0 && timeout > 0) { 702 prevTime = JVM_CurrentTimeMillis(env, 0); 703 } 704 705 /* passing a timeout of 0 to poll will return immediately, 706 but in the case of ServerSocket 0 means infinite. */ 707 if (timeout <= 0) { 708 ret = NET_Timeout(fd, -1); 709 } else { 710 ret = NET_Timeout(fd, timeout); 711 } 712 713 if (ret == 0) { 714 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", 715 "Accept timed out"); 716 return; 717 } else if (ret == -1) { 718 if (errno == EBADF) { 719 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); 720 } else { 721 NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Accept failed"); 722 } 723 return; 724 } 725 726 newfd = NET_Accept(fd, (struct sockaddr *)&him, &slen); 727 728 /* connection accepted */ 729 if (newfd >= 0) { 730 SET_BLOCKING(newfd); 731 break; 732 } | 688 /* 689 * accept connection but ignore ECONNABORTED indicating that 690 * connection was eagerly accepted by the OS but was reset 691 * before accept() was called. 692 * 693 * If accept timeout in place and timeout is adjusted with 694 * each ECONNABORTED or EWOULDBLOCK to ensure that semantics 695 * of timeout are preserved. 696 */ 697 for (;;) { 698 int ret; 699 700 /* first usage pick up current time */ 701 if (prevTime == 0 && timeout > 0) { 702 prevTime = JVM_CurrentTimeMillis(env, 0); 703 } 704 705 /* passing a timeout of 0 to poll will return immediately, 706 but in the case of ServerSocket 0 means infinite. */ 707 if (timeout <= 0) { 708 ret = NET_Timeout(env, fd, -1); 709 } else { 710 ret = NET_Timeout(env, fd, timeout); 711 } 712 JNU_CHECK_EXCEPTION(env); 713 if (ret == 0) { 714 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", 715 "Accept timed out"); 716 return; 717 } else if (ret == -1) { 718 if (errno == EBADF) { 719 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); 720 } else { 721 NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Accept failed"); 722 } 723 return; 724 } 725 726 newfd = NET_Accept(fd, (struct sockaddr *)&him, &slen); 727 728 /* connection accepted */ 729 if (newfd >= 0) { 730 SET_BLOCKING(newfd); 731 break; 732 } |