remm 2003/09/12 06:15:36 Modified: http11/src/java/org/apache/coyote/http11 Constants.java Http11Processor.java Http11Protocol.java InternalOutputBuffer.java Log: - Add a buffer at the socket layer, configured using the socketBuffer attribute. Add handling for explicit client flushes. Revision Changes Path 1.17 +1 -1 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Constants.java Index: Constants.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Constants.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- Constants.java 2 Sep 2003 21:34:39 -0000 1.16 +++ Constants.java 12 Sep 2003 13:15:36 -0000 1.17 @@ -239,7 +239,7 @@ /** * Ack string when pipelining HTTP requests. */ - public static final byte[] ACK = + public static final byte[] ACK_BYTES = "HTTP/1.1 100 Continue\r\n\r\n".getBytes(); 1.78 +30 -0 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java Index: Http11Processor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v retrieving revision 1.77 retrieving revision 1.78 diff -u -r1.77 -r1.78 --- Http11Processor.java 7 Sep 2003 18:04:58 -0000 1.77 +++ Http11Processor.java 12 Sep 2003 13:15:36 -0000 1.78 @@ -274,6 +274,12 @@ /** + * Socket buffering. + */ + protected int socketBuffer = -1; + + + /** * List of user agents to not use gzip with */ protected String[] noCompressionUserAgents = null; @@ -534,6 +540,21 @@ } /** + * Set the socket buffer flag. + */ + public void setSocketBuffer(int socketBuffer) { + this.socketBuffer = socketBuffer; + outputBuffer.setSocketBuffer(socketBuffer); + } + + /** + * Get the socket buffer flag. + */ + public int getSocketBuffer() { + return socketBuffer; + } + + /** * Set the upload timeout. */ public void setTimeout( int timeouts ) { @@ -767,6 +788,15 @@ // Set error flag error = true; } + } + + } else if (actionCode == ActionCode.ACTION_CLIENT_FLUSH) { + + try { + outputBuffer.flush(); + } catch (IOException e) { + // Set error flag + error = true; } } else if (actionCode == ActionCode.ACTION_CLOSE) { 1.36 +6 -0 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Protocol.java Index: Http11Protocol.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Protocol.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- Http11Protocol.java 2 Sep 2003 21:34:39 -0000 1.35 +++ Http11Protocol.java 12 Sep 2003 13:15:36 -0000 1.36 @@ -246,6 +246,7 @@ private String reportedname; private int socketCloseDelay=-1; private boolean disableUploadTimeout = true; + private int socketBuffer = 1500; private Adapter adapter; private Http11ConnectionHandler cHandler; @@ -318,6 +319,10 @@ disableUploadTimeout = isDisabled; } + public void setSocketBuffer(int valueI) { + socketBuffer = valueI; + } + public void setCompression(String valueS) { compression = valueS; } @@ -463,6 +468,7 @@ processor.setTimeout( proto.timeout ); processor.setDisableUploadTimeout( proto.disableUploadTimeout ); processor.setCompression( proto.compression ); + processor.setSocketBuffer( proto.socketBuffer ); thData[Http11Protocol.THREAD_DATA_PROCESSOR]=processor; 1.19 +87 -6 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java Index: InternalOutputBuffer.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- InternalOutputBuffer.java 11 Sep 2003 07:03:58 -0000 1.18 +++ InternalOutputBuffer.java 12 Sep 2003 13:15:36 -0000 1.19 @@ -77,7 +77,8 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> */ -public class InternalOutputBuffer implements OutputBuffer { +public class InternalOutputBuffer + implements OutputBuffer, ByteChunk.ByteOutputChannel { // -------------------------------------------------------------- Constants @@ -111,6 +112,9 @@ activeFilters = new OutputFilter[0]; lastActiveFilter = -1; + socketBuffer = new ByteChunk(); + socketBuffer.setByteOutputChannel(this); + committed = false; finished = false; @@ -203,6 +207,18 @@ protected int lastActiveFilter; + /** + * Socket buffer. + */ + protected ByteChunk socketBuffer; + + + /** + * Socket buffer (extra buffering to reduce number of packets sent). + */ + protected boolean useSocketBuffer = false; + + // ------------------------------------------------------------- Properties @@ -229,6 +245,21 @@ /** + * Set the socket buffer size. + */ + public void setSocketBuffer(int socketBufferSize) { + + if (socketBufferSize > 500) { + useSocketBuffer = true; + socketBuffer.allocate(socketBufferSize, socketBufferSize); + } else { + useSocketBuffer = false; + } + + } + + + /** * Add an output filter to the filter library. */ public void addFilter(OutputFilter filter) { @@ -293,6 +324,31 @@ /** + * Flush the response. + * + * @throws IOException an undelying I/O error occured + */ + public void flush() + throws IOException { + + if (!committed) { + + // Send the connector a request for commit. The connector should + // then validate the headers, send them (using sendHeader) and + // set the filters accordingly. + response.action(ActionCode.ACTION_COMMIT, null); + + } + + // Flush the current buffer + if (useSocketBuffer) { + socketBuffer.flushBuffer(); + } + + } + + + /** * Reset current response. * * @throws IllegalStateException if the response has already been committed @@ -316,6 +372,7 @@ // Recycle Request object response.recycle(); + socketBuffer.recycle(); outputStream = null; buf = headerBuffer; @@ -337,6 +394,7 @@ // Recycle Request object response.recycle(); + socketBuffer.recycle(); // Determine the header buffer used for next request buf = headerBuffer; @@ -378,6 +436,10 @@ if (lastActiveFilter != -1) activeFilters[lastActiveFilter].end(); + if (useSocketBuffer) { + socketBuffer.flushBuffer(); + } + finished = true; } @@ -393,7 +455,7 @@ throws IOException { if (!committed) - outputStream.write(Constants.ACK); + outputStream.write(Constants.ACK_BYTES); } @@ -543,8 +605,11 @@ if (pos > 0) { // Sending the response header buffer - outputStream.write(buf, 0, pos); - outputStream.flush(); // Is it really necessary ? + if (useSocketBuffer) { + socketBuffer.append(buf, 0, pos); + } else { + outputStream.write(buf, 0, pos); + } } } @@ -657,6 +722,17 @@ } + /** + * Callback to write data from the buffer. + */ + public void realWriteBytes(byte cbuf[], int off, int len) + throws IOException { + if (len > 0) { + outputStream.write(cbuf, off, len); + } + } + + // ----------------------------------- OutputStreamOutputBuffer Inner Class @@ -674,8 +750,13 @@ public int doWrite(ByteChunk chunk, Response res) throws IOException { - outputStream.write(chunk.getBuffer(), chunk.getStart(), - chunk.getLength()); + if (useSocketBuffer) { + socketBuffer.append(chunk.getBuffer(), chunk.getStart(), + chunk.getLength()); + } else { + outputStream.write(chunk.getBuffer(), chunk.getStart(), + chunk.getLength()); + } return chunk.getLength(); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]