< prev index next >

src/java.base/macosx/classes/sun/nio/ch/KQueueSelectorImpl.java

Print this page

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





142     /**
143      * Process changes to the interest ops.
144      */
145     private void processUpdateQueue() {
146         assert Thread.holdsLock(this);
147 
148         synchronized (updateLock) {
149             SelectionKeyImpl ski;
150             while ((ski = updateKeys.pollFirst()) != null) {
151                 if (ski.isValid()) {
152                     int fd = ski.getFDVal();
153                     // add to fdToKey if needed
154                     SelectionKeyImpl previous = fdToKey.putIfAbsent(fd, ski);
155                     assert (previous == null) || (previous == ski);
156 
157                     int newEvents = ski.translateInterestOps();
158                     int registeredEvents = ski.registeredEvents();
159 
160                     // DatagramChannelImpl::disconnect has reset socket
161                     if (ski.getAndClearReset() && registeredEvents != 0) {

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