< prev index next >

src/java.base/macosx/native/libnet/bsd_close.c

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -37,10 +37,12 @@
 #include <sys/resource.h>
 #include <sys/uio.h>
 #include <unistd.h>
 #include <errno.h>
 #include <sys/poll.h>
+#include "jvm.h"
+#include "net_util.h"
 
 /*
  * Stack allocated by thread when doing blocking operation
  */
 typedef struct threadEntry {

@@ -412,12 +414,11 @@
 /*
  * Wrapper for select(s, timeout). We are using select() on Mac OS due to Bug 7131399.
  * Auto restarts with adjusted timeout if interrupted by
  * signal other than our wakeup signal.
  */
-int NET_Timeout0(int s, long timeout, long currentTime) {
-    long prevtime = currentTime, newtime;
+int NET_Timeout(JNIEnv *env, int s, long timeout, long nanoTimeStamp) {
     struct timeval t, *tp = &t;
     fd_set fds;
     fd_set* fdsp = NULL;
     int allocated = 0;
     threadEntry_t self;

@@ -458,10 +459,12 @@
         }
         allocated = 1;
     }
     FD_SET(s, fdsp);
 
+    long prevNanoTime = nanoTimeStamp;
+    long nanoTimeout = timeout * NET_NSEC_PER_MSEC;    
     for(;;) {
         int rv;
 
         /*
          * call select on the fd. If interrupted by our wakeup signal

@@ -475,27 +478,23 @@
         /*
          * If interrupted then adjust timeout. If timeout
          * has expired return 0 (indicating timeout expired).
          */
         if (rv < 0 && errno == EINTR) {
-            if (timeout > 0) {
-                struct timeval now;
-                gettimeofday(&now, NULL);
-                newtime = now.tv_sec * 1000  +  now.tv_usec / 1000;
-                timeout -= newtime - prevtime;
-                if (timeout <= 0) {
+            long newNanoTime = JVM_NanoTime(env, 0);
+            nanoTimeout -= newNanoTime - prevNanoTime;
+            if (nanoTimeout < NET_NSEC_PER_MSEC) {
                     if (allocated != 0)
                         free(fdsp);
                     return 0;
                 }
-                prevtime = newtime;
-                t.tv_sec = timeout / 1000;
-                t.tv_usec = (timeout % 1000) * 1000;
-            }
+            prevNanoTime = newNanoTime;
+            t.tv_sec = nanoTimeout / NET_NSEC_PER_SEC;
+            t.tv_usec = (nanoTimeout % NET_NSEC_PER_SEC) / NET_NSEC_PER_USEC;
+
         } else {
             if (allocated != 0)
                 free(fdsp);
             return rv;
         }
-
     }
 }
< prev index next >