Skip to content

Commit

Permalink
[netty#2361] Native.epollCreate(...) fails on systems using a kernel …
Browse files Browse the repository at this point in the history
…< 2.6.27 / glibc < 2.9

Motivation:
Native.epollCreate(...) fails on systems using a kernel < 2.6.27 / glibc < 2.9 because it uses epoll_create1(...) without checking if it is present

Modifications:
Check if epoll_create1(...) exists abd if not fall back to use epoll_create(...)

Result:
Works even on systems with kernel < 2.6.27 / glibc < 2.9
  • Loading branch information
Norman Maurer committed Apr 4, 2014
1 parent 3eec26b commit 2fa79b2
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

// optional
extern int accept4(int sockFd, struct sockaddr *addr, socklen_t *addrlen, int flags) __attribute__((weak));
extern int epoll_create1(int flags) __attribute__((weak));

// Those are initialized in the init(...) method and cached for performance reasons
jmethodID updatePosId = NULL;
Expand Down Expand Up @@ -401,11 +402,25 @@ JNIEXPORT void JNICALL Java_io_netty_channel_epoll_Native_eventFdRead(JNIEnv * e
}

JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_epollCreate(JNIEnv * env, jclass clazz) {
jint efd = epoll_create1(EPOLL_CLOEXEC);
jint efd;
if (epoll_create1) {
efd = epoll_create1(EPOLL_CLOEXEC);
} else {
// size will be ignored anyway but must be positive
efd = epoll_create(126);
}
if (efd < 0) {
int err = errno;
throwRuntimeException(env, exceptionMessage("Error during epoll_create(...): ", err));
}
if (!epoll_create1) {
if (fcntl(efd, F_SETFD, FD_CLOEXEC) < 0) {
int err = errno;
close(efd);
throwRuntimeException(env, exceptionMessage("Error during fcntl(...): ", err));
return err;
}
}
return efd;
}

Expand Down

0 comments on commit 2fa79b2

Please sign in to comment.