jdk/src/java.base/aix/native/libnet/aix_close.c
changeset 44921 0672237e13c0
parent 44916 54d70322b32c
child 45061 74b09ee3cd55
child 46862 cb4b080576fa
equal deleted inserted replaced
44920:5b66112437ba 44921:0672237e13c0
     1 /*
     1 /*
     2  * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2016, 2017, SAP SE and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2016, SAP SE and/or its affiliates. All rights reserved.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.  Oracle designates this
     8  * published by the Free Software Foundation.  Oracle designates this
    63 #include <sys/resource.h>
    63 #include <sys/resource.h>
    64 #include <sys/uio.h>
    64 #include <sys/uio.h>
    65 #include <unistd.h>
    65 #include <unistd.h>
    66 #include <errno.h>
    66 #include <errno.h>
    67 #include <sys/poll.h>
    67 #include <sys/poll.h>
    68 #include "jvm.h"
       
    69 #include "net_util.h"
       
    70 
    68 
    71 /*
    69 /*
    72  * Stack allocated by thread when doing blocking operation
    70  * Stack allocated by thread when doing blocking operation
    73  */
    71  */
    74 typedef struct threadEntry {
    72 typedef struct threadEntry {
   507 /*
   505 /*
   508  * Wrapper for poll(s, timeout).
   506  * Wrapper for poll(s, timeout).
   509  * Auto restarts with adjusted timeout if interrupted by
   507  * Auto restarts with adjusted timeout if interrupted by
   510  * signal other than our wakeup signal.
   508  * signal other than our wakeup signal.
   511  */
   509  */
   512 int NET_Timeout(JNIEnv *env, int s, long timeout, long nanoTimeStamp) {
   510 int NET_Timeout0(int s, long timeout, long currentTime) {
   513     long prevNanoTime = nanoTimeStamp;
   511     long prevtime = currentTime, newtime;
   514     long nanoTimeout = timeout * NET_NSEC_PER_MSEC;
   512     struct timeval t;
   515     fdEntry_t *fdEntry = getFdEntry(s);
   513     fdEntry_t *fdEntry = getFdEntry(s);
   516 
   514 
   517     /*
   515     /*
   518      * Check that fd hasn't been closed.
   516      * Check that fd hasn't been closed.
   519      */
   517      */
   533          */
   531          */
   534         pfd.fd = s;
   532         pfd.fd = s;
   535         pfd.events = POLLIN | POLLERR;
   533         pfd.events = POLLIN | POLLERR;
   536 
   534 
   537         startOp(fdEntry, &self);
   535         startOp(fdEntry, &self);
   538         rv = poll(&pfd, 1, nanoTimeout / NET_NSEC_PER_MSEC);
   536         rv = poll(&pfd, 1, timeout);
   539         endOp(fdEntry, &self);
   537         endOp(fdEntry, &self);
   540 
   538 
   541         /*
   539         /*
   542          * If interrupted then adjust timeout. If timeout
   540          * If interrupted then adjust timeout. If timeout
   543          * has expired return 0 (indicating timeout expired).
   541          * has expired return 0 (indicating timeout expired).
   544          */
   542          */
   545         if (rv < 0 && errno == EINTR) {
   543         if (rv < 0 && errno == EINTR) {
   546             long newNanoTime = JVM_NanoTime(env, 0);
   544             if (timeout > 0) {
   547             nanoTimeout -= newNanoTime - prevNanoTime;
   545                 gettimeofday(&t, NULL);
   548             if (nanoTimeout < NET_NSEC_PER_MSEC) {
   546                 newtime = t.tv_sec * 1000  +  t.tv_usec / 1000;
   549                 return 0;
   547                 timeout -= newtime - prevtime;
       
   548                 if (timeout <= 0) {
       
   549                     return 0;
       
   550                 }
       
   551                 prevtime = newtime;
   550             }
   552             }
   551             prevNanoTime = newNanoTime;
       
   552         } else {
   553         } else {
   553             return rv;
   554             return rv;
   554         }
   555         }
   555     }
   556 
   556 }
   557     }
       
   558 }