From eb143d6d6ecddb27aab4047531520225ee36abee Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 19 Feb 2014 11:57:41 +0100 Subject: [PATCH] Correctly handle remove from epoll and EPOLLRDHUP. Also fix a bug with removing EPOLLIN and EPOLLOUT --- .../java/io/netty/channel/epoll/AbstractEpollChannel.java | 6 +++++- .../java/io/netty/channel/epoll/EpollSocketChannel.java | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java index 831f78f748..e2078d3880 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollChannel.java @@ -65,6 +65,10 @@ abstract class AbstractEpollChannel extends AbstractChannel { @Override protected void doClose() throws Exception { active = false; + + // deregister from epoll now + doDeregister(); + int fd = this.fd; this.fd = -1; Native.close(fd); @@ -110,7 +114,7 @@ abstract class AbstractEpollChannel extends AbstractChannel { protected final void clearEpollIn() { if ((flags & readFlag) != 0) { - flags = ~readFlag; + flags &= ~readFlag; ((EpollEventLoop) eventLoop()).modify(this); } } diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java index cb00276f6e..10d755fd6c 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannel.java @@ -101,7 +101,7 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So private void clearEpollOut() { if ((flags & Native.EPOLLOUT) != 0) { - flags = ~Native.EPOLLOUT; + flags &= ~Native.EPOLLOUT; ((EpollEventLoop) eventLoop()).modify(this); } } @@ -528,7 +528,11 @@ public final class EpollSocketChannel extends AbstractEpollChannel implements So @Override void epollRdHupReady() { - closeOnRead(pipeline()); + if (isActive()) { + epollInReady(); + } else { + closeOnRead(pipeline()); + } } @Override