GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix Incorrect nanos-to-millis conversion in epoll_wait EINTR retry lo… · netty/netty@d22b216

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • transport-native-epoll/src
    • main/c
      • netty_epoll_native.c
    • test/java/io/netty/channel/epoll
      • EpollTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎transport-native-epoll/src/main/c/netty_epoll_native.c‎

Copy file name to clipboardExpand all lines: transport-native-epoll/src/main/c/netty_epoll_native.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static inline jint netty_epoll_wait(JNIEnv* env, jint efd, struct epoll_event *e
269269
netty_unix_errors_throwRuntimeExceptionErrorNo(env, "clock_gettime() failed: ", errno);
270270
return -1;
271271
}
272-
deadline = ts.tv_sec * 1000 + ts.tv_nsec / 1000 + timeout;
272+
deadline = ts.tv_sec * 1000 + ts.tv_nsec / 1000000 + timeout;
273273

274274
while ((rc = epoll_wait(efd, ev, len, timeout)) < 0) {
275275
if (errno != EINTR) {
@@ -281,7 +281,7 @@ static inline jint netty_epoll_wait(JNIEnv* env, jint efd, struct epoll_event *e
281281
return -1;
282282
}
283283

284-
now = ts.tv_sec * 1000 + ts.tv_nsec / 1000;
284+
now = ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
285285
if (now >= deadline) {
286286
return 0;
287287
}
Collapse file

‎transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollTest.java‎

Copy file name to clipboardExpand all lines: transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollTest.java
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.concurrent.TimeUnit;
2323
import java.util.concurrent.atomic.AtomicReference;
2424

25+
import static org.assertj.core.api.Assertions.assertThat;
2526
import static org.junit.jupiter.api.Assertions.assertEquals;
2627
import static org.junit.jupiter.api.Assertions.assertNull;
2728
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -33,6 +34,29 @@ public void testIsAvailable() {
3334
assertTrue(Epoll.isAvailable());
3435
}
3536

37+
@Test
38+
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)
39+
public void testEpollWaitTimeoutAccuracy() throws Exception {
40+
final int timeoutMs = 200;
41+
final FileDescriptor epoll = Native.newEpollCreate();
42+
final EpollEventArray eventArray = new EpollEventArray(8);
43+
try {
44+
long startNs = System.nanoTime();
45+
// No fds registered, so this will just wait for the timeout.
46+
int ready = Native.epollWait(epoll, eventArray, timeoutMs);
47+
long elapsedMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
48+
49+
assertEquals(0, ready);
50+
// Should have waited at least close to the timeout
51+
assertThat(elapsedMs).isGreaterThanOrEqualTo(timeoutMs - 20);
52+
// Should not have waited vastly longer than the timeout
53+
assertThat(elapsedMs).isLessThan(timeoutMs + 200);
54+
} finally {
55+
eventArray.free();
56+
epoll.close();
57+
}
58+
}
59+
3660
// Testcase for https://github.com/netty/netty/issues/8444
3761
@Test
3862
@Timeout(value = 5000, unit = TimeUnit.MILLISECONDS)

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.