Author: mturk
Date: Sun Oct 29 08:50:56 2006
New Revision: 468937

URL: http://svn.apache.org/viewvc?view=rev&rev=468937
Log:
On explicit flush, create an empty (8 bytes)
SEND_BODY_CHUNK message, that can be used by
web server to flush the packet.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java?view=diff&rev=468937&r1=468936&r2=468937
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java Sun 
Oct 29 08:50:56 2006
@@ -265,6 +265,11 @@
      */
     protected static final byte[] endMessageArray;
 
+    /**
+     * Direct buffer used for sending explicit flush message.
+     */
+    protected static final ByteBuffer flushMessageBuffer;
+
 
     // ----------------------------------------------------- Static Initializer
 
@@ -272,7 +277,7 @@
     static {
 
         // Set the get body message buffer
-        AjpMessage getBodyMessage = new AjpMessage(128);
+        AjpMessage getBodyMessage = new AjpMessage(16);
         getBodyMessage.reset();
         getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK);
         getBodyMessage.appendInt(Constants.MAX_READ_SIZE);
@@ -283,7 +288,7 @@
                 getBodyMessage.getLen());
 
         // Set the read body message buffer
-        AjpMessage pongMessage = new AjpMessage(128);
+        AjpMessage pongMessage = new AjpMessage(16);
         pongMessage.reset();
         pongMessage.appendByte(Constants.JK_AJP13_CPONG_REPLY);
         pongMessage.end();
@@ -292,7 +297,7 @@
                 pongMessage.getLen());
 
         // Allocate the end message array
-        AjpMessage endMessage = new AjpMessage(128);
+        AjpMessage endMessage = new AjpMessage(16);
         endMessage.reset();
         endMessage.appendByte(Constants.JK_AJP13_END_RESPONSE);
         endMessage.appendByte(1);
@@ -301,6 +306,18 @@
         System.arraycopy(endMessage.getBuffer(), 0, endMessageArray, 0,
                 endMessage.getLen());
 
+        // Set the flush message buffer
+        AjpMessage flushMessage = new AjpMessage(16);
+        flushMessage.reset();
+        flushMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK);
+        flushMessage.appendInt(0);
+        flushMessage.appendByte(0);
+        flushMessage.end();
+        flushMessageBuffer =
+            ByteBuffer.allocateDirect(flushMessage.getLen());
+        flushMessageBuffer.put(flushMessage.getBuffer(), 0,
+                flushMessage.getLen());
+
     }
 
 
@@ -504,6 +521,11 @@
 
             try {
                 flush();
+                // Send explicit flush message
+                if (Socket.sendb(socket, flushMessageBuffer, 0,
+                                 flushMessageBuffer.position()) < 0) {
+                    error = true;                    
+                }
             } catch (IOException e) {
                 // Set error flag
                 error = true;

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java?view=diff&rev=468937&r1=468936&r2=468937
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Sun Oct 
29 08:50:56 2006
@@ -254,6 +254,11 @@
      */
     protected static final byte[] endMessageArray;
 
+    /**
+     * Flush message array.
+     */
+    protected static final byte[] flushMessageArray;
+
 
     // ----------------------------------------------------- Static Initializer
 
@@ -261,7 +266,8 @@
     static {
 
         // Set the get body message buffer
-        AjpMessage getBodyMessage = new AjpMessage(128);
+
+        AjpMessage getBodyMessage = new AjpMessage(16);
         getBodyMessage.reset();
         getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK);
         getBodyMessage.appendInt(Constants.MAX_READ_SIZE);
@@ -271,7 +277,7 @@
                 0, getBodyMessage.getLen());
 
         // Set the read body message buffer
-        AjpMessage pongMessage = new AjpMessage(128);
+        AjpMessage pongMessage = new AjpMessage(16);
         pongMessage.reset();
         pongMessage.appendByte(Constants.JK_AJP13_CPONG_REPLY);
         pongMessage.end();
@@ -280,7 +286,7 @@
                 0, pongMessage.getLen());
 
         // Allocate the end message array
-        AjpMessage endMessage = new AjpMessage(128);
+        AjpMessage endMessage = new AjpMessage(16);
         endMessage.reset();
         endMessage.appendByte(Constants.JK_AJP13_END_RESPONSE);
         endMessage.appendByte(1);
@@ -289,6 +295,17 @@
         System.arraycopy(endMessage.getBuffer(), 0, endMessageArray, 0,
                 endMessage.getLen());
 
+        // Allocate the flush message array
+        AjpMessage flushMessage = new AjpMessage(16);
+        flushMessage.reset();
+        flushMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK);
+        flushMessage.appendInt(0);
+        flushMessage.appendByte(0);
+        flushMessage.end();
+        flushMessageArray = new byte[flushMessage.getLen()];
+        System.arraycopy(flushMessage.getBuffer(), 0, flushMessageArray, 0,
+                flushMessage.getLen());
+
     }
 
 
@@ -1073,7 +1090,8 @@
      */
     protected void flush()
         throws IOException {
-        // Note: at the moment, there's no buffering at the socket level
+        // Send the flush message
+        output.write(flushMessageArray);
     }
 
 

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java?view=diff&rev=468937&r1=468936&r2=468937
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java Sun Oct 29 
08:50:56 2006
@@ -89,19 +89,27 @@
     public static final byte SC_A_ARE_DONE      = (byte)0xFF;
 
     // Ajp13 specific -  needs refactoring for the new model
+
     /**
-     * Maximum Total byte size for a AJP packet
+     * Default maximum total byte size for a AJP packet
      */
     public static final int MAX_PACKET_SIZE = 8192;
     /**
      * Size of basic packet header
      */
     public static final int H_SIZE = 4;
+
     /**
-     * Maximum size of data that can be sent in one packet
+     * Size of the header metadata
      */
-    public static final int  MAX_READ_SIZE = MAX_PACKET_SIZE - H_SIZE - 2;
-    public static final int  MAX_SEND_SIZE = MAX_PACKET_SIZE - H_SIZE - 4;
+    public static final int  READ_HEAD_LEN = 6;
+    public static final int  SEND_HEAD_LEN = 8;
+
+    /**
+     * Default maximum size of data that can be sent in one packet
+     */
+    public static final int  MAX_READ_SIZE = MAX_PACKET_SIZE - READ_HEAD_LEN;
+    public static final int  MAX_SEND_SIZE = MAX_PACKET_SIZE - SEND_HEAD_LEN;
 
     // Translates integer codes to names of HTTP methods
     public static final String []methodTransArray = {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to