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 67e70a2 Align with 9.0.x onwards - Prep for backporting socket close changes 67e70a2 is described below commit 67e70a2fbe2b9d777406e33b3317267419414332 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Feb 17 15:39:15 2022 +0000 Align with 9.0.x onwards - Prep for backporting socket close changes --- .../tomcat/util/net/ApplicationBufferHandler.java | 15 ++++ java/org/apache/tomcat/util/net/Nio2Channel.java | 85 ++++++++++++++++++++++ java/org/apache/tomcat/util/net/WriteBuffer.java | 3 + 3 files changed, 103 insertions(+) diff --git a/java/org/apache/tomcat/util/net/ApplicationBufferHandler.java b/java/org/apache/tomcat/util/net/ApplicationBufferHandler.java index d9a22ed..8362416 100644 --- a/java/org/apache/tomcat/util/net/ApplicationBufferHandler.java +++ b/java/org/apache/tomcat/util/net/ApplicationBufferHandler.java @@ -24,6 +24,21 @@ import java.nio.ByteBuffer; */ public interface ApplicationBufferHandler { + static final ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0); + + static ApplicationBufferHandler EMPTY = new ApplicationBufferHandler() { + @Override + public void expand(int newSize) { + } + @Override + public void setByteBuffer(ByteBuffer buffer) { + } + @Override + public ByteBuffer getByteBuffer() { + return EMPTY_BUFFER; + } + }; + public void setByteBuffer(ByteBuffer buffer); public ByteBuffer getByteBuffer(); diff --git a/java/org/apache/tomcat/util/net/Nio2Channel.java b/java/org/apache/tomcat/util/net/Nio2Channel.java index f5dd0f3..a22b7ab 100644 --- a/java/org/apache/tomcat/util/net/Nio2Channel.java +++ b/java/org/apache/tomcat/util/net/Nio2Channel.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.AsynchronousByteChannel; import java.nio.channels.AsynchronousSocketChannel; +import java.nio.channels.ClosedChannelException; import java.nio.channels.CompletionHandler; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -220,4 +221,88 @@ public class Nio2Channel implements AsynchronousByteChannel { protected ApplicationBufferHandler getAppReadBufHandler() { return appReadBufHandler; } + + private static final Future<Integer> DONE_INT = new Future<Integer>() { + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + @Override + public boolean isCancelled() { + return false; + } + @Override + public boolean isDone() { + return true; + } + @Override + public Integer get() throws InterruptedException, + ExecutionException { + return Integer.valueOf(-1); + } + @Override + public Integer get(long timeout, TimeUnit unit) + throws InterruptedException, ExecutionException, + TimeoutException { + return Integer.valueOf(-1); + } + }; + + static final Nio2Channel CLOSED_NIO2_CHANNEL = new Nio2Channel(SocketBufferHandler.EMPTY) { + @Override + public void close() throws IOException { + } + @Override + public boolean isOpen() { + return false; + } + @Override + public void reset(AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socket) throws IOException { + } + @Override + public void free() { + } + @Override + protected ApplicationBufferHandler getAppReadBufHandler() { + return ApplicationBufferHandler.EMPTY; + } + @Override + public void setAppReadBufHandler(ApplicationBufferHandler handler) { + } + @Override + public Future<Integer> read(ByteBuffer dst) { + return DONE_INT; + } + @Override + public <A> void read(ByteBuffer dst, + long timeout, TimeUnit unit, A attachment, + CompletionHandler<Integer, ? super A> handler) { + handler.failed(new ClosedChannelException(), attachment); + } + @Override + public <A> void read(ByteBuffer[] dsts, + int offset, int length, long timeout, TimeUnit unit, + A attachment, CompletionHandler<Long,? super A> handler) { + handler.failed(new ClosedChannelException(), attachment); + } + @Override + public Future<Integer> write(ByteBuffer src) { + return DONE_INT; + } + @Override + public <A> void write(ByteBuffer src, long timeout, TimeUnit unit, A attachment, + CompletionHandler<Integer, ? super A> handler) { + handler.failed(new ClosedChannelException(), attachment); + } + @Override + public <A> void write(ByteBuffer[] srcs, int offset, int length, + long timeout, TimeUnit unit, A attachment, + CompletionHandler<Long,? super A> handler) { + handler.failed(new ClosedChannelException(), attachment); + } + @Override + public String toString() { + return "Closed Nio2Channel"; + } + }; } diff --git a/java/org/apache/tomcat/util/net/WriteBuffer.java b/java/org/apache/tomcat/util/net/WriteBuffer.java index 82e36c5..fa6599d 100644 --- a/java/org/apache/tomcat/util/net/WriteBuffer.java +++ b/java/org/apache/tomcat/util/net/WriteBuffer.java @@ -43,6 +43,9 @@ public class WriteBuffer { this.bufferSize = bufferSize; } + void clear() { + buffers.clear(); + } void add(byte[] buf, int offset, int length) { ByteBufferHolder holder = getByteBufferHolder(length); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org