Author: markt
Date: Wed Nov 12 10:49:24 2014
New Revision: 1638753
URL: http://svn.apache.org/r1638753
Log:
Use the SocketWrapper's write method
Modified:
tomcat/trunk/java/org/apache/coyote/ajp/AjpNio2Processor.java
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpNio2Processor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpNio2Processor.java?rev=1638753&r1=1638752&r2=1638753&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpNio2Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpNio2Processor.java Wed Nov 12
10:49:24 2014
@@ -18,7 +18,6 @@ package org.apache.coyote.ajp;
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.nio.channels.CompletionHandler;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -27,7 +26,6 @@ import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.net.Nio2Channel;
import org.apache.tomcat.util.net.Nio2Endpoint;
-import org.apache.tomcat.util.net.SocketStatus;
import org.apache.tomcat.util.net.SocketWrapperBase;
/**
@@ -42,54 +40,18 @@ public class AjpNio2Processor extends Ab
}
/**
- * The completion handler used for asynchronous write operations
- */
- protected CompletionHandler<Integer, SocketWrapperBase<Nio2Channel>>
writeCompletionHandler;
-
- /**
* Flipped flag for read buffer.
*/
protected boolean flipped = false;
- /**
- * Write pending flag.
- */
- protected volatile boolean writePending = false;
-
public AjpNio2Processor(int packetSize, Nio2Endpoint endpoint0) {
super(packetSize, endpoint0);
response.setOutputBuffer(new SocketOutputBuffer());
- this.writeCompletionHandler = new CompletionHandler<Integer,
SocketWrapperBase<Nio2Channel>>() {
- @Override
- public void completed(Integer nBytes,
SocketWrapperBase<Nio2Channel> attachment) {
- boolean notify = false;
- synchronized (writeCompletionHandler) {
- if (nBytes.intValue() < 0) {
- failed(new
IOException(sm.getString("ajpprocessor.failedsend")), attachment);
- return;
- }
- writePending = false;
- if (!Nio2Endpoint.isInline()) {
- notify = true;
- }
- }
- if (notify) {
- endpoint.processSocket(attachment,
SocketStatus.OPEN_WRITE, false);
- }
- }
- @Override
- public void failed(Throwable exc, SocketWrapperBase<Nio2Channel>
attachment) {
- attachment.setError(true);
- writePending = false;
- endpoint.processSocket(attachment, SocketStatus.DISCONNECT,
true);
- }
- };
}
@Override
public void recycle(boolean socketClosing) {
super.recycle(socketClosing);
- writePending = false;
flipped = false;
}
@@ -108,43 +70,12 @@ public class AjpNio2Processor extends Ab
@Override
- protected int output(byte[] src, int offset, int length, boolean block)
- throws IOException {
+ protected int output(byte[] src, int offset, int length, boolean block)
throws IOException {
if (socketWrapper == null || socketWrapper.getSocket() == null)
return -1;
- ByteBuffer writeBuffer =
- socketWrapper.getSocket().getBufHandler().getWriteBuffer();
-
- int result = 0;
- if (block) {
- writeBuffer.clear();
- writeBuffer.put(src, offset, length);
- writeBuffer.flip();
- try {
- result = socketWrapper.getSocket().write(writeBuffer)
- .get(socketWrapper.getTimeout(),
TimeUnit.MILLISECONDS).intValue();
- } catch (InterruptedException | ExecutionException
- | TimeoutException e) {
- throw new IOException(sm.getString("ajpprocessor.failedsend"),
e);
- }
- } else {
- synchronized (writeCompletionHandler) {
- if (!writePending) {
- writeBuffer.clear();
- writeBuffer.put(src, offset, length);
- writeBuffer.flip();
- writePending = true;
- Nio2Endpoint.startInline();
- socketWrapper.getSocket().write(writeBuffer,
socketWrapper.getTimeout(),
- TimeUnit.MILLISECONDS, socketWrapper,
writeCompletionHandler);
- Nio2Endpoint.endInline();
- result = length;
- }
- }
- }
- return result;
+ return socketWrapper.write(block, src, offset, length);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]