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