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 — Epoll: Correctly delete fd from epoll if there is nothing to handle (… · netty/netty@0ec3d97

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • transport-classes-epoll/src/main/java/io/netty/channel/epoll
    • EpollIoHandler.java
    • EpollIoOps.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollIoHandler.java‎

Copy file name to clipboardExpand all lines: transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollIoHandler.java
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,21 @@ public long submit(IoOps ops) {
261261
case Cancelled:
262262
return -1;
263263
case Pending:
264+
if (epollIoOps.value == EpollIoOps.NONE.value) {
265+
// 0 is a special value that basically means we should remove the registration.
266+
// As we did not add the fd yet we should just return.
267+
return 0;
268+
}
264269
Native.epollCtlAdd(epollFd.intValue(), handle.fd().intValue(), epollIoOps.value);
265270
state = RegistrationState.Added;
271+
return epollIoOps.value;
266272
case Added:
273+
if (epollIoOps.value == EpollIoOps.NONE.value) {
274+
// 0 means there is nothing to handle anymore, unregister the fd as otherwise
275+
// we might get notified forever because of EPOLLHUP / EPOLLERR.
276+
Native.epollCtlDel(epollFd.intValue(), handle.fd().intValue());
277+
return 0;
278+
}
267279
Native.epollCtlMod(epollFd.intValue(), handle.fd().intValue(), epollIoOps.value);
268280
return epollIoOps.value;
269281
default:
Collapse file

‎transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollIoOps.java‎

Copy file name to clipboardExpand all lines: transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollIoOps.java
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public final class EpollIoOps implements IoOps {
5151

5252
public static final EpollIoOps EPOLLET = new EpollIoOps(Native.EPOLLET);
5353

54+
/**
55+
* Special {@link EpollIoOps} which basically means we are not interested in any event and so should remove the
56+
* fd from underlying epoll fd.
57+
*/
58+
public static final EpollIoOps NONE = new EpollIoOps(0);
59+
5460
static final int EPOLL_ERR_OUT_MASK = EpollIoOps.EPOLLERR.value | EpollIoOps.EPOLLOUT.value;
5561
static final int EPOLL_ERR_IN_MASK = EpollIoOps.EPOLLERR.value | EpollIoOps.EPOLLIN.value;
5662
static final int EPOLL_RDHUP_MASK = EpollIoOps.EPOLLRDHUP.value;
@@ -60,7 +66,8 @@ public final class EpollIoOps implements IoOps {
6066

6167
static {
6268
EpollIoOps all = new EpollIoOps(EPOLLOUT.value | EPOLLIN.value | EPOLLERR.value | EPOLLRDHUP.value);
63-
EVENTS = new EpollIoEvent[all.value + 1];
69+
EVENTS = new EpollIoEvent[all.value + 2];
70+
addToArray(EVENTS, NONE);
6471
addToArray(EVENTS, EPOLLOUT);
6572
addToArray(EVENTS, EPOLLIN);
6673
addToArray(EVENTS, EPOLLERR);

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.