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
commit 6752a0b60fdc0f706392ba285e36ce8439115624 Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Feb 18 00:19:33 2022 +0000 Align with 9.0.x onwards - refactor timeoute --- java/org/apache/tomcat/util/net/NioEndpoint.java | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 4306052..6f31c0c 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1141,25 +1141,38 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> processKey(key, socketWrapper); } else if ((socketWrapper.interestOps() & SelectionKey.OP_READ) == SelectionKey.OP_READ || (socketWrapper.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) { - boolean isTimedOut = false; + boolean readTimeout = false; + boolean writeTimeout = false; // Check for read timeout if ((socketWrapper.interestOps() & SelectionKey.OP_READ) == SelectionKey.OP_READ) { long delta = now - socketWrapper.getLastRead(); long timeout = socketWrapper.getReadTimeout(); - isTimedOut = timeout > 0 && delta > timeout; + if (timeout > 0 && delta > timeout) { + readTimeout = true; + } } // Check for write timeout - if (!isTimedOut && (socketWrapper.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) { + if (!readTimeout && (socketWrapper.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) { long delta = now - socketWrapper.getLastWrite(); long timeout = socketWrapper.getWriteTimeout(); - isTimedOut = timeout > 0 && delta > timeout; + if (timeout > 0 && delta > timeout) { + writeTimeout = true; + } } - if (isTimedOut) { + if (readTimeout || writeTimeout) { key.interestOps(0); // Avoid duplicate timeout calls socketWrapper.interestOps(0); socketWrapper.setError(new SocketTimeoutException()); - if (!processSocket(socketWrapper, SocketEvent.ERROR, true)) { + if (readTimeout && socketWrapper.readOperation != null) { + if (!socketWrapper.readOperation.process()) { + cancelledKey(key); + } + } else if (writeTimeout && socketWrapper.writeOperation != null) { + if (!socketWrapper.writeOperation.process()) { + cancelledKey(key); + } + } else if (!processSocket(socketWrapper, SocketEvent.ERROR, true)) { cancelledKey(key); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org