You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2017/03/09 12:26:34 UTC
svn commit: r1786153 - in /tomcat/trunk/java/org/apache/tomcat/util/net:
Nio2Endpoint.java SocketWrapperBase.java
Author: remm
Date: Thu Mar 9 12:26:34 2017
New Revision: 1786153
URL: http://svn.apache.org/viewvc?rev=1786153&view=rev
Log:
Add blocking mode tweak, as I accidentally found out blocking does make a difference.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1786153&r1=1786152&r2=1786153&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Thu Mar 9 12:26:34 2017
@@ -971,9 +971,9 @@ public class Nio2Endpoint extends Abstra
@Override
public <A> CompletionState read(ByteBuffer[] dsts, int offset, int length,
- boolean block, long timeout, TimeUnit unit, A attachment,
+ BlockingMode block, long timeout, TimeUnit unit, A attachment,
CompletionCheck check, CompletionHandler<Long, ? super A> handler) {
- if (block) {
+ if (block != BlockingMode.NON_BLOCK) {
try {
if (!readPending.tryAcquire(timeout, unit)) {
handler.failed(new SocketTimeoutException(), attachment);
@@ -992,7 +992,7 @@ public class Nio2Endpoint extends Abstra
Nio2Endpoint.startInline();
getSocket().read(dsts, offset, length, timeout, unit, state, new ScatterReadCompletionHandler<>());
Nio2Endpoint.endInline();
- if (block && state.state == CompletionState.PENDING) {
+ if (block == BlockingMode.BLOCK && state.state == CompletionState.PENDING) {
if (!awaitReadComplete(timeout, unit)) {
handler.failed(new SocketTimeoutException(), attachment);
return CompletionState.ERROR;
@@ -1010,9 +1010,9 @@ public class Nio2Endpoint extends Abstra
@Override
public <A> CompletionState write(ByteBuffer[] srcs, int offset, int length,
- boolean block, long timeout, TimeUnit unit, A attachment,
+ BlockingMode block, long timeout, TimeUnit unit, A attachment,
CompletionCheck check, CompletionHandler<Long, ? super A> handler) {
- if (block) {
+ if (block != BlockingMode.NON_BLOCK) {
try {
if (!writePending.tryAcquire(timeout, unit)) {
handler.failed(new SocketTimeoutException(), attachment);
@@ -1031,7 +1031,7 @@ public class Nio2Endpoint extends Abstra
Nio2Endpoint.startInline();
getSocket().write(srcs, offset, length, timeout, unit, state, new GatherWriteCompletionHandler<>());
Nio2Endpoint.endInline();
- if (block && state.state == CompletionState.PENDING) {
+ if (block == BlockingMode.BLOCK && state.state == CompletionState.PENDING) {
if (!awaitWriteComplete(timeout, unit)) {
handler.failed(new SocketTimeoutException(), attachment);
return CompletionState.ERROR;
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java?rev=1786153&r1=1786152&r2=1786153&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java Thu Mar 9 12:26:34 2017
@@ -764,6 +764,23 @@ public abstract class SocketWrapperBase<
// ------------------------------------------------------- NIO 2 style APIs
+ public enum BlockingMode {
+ /**
+ * The operation will now block. If there are pending operations,
+ * the operation will return CompletionState.NOT_DONE.
+ */
+ NON_BLOCK,
+ /**
+ * The operation will block until pending operations are completed, but
+ * will not block after performing it.
+ */
+ SEMI_BLOCK,
+ /**
+ * The operation will block until completed.
+ */
+ BLOCK
+ }
+
public enum CompletionState {
/**
* Operation is still pending.
@@ -921,11 +938,7 @@ public abstract class SocketWrapperBase<
* behavior is used: the completion handler will be called as soon
* as some data has been read, even if the read has completed inline.
*
- * @param block true to block until any pending read is done, if the
- * timeout occurs and a read is still pending, a
- * ReadPendingException will be thrown; false to
- * not block but any pending read operation will cause
- * a ReadPendingException
+ * @param block is the blocking mode that will be used for this operation
* @param timeout timeout duration for the read
* @param unit units for the timeout duration
* @param attachment an object to attach to the I/O operation that will be
@@ -936,8 +949,9 @@ public abstract class SocketWrapperBase<
* @param <A> The attachment type
* @return the completion state (done, done inline, or still pending)
*/
- public final <A> CompletionState read(boolean block, long timeout, TimeUnit unit, A attachment,
- CompletionCheck check, CompletionHandler<Long, ? super A> handler, ByteBuffer... dsts) {
+ public final <A> CompletionState read(BlockingMode block, long timeout,
+ TimeUnit unit, A attachment, CompletionCheck check,
+ CompletionHandler<Long, ? super A> handler, ByteBuffer... dsts) {
if (dsts == null) {
throw new IllegalArgumentException();
}
@@ -956,11 +970,7 @@ public abstract class SocketWrapperBase<
* @param dsts buffers
* @param offset in the buffer array
* @param length in the buffer array
- * @param block true to block until any pending read is done, if the
- * timeout occurs and a read is still pending, a
- * ReadPendingException will be thrown; false to
- * not block but any pending read operation will cause
- * a ReadPendingException
+ * @param block is the blocking mode that will be used for this operation
* @param timeout timeout duration for the read
* @param unit units for the timeout duration
* @param attachment an object to attach to the I/O operation that will be
@@ -970,9 +980,9 @@ public abstract class SocketWrapperBase<
* @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, boolean block,
- long timeout, TimeUnit unit, A attachment, CompletionCheck check,
- CompletionHandler<Long, ? super A> handler) {
+ public <A> CompletionState read(ByteBuffer[] dsts, int offset, int length,
+ BlockingMode block, long timeout, TimeUnit unit, A attachment,
+ CompletionCheck check, CompletionHandler<Long, ? super A> handler) {
throw new UnsupportedOperationException();
}
@@ -986,11 +996,7 @@ public abstract class SocketWrapperBase<
* if the write is incomplete and data remains in the buffers, or
* if the write completed inline.
*
- * @param block true to block until any pending write is done, if the
- * timeout occurs and a write is still pending, a
- * WritePendingException will be thrown; false to
- * not block but any pending write operation will cause
- * a WritePendingException
+ * @param block is the blocking mode that will be used for this operation
* @param timeout timeout duration for the write
* @param unit units for the timeout duration
* @param attachment an object to attach to the I/O operation that will be
@@ -1001,8 +1007,9 @@ public abstract class SocketWrapperBase<
* @param <A> The attachment type
* @return the completion state (done, done inline, or still pending)
*/
- public final <A> CompletionState write(boolean block, long timeout, TimeUnit unit, A attachment,
- CompletionCheck check, CompletionHandler<Long, ? super A> handler, ByteBuffer... srcs) {
+ public final <A> CompletionState write(BlockingMode block, long timeout,
+ TimeUnit unit, A attachment, CompletionCheck check,
+ CompletionHandler<Long, ? super A> handler, ByteBuffer... srcs) {
if (srcs == null) {
throw new IllegalArgumentException();
}
@@ -1022,11 +1029,7 @@ public abstract class SocketWrapperBase<
* @param srcs buffers
* @param offset in the buffer array
* @param length in the buffer array
- * @param block true to block until any pending write is done, if the
- * timeout occurs and a write is still pending, a
- * WritePendingException will be thrown; false to
- * not block but any pending write operation will cause
- * a WritePendingException
+ * @param block is the blocking mode that will be used for this operation
* @param timeout timeout duration for the write
* @param unit units for the timeout duration
* @param attachment an object to attach to the I/O operation that will be
@@ -1036,9 +1039,9 @@ public abstract class SocketWrapperBase<
* @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, boolean block,
- long timeout, TimeUnit unit, A attachment, CompletionCheck check,
- CompletionHandler<Long, ? super A> handler) {
+ public <A> CompletionState write(ByteBuffer[] srcs, int offset, int length,
+ BlockingMode block, long timeout, TimeUnit unit, A attachment,
+ CompletionCheck check, CompletionHandler<Long, ? super A> handler) {
throw new UnsupportedOperationException();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org