jdk/src/java.base/unix/native/libnet/SocketInputStream.c
changeset 45061 74b09ee3cd55
parent 44921 0672237e13c0
--- a/jdk/src/java.base/unix/native/libnet/SocketInputStream.c	Wed May 10 12:00:08 2017 +0530
+++ b/jdk/src/java.base/unix/native/libnet/SocketInputStream.c	Wed May 10 23:06:49 2017 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "jvm.h"
 #include "net_util.h"
 
 #include "java_net_SocketInputStream.h"
@@ -48,9 +49,10 @@
 
 static int NET_ReadWithTimeout(JNIEnv *env, int fd, char *bufP, int len, long timeout) {
     int result = 0;
-    long prevtime = NET_GetCurrentTime(), newtime;
-    while (timeout > 0) {
-        result = NET_TimeoutWithCurrentTime(fd, timeout, prevtime);
+    jlong prevNanoTime = JVM_NanoTime(env, 0);
+    jlong nanoTimeout = (jlong) timeout * NET_NSEC_PER_MSEC;
+    while (nanoTimeout >= NET_NSEC_PER_MSEC) {
+        result = NET_Timeout(env, fd, nanoTimeout / NET_NSEC_PER_MSEC, prevNanoTime);
         if (result <= 0) {
             if (result == 0) {
                 JNU_ThrowByName(env, "java/net/SocketTimeoutException", "Read timed out");
@@ -68,10 +70,10 @@
         }
         result = NET_NonBlockingRead(fd, bufP, len);
         if (result == -1 && ((errno == EAGAIN) || (errno == EWOULDBLOCK))) {
-            newtime = NET_GetCurrentTime();
-            timeout -= newtime - prevtime;
-            if (timeout > 0) {
-                prevtime = newtime;
+            jlong newtNanoTime = JVM_NanoTime(env, 0);
+            nanoTimeout -= newtNanoTime - prevNanoTime;
+            if (nanoTimeout >= NET_NSEC_PER_MSEC) {
+                prevNanoTime = newtNanoTime;
             }
         } else {
             break;