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 d2eeca5 Minor fixes, forgotten finals and cleanups d2eeca5 is described below commit d2eeca58416a5cf94473239da691eeeba3e6729a Author: remm <r...@apache.org> AuthorDate: Tue May 14 21:14:20 2019 +0200 Minor fixes, forgotten finals and cleanups --- java/org/apache/tomcat/util/net/AprEndpoint.java | 2 +- java/org/apache/tomcat/util/net/Nio2Endpoint.java | 9 ++++++--- java/org/apache/tomcat/util/net/NioEndpoint.java | 5 ++++- .../apache/tomcat/util/net/SocketWrapperBase.java | 22 ++++++++-------------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java index d5898fe..2d6622f 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -2773,6 +2773,7 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB } private class AprOperationState<A> extends OperationState<A> { + private volatile boolean inline = true; private AprOperationState(boolean read, ByteBuffer[] buffers, int offset, int length, BlockingMode block, long timeout, TimeUnit unit, A attachment, CompletionCheck check, CompletionHandler<Long, ? super A> handler, Semaphore semaphore, @@ -2807,7 +2808,6 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB } return; } - if (!read && flush(false)) { inline = false; registerWriteInterest(); diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java b/java/org/apache/tomcat/util/net/Nio2Endpoint.java index 3c166b9..652644a 100644 --- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java +++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java @@ -469,6 +469,7 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS private final CompletionHandler<Long, ByteBuffer[]> gatheringWriteCompletionHandler; private boolean writeInterest = false; // Guarded by writeCompletionHandler private boolean writeNotify = false; + private volatile boolean closed = false; private CompletionHandler<Integer, SendfileData> sendfileHandler @@ -952,7 +953,7 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS @Override public boolean hasPerOperationTimeout() { - return false; + return true; } @Override @@ -997,8 +998,9 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS public void run() { if (read) { long nBytes = 0; + // Read from main buffer first if (!socketBufferHandler.isReadBufferEmpty()) { - // There is still data inside the main read buffer, use it to fill out the destination buffers + // There is still data inside the main read buffer, it needs to be read first synchronized (readCompletionHandler) { // Note: It is not necessary to put this code in the completion handler socketBufferHandler.configureReadBufferForRead(); @@ -1014,8 +1016,9 @@ public class Nio2Endpoint extends AbstractJsseEndpoint<Nio2Channel,AsynchronousS getSocket().read(buffers, offset, length, timeout, unit, this, completion); } } else { + // Write from main buffer first if (!socketBufferHandler.isWriteBufferEmpty()) { - // First flush the main buffer as needed + // There is still data inside the main write buffer, it needs to be written first socketBufferHandler.configureWriteBufferForRead(); getSocket().write(socketBufferHandler.getWriteBuffer(), null, new CompletionHandler<Integer, Void>() { @Override diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index bdebc73..621d58c 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1426,6 +1426,7 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> } private class NioOperationState<A> extends OperationState<A> { + private volatile boolean inline = true; private NioOperationState(boolean read, ByteBuffer[] buffers, int offset, int length, BlockingMode block, long timeout, TimeUnit unit, A attachment, CompletionCheck check, CompletionHandler<Long, ? super A> handler, Semaphore semaphore, @@ -1478,7 +1479,9 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> // Write from main buffer first if (!socketBufferHandler.isWriteBufferEmpty()) { // There is still data inside the main write buffer, it needs to be written first - doWrite(false); + socketBufferHandler.configureWriteBufferForRead(); + getSocket().write(socketBufferHandler.getWriteBuffer()); + // Start operation only if the main write buffer is now empty if (!socketBufferHandler.isWriteBufferEmpty()) { doWrite = false; } diff --git a/java/org/apache/tomcat/util/net/SocketWrapperBase.java b/java/org/apache/tomcat/util/net/SocketWrapperBase.java index 60e383d..b42c603 100644 --- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java +++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java @@ -1005,7 +1005,6 @@ public abstract class SocketWrapperBase<E> { } protected volatile long nBytes = 0; protected volatile CompletionState state = CompletionState.PENDING; - protected volatile boolean inline = true; protected boolean completionDone = true; /** @@ -1017,7 +1016,7 @@ public abstract class SocketWrapperBase<E> { /** * Process the operation using the connector executor. * @return true if the operation was accepted, false if the executor - * rejected execurtion + * rejected execution */ protected boolean process() { try { @@ -1131,10 +1130,9 @@ public abstract class SocketWrapperBase<E> { } /** - * Allows using NIO2 style read/write only for connectors that can - * efficiently support it. + * Allows using NIO2 style read/write. * - * @return This default implementation always returns {@code false} + * @return {@code true} if the connector has the capability enabled */ public boolean hasAsyncIO() { // The semaphores are only created if async IO is enabled @@ -1281,7 +1279,7 @@ public abstract class SocketWrapperBase<E> { * @param <A> The attachment type * @return the completion state (done, done inline, or still pending) */ - public <A> CompletionState read(ByteBuffer[] dsts, int offset, int length, + public final <A> CompletionState read(ByteBuffer[] dsts, int offset, int length, BlockingMode block, long timeout, TimeUnit unit, A attachment, CompletionCheck check, CompletionHandler<Long, ? super A> handler) { return vectoredOperation(true, dsts, offset, length, block, timeout, unit, attachment, check, handler); @@ -1364,7 +1362,7 @@ public abstract class SocketWrapperBase<E> { * @param <A> The attachment type * @return the completion state (done, done inline, or still pending) */ - public <A> CompletionState write(ByteBuffer[] srcs, int offset, int length, + public final <A> CompletionState write(ByteBuffer[] srcs, int offset, int length, BlockingMode block, long timeout, TimeUnit unit, A attachment, CompletionCheck check, CompletionHandler<Long, ? super A> handler) { return vectoredOperation(false, srcs, offset, length, block, timeout, unit, attachment, check, handler); @@ -1394,7 +1392,7 @@ public abstract class SocketWrapperBase<E> { * @param <A> The attachment type * @return the completion state (done, done inline, or still pending) */ - protected <A> CompletionState vectoredOperation(boolean read, + protected final <A> CompletionState vectoredOperation(boolean read, ByteBuffer[] buffers, int offset, int length, BlockingMode block, long timeout, TimeUnit unit, A attachment, CompletionCheck check, CompletionHandler<Long, ? super A> handler) { @@ -1404,7 +1402,8 @@ public abstract class SocketWrapperBase<E> { return CompletionState.ERROR; } if (timeout == -1) { - timeout = toTimeout(read ? getReadTimeout() : getWriteTimeout()); + timeout = AbstractEndpoint.toTimeout(read ? getReadTimeout() : getWriteTimeout()); + unit = TimeUnit.MILLISECONDS; } else if (!hasPerOperationTimeout() && (unit.toMillis(timeout) != (read ? getReadTimeout() : getWriteTimeout()))) { if (read) { setReadTimeout(unit.toMillis(timeout)); @@ -1467,11 +1466,6 @@ public abstract class SocketWrapperBase<E> { // --------------------------------------------------------- Utility methods - protected static long toTimeout(long timeout) { - // Many calls can't do infinite timeout so use Long.MAX_VALUE if timeout is <= 0 - return (timeout > 0) ? timeout : Long.MAX_VALUE; - } - protected static int transfer(byte[] from, int offset, int length, ByteBuffer to) { int max = Math.min(length, to.remaining()); if (max > 0) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org