Add workaround for bug in older linux kernels handling epoll_wait(...)
Motivation: Older linux kernels have problems handling a large value for epoll_wait(...) and so wait for ever. Modifications: Adjust timeout on the fly if a too big value is passed in. Result: Correctly works also on older kernels.
This commit is contained in:
parent
4d0eeb0dcc
commit
795de8a590
@ -33,6 +33,17 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "io_netty_channel_epoll_Native.h"
|
#include "io_netty_channel_epoll_Native.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On older Linux kernels, epoll can't handle timeout
|
||||||
|
* values bigger than (LONG_MAX - 999ULL)/HZ.
|
||||||
|
*
|
||||||
|
* See:
|
||||||
|
* - https://github.com/libevent/libevent/blob/master/epoll.c#L138
|
||||||
|
* - http://cvs.schmorp.de/libev/ev_epoll.c?revision=1.68&view=markup
|
||||||
|
*/
|
||||||
|
#define MAX_EPOLL_TIMEOUT_MSEC (35*60*1000)
|
||||||
|
|
||||||
// optional
|
// optional
|
||||||
extern int accept4(int sockFd, struct sockaddr* addr, socklen_t* addrlen, int flags) __attribute__((weak));
|
extern int accept4(int sockFd, struct sockaddr* addr, socklen_t* addrlen, int flags) __attribute__((weak));
|
||||||
extern int epoll_create1(int flags) __attribute__((weak));
|
extern int epoll_create1(int flags) __attribute__((weak));
|
||||||
@ -617,6 +628,11 @@ JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_epollWait0(JNIEnv* env
|
|||||||
struct epoll_event *ev = (struct epoll_event*) address;
|
struct epoll_event *ev = (struct epoll_event*) address;
|
||||||
int ready;
|
int ready;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (timeout > MAX_EPOLL_TIMEOUT_MSEC) {
|
||||||
|
// Workaround for bug in older linux kernels that can not handle bigger timeout then MAX_EPOLL_TIMEOUT_MSEC.
|
||||||
|
timeout = MAX_EPOLL_TIMEOUT_MSEC;
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
ready = epoll_wait(efd, ev, len, timeout);
|
ready = epoll_wait(efd, ev, len, timeout);
|
||||||
// was interrupted try again.
|
// was interrupted try again.
|
||||||
|
Loading…
Reference in New Issue
Block a user