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 2015/10/27 16:16:04 UTC
svn commit: r1710835 - in /tomcat/trunk/java/org/apache/tomcat/util/net:
Nio2Endpoint.java SocketWrapperBase.java
Author: remm
Date: Tue Oct 27 15:16:04 2015
New Revision: 1710835
URL: http://svn.apache.org/viewvc?rev=1710835&view=rev
Log:
- Add an extra async IO flag I used for testing.
- Blocking should block.
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=1710835&r1=1710834&r2=1710835&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Tue Oct 27 15:16:04 2015
@@ -954,6 +954,11 @@ public class Nio2Endpoint extends Abstra
}
}
+ @Override
+ public boolean hasAsyncIO() {
+ return false;
+ }
+
/**
* Internal state tracker for scatter/gather operations.
*/
@@ -978,8 +983,8 @@ public class Nio2Endpoint extends Abstra
this.check = check;
this.handler = handler;
}
- private long nBytes = 0;
- private CompletionState state = CompletionState.PENDING;
+ private volatile long nBytes = 0;
+ private volatile CompletionState state = CompletionState.PENDING;
}
private class ScatterReadCompletionHandler<A> implements CompletionHandler<Long, OperationState<A>> {
@@ -1127,6 +1132,9 @@ public class Nio2Endpoint extends Abstra
} else {
throw new WritePendingException();
}
+ if (block && state.state == CompletionState.PENDING && writePending.tryAcquire(timeout, unit)) {
+ writePending.release();
+ }
} catch (InterruptedException e) {
handler.failed(e, attachment);
}
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=1710835&r1=1710834&r2=1710835&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java Tue Oct 27 15:16:04 2015
@@ -662,6 +662,14 @@ public abstract class SocketWrapperBase<
};
/**
+ * Allows using NIO2 style read/write only for connectors that can
+ * efficiently support it.
+ */
+ public boolean hasAsyncIO() {
+ return false;
+ }
+
+ /**
* Scatter read. The completion handler will be called once some
* data has been read or an error occurred. If a CompletionCheck
* object has been provided, the completion handler will only be
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1710835 - in /tomcat/trunk/java/org/apache/tomcat/util/net:
Nio2Endpoint.java SocketWrapperBase.java
Posted by Rémy Maucherat <re...@apache.org>.
2015-10-27 16:16 GMT+01:00 <re...@apache.org>:
> Author: remm
> Date: Tue Oct 27 15:16:04 2015
> New Revision: 1710835
>
> URL: http://svn.apache.org/viewvc?rev=1710835&view=rev
> Log:
> - Add an extra async IO flag I used for testing.
> - Blocking should block.
>
> It's possible I'll remove this code eventually.
SSL really gets in the way of possible gather optimizations (it wants a
direct buffer), and scatter is hard to use. I now think it will perform
worse. However, this sort of API could be used to produce a true async impl
of HTTP/2, while the current one is async/blocking, and also do away with
the plumbing for IO dispatches (they are a completion handler invocation,
end of story) and state tracking needed to avoid a true async impl.
Example (writing the GOAWAY frame):
try {
synchronized (socketWrapper) {
socketWrapper.write(true, payloadLength, 0,
payloadLength.length);
socketWrapper.write(true, GOAWAY, 0, GOAWAY.length);
socketWrapper.write(true, fixedPayload, 0, 8);
socketWrapper.flush(true);
}
} catch (IOException ioe) {
// This is fatal for the connection. Ignore it here. There
will be
// further attempts at I/O in upgradeDispatch() and it can
better
// handle the IO errors.
}
Becomes:
socketWrapper.write(true, getWriteTimeout(),
TimeUnit.MILLISECONDS, null, SocketWrapperBase.COMPLETE_WRITE, null,
ByteBuffer.wrap(payloadLength),
ByteBuffer.wrap(GOAWAY), ByteBuffer.wrap(fixedPayload));
The code looks nicer IMO (I did rewrite the Http2UpgradeHandler with that
to see if it helped me debug or solved the HTTP/2 issues).
So it's "meh" overall and I won't use it for now, but I'd like to keep it
for a possible async impl.
Rémy