src/java.base/solaris/classes/sun/nio/ch/EventPortWrapper.java
changeset 49290 07779973cbe2
parent 47216 71c04702a3d5
equal deleted inserted replaced
49289:148e29df1644 49290:07779973cbe2
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   179             }
   179             }
   180             updateCount = 0;
   180             updateCount = 0;
   181         }
   181         }
   182 
   182 
   183         // poll for events
   183         // poll for events
   184         int updated = port_getn(pfd, pollArrayAddress, POLL_MAX, timeout);
   184         int numEntries;
       
   185         long to = timeout;
       
   186         boolean timedPoll = (to > 0);
       
   187         do {
       
   188             long startTime = timedPoll ? System.currentTimeMillis() : 0;
       
   189             numEntries = port_getn(pfd, pollArrayAddress, POLL_MAX, timeout);
       
   190             if (numEntries == IOStatus.INTERRUPTED && timedPoll) {
       
   191                 // timed poll interrupted so need to adjust timeout
       
   192                 to -= System.currentTimeMillis() - startTime;
       
   193                 if (to <= 0) {
       
   194                     // timeout also expired so no retry
       
   195                     numEntries = 0;
       
   196                 }
       
   197             }
       
   198         } while (numEntries == IOStatus.INTERRUPTED);
   185 
   199 
   186         // after polling we need to queue all polled file descriptors as they
   200         // after polling we need to queue all polled file descriptors as they
   187         // are candidates to register for the next poll.
   201         // are candidates to register for the next poll.
   188         synchronized (updateLock) {
   202         synchronized (updateLock) {
   189             for (int i=0; i<updated; i++) {
   203             for (int i=0; i<numEntries; i++) {
   190                 if (getSource(i) == PORT_SOURCE_USER) {
   204                 if (getSource(i) == PORT_SOURCE_USER) {
   191                     interrupted = true;
   205                     interrupted = true;
   192                     setDescriptor(i, -1);
   206                     setDescriptor(i, -1);
   193                 } else {
   207                 } else {
   194                     // the default is to re-associate for the next poll
   208                     // the default is to re-associate for the next poll
   197                     setInterest(fd);
   211                     setInterest(fd);
   198                 }
   212                 }
   199             }
   213             }
   200         }
   214         }
   201 
   215 
   202         return updated;
   216         return numEntries;
   203     }
   217     }
   204 
   218 
   205     private void setInterest(int fd) {
   219     private void setInterest(int fd) {
   206         assert Thread.holdsLock(updateLock);
   220         assert Thread.holdsLock(updateLock);
   207 
   221