You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/11/04 21:08:09 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/service/connector TcpConnector.java

craigmcc    00/11/04 12:08:08

  Modified:    src/share/org/apache/tomcat/service/connector Tag: tomcat_32
                        TcpConnector.java
  Log:
  When receiving messages from the input stream, fully read the header and
  the message before returning.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +52 -22    jakarta-tomcat/src/share/org/apache/tomcat/service/connector/TcpConnector.java
  
  Index: TcpConnector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/TcpConnector.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- TcpConnector.java	2000/06/12 09:45:22	1.2
  +++ TcpConnector.java	2000/11/04 20:08:07	1.2.2.1
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/TcpConnector.java,v 1.2 2000/06/12 09:45:22 shachor Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/06/12 09:45:22 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/TcpConnector.java,v 1.2.2.1 2000/11/04 20:08:07 craigmcc Exp $
  + * $Revision: 1.2.2.1 $
  + * $Date: 2000/11/04 20:08:07 $
    *
    * ====================================================================
    *
  @@ -103,31 +103,61 @@
   	return msg;
       }
       
  +
  +    /**
  +     * Read the next message from the input stream, and return the
  +     * message length that was actually read (not counting the header).
  +     *
  +     * @param msg Message buffer into which we should read
  +     *
  +     * @exception IOException if an input/output error occurs
  +     */
       public int receive(MsgBuffer msg) throws IOException {
  -	// Read Packet
   
  +	// Acquire our byte buffer
   	byte b[]=msg.getBuff();
  -	
  -	int rd=in.read( b, 0, H_SIZE );
  -	if( rd<=0 ) {
  -	    //	    System.out.println("Rd header returned: " + rd );
  -	    return rd;
  -	}
   
  -	int len=msg.checkIn();
  +        // Read the entire header
  +        if (receiveFully(b, 0, H_SIZE) < H_SIZE)
  +            return (-1);        // End of file indication
   	
  -	// XXX check if enough space - it's assert()-ed !!!
  -	// Can we have only one read ( with unblocking, it can read all at once - but maybe more ) ?
  -	//???	len-=4; // header
  -
  -	rd=in.read( b, 4, len );
  -	if( rd != len ) {
  -	    System.out.println( "Incomplete read, deal with it " + len + " " + rd);
  -	}
  -	// 	msg.dump( "Incoming");
  -	return rd;
  -	//    System.out.println( "Incoming Packet len=" + len);
  +        // Read the entire message
  +	int len = msg.checkIn();
  +        int read = receiveFully(b, H_SIZE, len);
  +        return (read);
  +
  +    }
  +
  +
  +    /**
  +     * Read the specified number of bytes into the specified buffer,
  +     * continuing to read until the required number of bytes has been
  +     * encountered or end-of-file is reached.  Return the number of
  +     * bytes actually read (which will be less than the specified length
  +     * <strong>only</strong> if EOF was reached.
  +     *
  +     * @param buff Byte array into which reading takes place
  +     * @param off Initial offset at which read bytes are placed
  +     * @param len Number of bytes to be read
  +     *
  +     * @exception IOException if an input/output error occurs
  +     */
  +    private int receiveFully(byte buff[], int off, int len)
  +        throws IOException {
  +
  +        int count = 0;
  +        while (len > 0) {
  +            int read = in.read(buff, off, len);
  +            if (read < 0)       // End of file indication
  +                break;
  +            count += read;
  +            off += read;
  +            len -= read;
  +        }
  +        return (count);
  +
       }
  +
   
       public void send( MsgBuffer msg ) throws IOException {
   	msg.end();