This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new cc7c12993b NIO writes don't return -1 so neither should CLOSED_NIO_CHANNEL cc7c12993b is described below commit cc7c12993bb43bafbdcc209d145e65e32025e3ab 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 9a22906914..d263ce9ae6 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.SocketChannel; @@ -260,12 +261,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 bdc534263e..7bad146bcf 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1372,9 +1372,7 @@ public class NioEndpoint extends AbstractNetworkChannelEndpoint<NioChannel,Socke } } 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 @@ -1405,9 +1403,6 @@ public class NioEndpoint extends AbstractNetworkChannelEndpoint<NioChannel,Socke } 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 2c6bde9208..da5668d3f5 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -154,6 +154,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