billbarker    2005/07/16 13:54:05

  Modified:    jk/java/org/apache/jk/common HandlerRequest.java
                        JkInputStream.java
  Log:
  Copy the idea from the APR Connector, and delay reading the initial request 
body packet until the Servlet asks for it.
  
  This reduces the chance that the socket read will block uselessly waiting for 
the data to be available.  You can restore the previous behavior by setting 
request.delayInitialRead="false" on the <Connector>.
  
  Of course, if Bill R. decides to port his C-L patch for proxy_http to mod_jk, 
the value of this setting won't matter :).
  
  Revision  Changes    Path
  1.48      +28 -10    
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/HandlerRequest.java
  
  Index: HandlerRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/HandlerRequest.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- HandlerRequest.java       30 Jun 2005 02:49:38 -0000      1.47
  +++ HandlerRequest.java       16 Jul 2005 20:54:05 -0000      1.48
  @@ -168,6 +168,20 @@
           return registerRequests;
       }
   
  +    /**
  +     * Set the flag to delay the initial body read
  +     */
  +    public void setDelayInitialRead(boolean dir) {
  +     delayInitialRead = dir;
  +    }
  +
  +    /**
  +     * Get the flag to tell if we delay the initial body read
  +     */
  +    public boolean getDelayInitialRead() {
  +     return delayInitialRead;
  +    }
  +
       // -------------------- Ajp13.id --------------------
   
       private void generateAjp13Id() {
  @@ -210,14 +224,15 @@
       }
       
       // -------------------- Incoming message --------------------
  -    String requiredSecret=null;
  -    int secretNote;
  -    int tmpBufNote;
  -
  -    boolean decoded=true;
  -    boolean tomcatAuthentication=true;
  -    boolean registerRequests=true;
  -    boolean shutdownEnabled=false;
  +    private String requiredSecret=null;
  +    private int secretNote;
  +    private int tmpBufNote;
  +
  +    private boolean decoded=true;
  +    private boolean tomcatAuthentication=true;
  +    private boolean registerRequests=true;
  +    private boolean shutdownEnabled=false;
  +    private boolean delayInitialRead = true;
       
       public int invoke(Msg msg, MsgContext ep ) 
           throws IOException    {
  @@ -393,8 +408,11 @@
           // immediately after
           int cl=req.getContentLength();
           if(cl > 0) {
  -            // This is hidious.  Look to remove it.
  -            ep.getInputStream().receive();
  +            JkInputStream jkIS = ep.getInputStream();
  +            jkIS.setIsReadRequired(true);
  +            if(!delayInitialRead) {
  +                jkIS.receive();
  +            }
           }
       
           if (log.isTraceEnabled()) {
  
  
  
  1.20      +26 -0     
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JkInputStream.java
  
  Index: JkInputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JkInputStream.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- JkInputStream.java        30 Jun 2005 02:49:38 -0000      1.19
  +++ JkInputStream.java        16 Jul 2005 20:54:05 -0000      1.20
  @@ -50,6 +50,7 @@
       private boolean isEmpty = true;
       private boolean isFirst = true;
       private boolean isReplay = false;
  +    private boolean isReadRequired = false;
   
       static {
           // Make certain HttpMessages is loaded for SecurityManager
  @@ -66,14 +67,39 @@
   
       // -------------------- Jk specific methods --------------------
   
  +
  +    /**
  +     * Set the flag saying that the server is sending a body
  +     */
  +    public void setIsReadRequired(boolean irr) {
  +        isReadRequired = irr;
  +    }
  +
  +    /**
  +     * Return the flag saying that the server is sending a body
  +     */
  +    public boolean isReadRequired() {
  +        return isReadRequired;
  +    }
  +
       
       /** Must be called before or after each request
        */
       public void recycle() {
  +        if(isReadRequired && isFirst) {
  +            // The Servlet never read the request body, so we need to junk it
  +            try {
  +              receive();
  +            } catch(IOException iex) {
  +              log.debug("Error consuming request body",iex);
  +            }
  +        }
  +
           end_of_stream = false;
           isEmpty = true;
           isFirst = true;
           isReplay = false;
  +        isReadRequired = false;
           bodyBuff.recycle();
           tempMB.recycle();
       }
  
  
  

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

Reply via email to