< prev index next >

src/java.base/linux/classes/sun/nio/ch/EPollSelectorImpl.java

Print this page

 98 
 99     @Override
100     protected int doSelect(Consumer<SelectionKey> action, long timeout)
101         throws IOException
102     {
103         assert Thread.holdsLock(this);
104 
105         // epoll_wait timeout is int
106         int to = (int) Math.min(timeout, Integer.MAX_VALUE);
107         boolean blocking = (to != 0);
108         boolean timedPoll = (to > 0);
109 
110         int numEntries;
111         processUpdateQueue();
112         processDeregisterQueue();
113         try {
114             begin(blocking);
115 
116             do {
117                 long startTime = timedPoll ? System.nanoTime() : 0;
118                 numEntries = EPoll.wait(epfd, pollArrayAddress, NUM_EPOLLEVENTS, to);
119                 if (numEntries == IOStatus.INTERRUPTED && timedPoll) {
120                     // timed poll interrupted so need to adjust timeout
121                     long adjust = System.nanoTime() - startTime;
122                     to -= TimeUnit.MILLISECONDS.convert(adjust, TimeUnit.NANOSECONDS);
123                     if (to <= 0) {
124                         // timeout expired so no retry
125                         numEntries = 0;
126                     }
127                 }
128             } while (numEntries == IOStatus.INTERRUPTED);
129             assert IOStatus.check(numEntries);
130 
131         } finally {
132             end(blocking);
133         }
134         processDeregisterQueue();
135         return processEvents(numEntries, action);
136     }
137 





138     /**
139      * Process changes to the interest ops.
140      */
141     private void processUpdateQueue() {
142         assert Thread.holdsLock(this);
143 
144         synchronized (updateLock) {
145             SelectionKeyImpl ski;
146             while ((ski = updateKeys.pollFirst()) != null) {
147                 if (ski.isValid()) {
148                     int fd = ski.getFDVal();
149                     // add to fdToKey if needed
150                     SelectionKeyImpl previous = fdToKey.putIfAbsent(fd, ski);
151                     assert (previous == null) || (previous == ski);
152 
153                     int newEvents = ski.translateInterestOps();
154                     int registeredEvents = ski.registeredEvents();
155                     if (newEvents != registeredEvents) {
156                         if (newEvents == 0) {
157                             // remove from epoll

 98 
 99     @Override
100     protected int doSelect(Consumer<SelectionKey> action, long timeout)
101         throws IOException
102     {
103         assert Thread.holdsLock(this);
104 
105         // epoll_wait timeout is int
106         int to = (int) Math.min(timeout, Integer.MAX_VALUE);
107         boolean blocking = (to != 0);
108         boolean timedPoll = (to > 0);
109 
110         int numEntries;
111         processUpdateQueue();
112         processDeregisterQueue();
113         try {
114             begin(blocking);
115 
116             do {
117                 long startTime = timedPoll ? System.nanoTime() : 0;
118                 numEntries = poll(to);
119                 if (numEntries == IOStatus.INTERRUPTED && timedPoll) {
120                     // timed poll interrupted so need to adjust timeout
121                     long adjust = System.nanoTime() - startTime;
122                     to -= TimeUnit.MILLISECONDS.convert(adjust, TimeUnit.NANOSECONDS);
123                     if (to <= 0) {
124                         // timeout expired so no retry
125                         numEntries = 0;
126                     }
127                 }
128             } while (numEntries == IOStatus.INTERRUPTED);
129             assert IOStatus.check(numEntries);
130 
131         } finally {
132             end(blocking);
133         }
134         processDeregisterQueue();
135         return processEvents(numEntries, action);
136     }
137 
138     @Override
139     protected int implPoll(long timeout) throws IOException {
140         return EPoll.wait(epfd, pollArrayAddress, NUM_EPOLLEVENTS, (int) timeout);
141     }
142 
143     /**
144      * Process changes to the interest ops.
145      */
146     private void processUpdateQueue() {
147         assert Thread.holdsLock(this);
148 
149         synchronized (updateLock) {
150             SelectionKeyImpl ski;
151             while ((ski = updateKeys.pollFirst()) != null) {
152                 if (ski.isValid()) {
153                     int fd = ski.getFDVal();
154                     // add to fdToKey if needed
155                     SelectionKeyImpl previous = fdToKey.putIfAbsent(fd, ski);
156                     assert (previous == null) || (previous == ski);
157 
158                     int newEvents = ski.translateInterestOps();
159                     int registeredEvents = ski.registeredEvents();
160                     if (newEvents != registeredEvents) {
161                         if (newEvents == 0) {
162                             // remove from epoll
< prev index next >