This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 339b40b The closed channels need to be immutable so override a few
more methods
339b40b is described below
commit 339b40bc07bdba9ded565929b9a3448c5a78f015
Author: remm <[email protected]>
AuthorDate: Wed May 29 16:23:03 2019 +0200
The closed channels need to be immutable so override a few more methods
Avoiding a NPE in NioBlockignSelector is not possible however and
getting there is wasteful, so filter out read as well. In theory ==
CLOSED_NIO_CHANNEL would be enough but use instanceof for now.
---
java/org/apache/tomcat/util/net/Nio2Channel.java | 5 ++++-
java/org/apache/tomcat/util/net/NioChannel.java | 13 +++++++++++--
java/org/apache/tomcat/util/net/NioEndpoint.java | 9 ++++++---
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/java/org/apache/tomcat/util/net/Nio2Channel.java
b/java/org/apache/tomcat/util/net/Nio2Channel.java
index 36c5b99..f6b9f0c 100644
--- a/java/org/apache/tomcat/util/net/Nio2Channel.java
+++ b/java/org/apache/tomcat/util/net/Nio2Channel.java
@@ -251,7 +251,7 @@ public class Nio2Channel implements AsynchronousByteChannel
{
static final Nio2Channel CLOSED_NIO2_CHANNEL = new ClosedNio2Channel();
public static class ClosedNio2Channel extends Nio2Channel {
public ClosedNio2Channel() {
- super(null);
+ super(SocketBufferHandler.EMPTY);
}
@Override
public void close() throws IOException {
@@ -267,6 +267,9 @@ public class Nio2Channel implements AsynchronousByteChannel
{
public void free() {
}
@Override
+ public void setAppReadBufHandler(ApplicationBufferHandler handler) {
+ }
+ @Override
public Future<Integer> read(ByteBuffer dst) {
return DONE_INT;
}
diff --git a/java/org/apache/tomcat/util/net/NioChannel.java
b/java/org/apache/tomcat/util/net/NioChannel.java
index d3f2766..1de1e80 100644
--- a/java/org/apache/tomcat/util/net/NioChannel.java
+++ b/java/org/apache/tomcat/util/net/NioChannel.java
@@ -246,7 +246,6 @@ public class NioChannel implements ByteChannel,
ScatteringByteChannel, Gathering
}
}
-
private ApplicationBufferHandler appReadBufHandler;
public void setAppReadBufHandler(ApplicationBufferHandler handler) {
this.appReadBufHandler = handler;
@@ -258,7 +257,7 @@ public class NioChannel implements ByteChannel,
ScatteringByteChannel, Gathering
static final NioChannel CLOSED_NIO_CHANNEL = new ClosedNioChannel();
public static class ClosedNioChannel extends NioChannel {
public ClosedNioChannel() {
- super(null, null);
+ super(null, SocketBufferHandler.EMPTY);
}
@Override
public void close() throws IOException {
@@ -274,6 +273,15 @@ public class NioChannel implements ByteChannel,
ScatteringByteChannel, Gathering
public void free() {
}
@Override
+ void setSocketWrapper(NioSocketWrapper socketWrapper) {
+ }
+ @Override
+ public void setIOChannel(SocketChannel sc) {
+ }
+ @Override
+ public void setAppReadBufHandler(ApplicationBufferHandler handler) {
+ }
+ @Override
public int read(ByteBuffer dst) throws IOException {
return -1;
}
@@ -297,4 +305,5 @@ public class NioChannel implements ByteChannel,
ScatteringByteChannel, Gathering
return "Closed NioChannel";
}
}
+
}
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java
b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 765935e..68f401a 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -1215,7 +1215,10 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
private int fillReadBuffer(boolean block, ByteBuffer to) throws
IOException {
int nRead;
- NioChannel channel = getSocket();
+ NioChannel socket = getSocket();
+ if (socket instanceof ClosedNioChannel) {
+ throw new ClosedChannelException();
+ }
if (block) {
Selector selector = null;
try {
@@ -1224,14 +1227,14 @@ public class NioEndpoint extends
AbstractJsseEndpoint<NioChannel,SocketChannel>
// Ignore
}
try {
- nRead = pool.read(to, channel, selector, getReadTimeout());
+ nRead = pool.read(to, socket, selector, getReadTimeout());
} finally {
if (selector != null) {
pool.put(selector);
}
}
} else {
- nRead = channel.read(to);
+ nRead = socket.read(to);
if (nRead == -1) {
throw new EOFException();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]