@@ -197,9 +197,8 @@ static void netty_epoll_native_timerFdSetTime(JNIEnv* env, jclass clazz, jint ti
197
197
}
198
198
}
199
199
200
- static jint netty_epoll_native_epollWaitNoTimeout (JNIEnv * env , jclass clazz , jint efd , jlong address , jint len , jboolean immediatePoll ) {
200
+ static jint netty_epoll_native_epollWait (JNIEnv * env , jclass clazz , jint efd , jlong address , jint len , jint timeout ) {
201
201
struct epoll_event * ev = (struct epoll_event * ) (intptr_t ) address ;
202
- const int timeout = immediatePoll ? 0 : -1 ;
203
202
int result , err ;
204
203
205
204
do {
@@ -213,47 +212,23 @@ static jint netty_epoll_native_epollWaitNoTimeout(JNIEnv* env, jclass clazz, jin
213
212
214
213
// This method is deprecated!
215
214
static jint netty_epoll_native_epollWait0 (JNIEnv * env , jclass clazz , jint efd , jlong address , jint len , jint timerFd , jint tvSec , jint tvNsec ) {
216
- struct epoll_event * ev = (struct epoll_event * ) (intptr_t ) address ;
217
- int result , err ;
218
-
219
215
if (tvSec == 0 && tvNsec == 0 ) {
220
216
// Zeros = poll (aka return immediately).
221
- do {
222
- result = epoll_wait (efd , ev , len , 0 );
223
- if (result >= 0 ) {
224
- return result ;
225
- }
226
- } while ((err = errno ) == EINTR );
227
- } else {
228
- // only reschedule the timer if there is a newer event.
229
- // -1 is a special value used by EpollEventLoop.
230
- if (tvSec != ((jint ) - 1 ) && tvNsec != ((jint ) - 1 )) {
231
- struct itimerspec ts ;
232
- memset (& ts .it_interval , 0 , sizeof (struct timespec ));
233
- ts .it_value .tv_sec = tvSec ;
234
- ts .it_value .tv_nsec = tvNsec ;
235
- if (timerfd_settime (timerFd , 0 , & ts , NULL ) < 0 ) {
236
- netty_unix_errors_throwChannelExceptionErrorNo (env , "timerfd_settime() failed: " , errno );
237
- return -1 ;
238
- }
239
- }
240
- do {
241
- result = epoll_wait (efd , ev , len , -1 );
242
- if (result > 0 ) {
243
- // Detect timeout, and preserve the epoll_wait API.
244
- if (result == 1 && ev [0 ].data .fd == timerFd ) {
245
- // We assume that timerFD is in ET mode. So we must consume this event to ensure we are notified
246
- // of future timer events because ET mode only notifies a single time until the event is consumed.
247
- uint64_t timerFireCount ;
248
- // We don't care what the result is. We just want to consume the wakeup event and reset ET.
249
- result = read (timerFd , & timerFireCount , sizeof (uint64_t ));
250
- return 0 ;
251
- }
252
- return result ;
253
- }
254
- } while ((err = errno ) == EINTR );
217
+ return netty_epoll_native_epollWait (env , clazz , efd , address , len , 0 );
255
218
}
256
- return - err ;
219
+ // only reschedule the timer if there is a newer event.
220
+ // -1 is a special value used by EpollEventLoop.
221
+ if (tvSec != ((jint ) - 1 ) && tvNsec != ((jint ) - 1 )) {
222
+ struct itimerspec ts ;
223
+ memset (& ts .it_interval , 0 , sizeof (struct timespec ));
224
+ ts .it_value .tv_sec = tvSec ;
225
+ ts .it_value .tv_nsec = tvNsec ;
226
+ if (timerfd_settime (timerFd , 0 , & ts , NULL ) < 0 ) {
227
+ netty_unix_errors_throwChannelExceptionErrorNo (env , "timerfd_settime() failed: " , errno );
228
+ return -1 ;
229
+ }
230
+ }
231
+ return netty_epoll_native_epollWait (env , clazz , efd , address , len , -1 );
257
232
}
258
233
259
234
static inline void cpu_relax () {
@@ -524,7 +499,7 @@ static const JNINativeMethod fixed_method_table[] = {
524
499
{ "timerFdSetTime" , "(III)V" , (void * ) netty_epoll_native_timerFdSetTime },
525
500
{ "epollCreate" , "()I" , (void * ) netty_epoll_native_epollCreate },
526
501
{ "epollWait0" , "(IJIIII)I" , (void * ) netty_epoll_native_epollWait0 }, // This method is deprecated!
527
- { "epollWaitNoTimeout " , "(IJIZ )I" , (void * ) netty_epoll_native_epollWaitNoTimeout },
502
+ { "epollWait " , "(IJII )I" , (void * ) netty_epoll_native_epollWait },
528
503
{ "epollBusyWait0" , "(IJI)I" , (void * ) netty_epoll_native_epollBusyWait0 },
529
504
{ "epollCtlAdd0" , "(III)I" , (void * ) netty_epoll_native_epollCtlAdd0 },
530
505
{ "epollCtlMod0" , "(III)I" , (void * ) netty_epoll_native_epollCtlMod0 },
0 commit comments