From 6b566fa2dd7eb017fcea9d9e594fc5cf1692ccf5 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 23 Aug 2011 11:07:29 +0000 Subject: [PATCH] Pull up AJP SocketOutputBuffer git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1160626 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/coyote/ajp/AbstractAjpProcessor.java | 64 ++++++++++++++++++++- java/org/apache/coyote/ajp/AjpAprProcessor.java | 67 ---------------------- java/org/apache/coyote/ajp/AjpNioProcessor.java | 60 ------------------- java/org/apache/coyote/ajp/AjpProcessor.java | 60 ------------------- 4 files changed, 61 insertions(+), 190 deletions(-) diff --git a/java/org/apache/coyote/ajp/AbstractAjpProcessor.java b/java/org/apache/coyote/ajp/AbstractAjpProcessor.java index f3f48c3ac..50c9bc042 100644 --- a/java/org/apache/coyote/ajp/AbstractAjpProcessor.java +++ b/java/org/apache/coyote/ajp/AbstractAjpProcessor.java @@ -29,8 +29,10 @@ import org.apache.coyote.AbstractProcessor; import org.apache.coyote.ActionCode; import org.apache.coyote.AsyncContextCallback; import org.apache.coyote.InputBuffer; +import org.apache.coyote.OutputBuffer; import org.apache.coyote.Request; import org.apache.coyote.RequestInfo; +import org.apache.coyote.Response; import org.apache.juli.logging.Log; import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.buf.ByteChunk; @@ -542,6 +544,10 @@ public abstract class AbstractAjpProcessor extends AbstractProcessor { protected abstract void output(byte[] src, int offset, int length) throws IOException; + // Methods used by SocketInputBuffer + protected abstract boolean receive() throws IOException; + protected abstract boolean refillReadBuffer() throws IOException; + @Override protected final boolean isComet() { @@ -962,7 +968,59 @@ public abstract class AbstractAjpProcessor extends AbstractProcessor { } - // Methods used by SocketInputBuffer - protected abstract boolean receive() throws IOException; - protected abstract boolean refillReadBuffer() throws IOException; + + // ----------------------------------- OutputStreamOutputBuffer Inner Class + + /** + * This class is an output buffer which will write data to an output + * stream. + */ + protected class SocketOutputBuffer implements OutputBuffer { + + /** + * Write chunk. + */ + @Override + public int doWrite(ByteChunk chunk, Response res) + throws IOException { + + if (!response.isCommitted()) { + // Validate and write response headers + try { + prepareResponse(); + } catch (IOException e) { + // Set error flag + error = true; + } + } + + int len = chunk.getLength(); + // 4 - hardcoded, byte[] marshaling overhead + // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE) + int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE; + int off = 0; + while (len > 0) { + int thisTime = len; + if (thisTime > chunkSize) { + thisTime = chunkSize; + } + len -= thisTime; + responseMessage.reset(); + responseMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK); + responseMessage.appendBytes(chunk.getBytes(), chunk.getOffset() + off, thisTime); + responseMessage.end(); + output(responseMessage.getBuffer(), 0, responseMessage.getLen()); + + off += thisTime; + } + + byteCount += chunk.getLength(); + return chunk.getLength(); + } + + @Override + public long getBytesWritten() { + return byteCount; + } + } } diff --git a/java/org/apache/coyote/ajp/AjpAprProcessor.java b/java/org/apache/coyote/ajp/AjpAprProcessor.java index 880c9645b..b2a25f685 100644 --- a/java/org/apache/coyote/ajp/AjpAprProcessor.java +++ b/java/org/apache/coyote/ajp/AjpAprProcessor.java @@ -21,15 +21,12 @@ import java.io.InterruptedIOException; import java.nio.ByteBuffer; import org.apache.coyote.ActionCode; -import org.apache.coyote.OutputBuffer; import org.apache.coyote.RequestInfo; -import org.apache.coyote.Response; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.jni.Socket; import org.apache.tomcat.jni.Status; import org.apache.tomcat.util.ExceptionUtils; -import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; import org.apache.tomcat.util.net.AprEndpoint; import org.apache.tomcat.util.net.SocketStatus; @@ -524,68 +521,4 @@ public class AjpAprProcessor extends AbstractAjpProcessor { } } } - - - // ----------------------------------- OutputStreamOutputBuffer Inner Class - - - /** - * This class is an output buffer which will write data to an output - * stream. - */ - protected class SocketOutputBuffer - implements OutputBuffer { - - - /** - * Write chunk. - */ - @Override - public int doWrite(ByteChunk chunk, Response res) - throws IOException { - - if (!response.isCommitted()) { - // Validate and write response headers - try { - prepareResponse(); - } catch (IOException e) { - // Set error flag - error = true; - } - } - - int len = chunk.getLength(); - // 4 - hardcoded, byte[] marshaling overhead - // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE) - int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE; - int off = 0; - while (len > 0) { - int thisTime = len; - if (thisTime > chunkSize) { - thisTime = chunkSize; - } - len -= thisTime; - if (outputBuffer.position() + thisTime + - Constants.H_SIZE + 4 > outputBuffer.capacity()) { - flush(false); - } - outputBuffer.put((byte) 0x41); - outputBuffer.put((byte) 0x42); - outputBuffer.putShort((short) (thisTime + 4)); - outputBuffer.put(Constants.JK_AJP13_SEND_BODY_CHUNK); - outputBuffer.putShort((short) thisTime); - outputBuffer.put(chunk.getBytes(), chunk.getOffset() + off, thisTime); - outputBuffer.put((byte) 0x00); - off += thisTime; - } - - byteCount += chunk.getLength(); - return chunk.getLength(); - } - - @Override - public long getBytesWritten() { - return byteCount; - } - } } diff --git a/java/org/apache/coyote/ajp/AjpNioProcessor.java b/java/org/apache/coyote/ajp/AjpNioProcessor.java index 631541910..3bd59803c 100644 --- a/java/org/apache/coyote/ajp/AjpNioProcessor.java +++ b/java/org/apache/coyote/ajp/AjpNioProcessor.java @@ -23,13 +23,10 @@ import java.nio.ByteBuffer; import java.nio.channels.Selector; import org.apache.coyote.ActionCode; -import org.apache.coyote.OutputBuffer; import org.apache.coyote.RequestInfo; -import org.apache.coyote.Response; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.ExceptionUtils; -import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; import org.apache.tomcat.util.net.NioChannel; import org.apache.tomcat.util.net.NioEndpoint; @@ -499,61 +496,4 @@ public class AjpNioProcessor extends AbstractAjpProcessor { output(flushMessageArray, 0, flushMessageArray.length); } } - - - // ----------------------------------- OutputStreamOutputBuffer Inner Class - - - /** - * This class is an output buffer which will write data to an output - * stream. - */ - protected class SocketOutputBuffer implements OutputBuffer { - - /** - * Write chunk. - */ - @Override - public int doWrite(ByteChunk chunk, Response res) - throws IOException { - - if (!response.isCommitted()) { - // Validate and write response headers - try { - prepareResponse(); - } catch (IOException e) { - // Set error flag - error = true; - } - } - - int len = chunk.getLength(); - // 4 - hardcoded, byte[] marshaling overhead - // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE) - int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE; - int off = 0; - while (len > 0) { - int thisTime = len; - if (thisTime > chunkSize) { - thisTime = chunkSize; - } - len -= thisTime; - responseMessage.reset(); - responseMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK); - responseMessage.appendBytes(chunk.getBytes(), chunk.getOffset() + off, thisTime); - responseMessage.end(); - output(responseMessage.getBuffer(), 0, responseMessage.getLen()); - - off += thisTime; - } - - byteCount += chunk.getLength(); - return chunk.getLength(); - } - - @Override - public long getBytesWritten() { - return byteCount; - } - } } diff --git a/java/org/apache/coyote/ajp/AjpProcessor.java b/java/org/apache/coyote/ajp/AjpProcessor.java index b5b3e24b2..6f524b7d4 100644 --- a/java/org/apache/coyote/ajp/AjpProcessor.java +++ b/java/org/apache/coyote/ajp/AjpProcessor.java @@ -23,13 +23,10 @@ import java.io.OutputStream; import java.net.Socket; import org.apache.coyote.ActionCode; -import org.apache.coyote.OutputBuffer; import org.apache.coyote.RequestInfo; -import org.apache.coyote.Response; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.ExceptionUtils; -import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; import org.apache.tomcat.util.net.JIoEndpoint; import org.apache.tomcat.util.net.SocketStatus; @@ -448,61 +445,4 @@ public class AjpProcessor extends AbstractAjpProcessor { output.write(flushMessageArray); } } - - - // ----------------------------------- OutputStreamOutputBuffer Inner Class - - - /** - * This class is an output buffer which will write data to an output - * stream. - */ - protected class SocketOutputBuffer implements OutputBuffer { - - /** - * Write chunk. - */ - @Override - public int doWrite(ByteChunk chunk, Response res) - throws IOException { - - if (!response.isCommitted()) { - // Validate and write response headers - try { - prepareResponse(); - } catch (IOException e) { - // Set error flag - error = true; - } - } - - int len = chunk.getLength(); - // 4 - hardcoded, byte[] marshaling overhead - // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE) - int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE; - int off = 0; - while (len > 0) { - int thisTime = len; - if (thisTime > chunkSize) { - thisTime = chunkSize; - } - len -= thisTime; - responseMessage.reset(); - responseMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK); - responseMessage.appendBytes(chunk.getBytes(), chunk.getOffset() + off, thisTime); - responseMessage.end(); - output.write(responseMessage.getBuffer(), 0, responseMessage.getLen()); - - off += thisTime; - } - - byteCount += chunk.getLength(); - return chunk.getLength(); - } - - @Override - public long getBytesWritten() { - return byteCount; - } - } } -- 2.11.0