This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new fef2d26ccf NIO writes don't return -1 so neither should CLOSED_NIO_CHANNEL fef2d26ccf is described below commit fef2d26ccf35b6935c9adcedcfe3093a4f6c2e34 Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Nov 7 13:32:20 2022 +0000 NIO writes don't return -1 so neither should CLOSED_NIO_CHANNEL --- java/org/apache/catalina/tribes/transport/nio/NioSender.java | 4 ---- java/org/apache/tomcat/util/net/NioChannel.java | 5 +++-- java/org/apache/tomcat/util/net/NioEndpoint.java | 7 +------ webapps/docs/changelog.xml | 5 +++++ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/java/org/apache/catalina/tribes/transport/nio/NioSender.java b/java/org/apache/catalina/tribes/transport/nio/NioSender.java index 252dc4d183..82e7149222 100644 --- a/java/org/apache/catalina/tribes/transport/nio/NioSender.java +++ b/java/org/apache/catalina/tribes/transport/nio/NioSender.java @@ -16,7 +16,6 @@ */ package org.apache.catalina.tribes.transport.nio; -import java.io.EOFException; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; @@ -206,9 +205,6 @@ public class NioSender extends AbstractSender { //we have written everything, or we are starting a new package //protect against buffer overwrite int byteswritten = isUdpBased()?dataChannel.write(writebuf) : socketChannel.write(writebuf); - if (byteswritten == -1 ) { - throw new EOFException(); - } remaining -= byteswritten; //if the entire message was written from the buffer //reset the position counter diff --git a/java/org/apache/tomcat/util/net/NioChannel.java b/java/org/apache/tomcat/util/net/NioChannel.java index ac46d76753..8e3cb4f0e1 100644 --- a/java/org/apache/tomcat/util/net/NioChannel.java +++ b/java/org/apache/tomcat/util/net/NioChannel.java @@ -19,6 +19,7 @@ package org.apache.tomcat.util.net; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.ByteChannel; +import java.nio.channels.ClosedChannelException; import java.nio.channels.GatheringByteChannel; import java.nio.channels.ScatteringByteChannel; import java.nio.channels.Selector; @@ -278,12 +279,12 @@ public class NioChannel implements ByteChannel, ScatteringByteChannel, Gathering @Override public int write(ByteBuffer src) throws IOException { checkInterruptStatus(); - return -1; + throw new ClosedChannelException(); } @Override public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { - return -1L; + throw new ClosedChannelException(); } @Override public String toString() { diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 2c4cde8bc9..74e75d744b 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1322,9 +1322,7 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> } } n = getSocket().write(buffer); - if (n == -1) { - throw new EOFException(); - } else if (n == 0 && (buffer.hasRemaining() || getSocket().getOutboundRemaining() > 0)) { + if (n == 0 && (buffer.hasRemaining() || getSocket().getOutboundRemaining() > 0)) { // n == 0 could be an incomplete write but it could also // indicate that a previous incomplete write of the // outbound buffer (for TLS) has now completed. Only @@ -1355,9 +1353,6 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> } else { do { n = getSocket().write(buffer); - if (n == -1) { - throw new EOFException(); - } } while (n > 0 && buffer.hasRemaining()); // If there is data left in the buffer the socket will be registered for // write further up the stack. This is to ensure the socket is only diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index aea7fc4a18..f501abd8c4 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -137,6 +137,11 @@ stream is cancelled due to an attempt to write to the stream when it is in a state that does not permit writes. (markt) </add> + <scode> + NIO writes never return -1 so refactor <code>CLOSED_NIO_CHANNEL</code> + not to do so and remove checks for this return value. Based on + <pr>562</pr> by tianshuang. (markt) + </scode> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org