costin 02/01/25 23:25:09 Modified: jk/java/org/apache/jk/common ChannelSocket.java ChannelUn.java Log: Updates, fixes. Revision Changes Path 1.3 +80 -25 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java Index: ChannelSocket.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ChannelSocket.java 16 Jan 2002 15:38:29 -0000 1.2 +++ ChannelSocket.java 26 Jan 2002 07:25:09 -0000 1.3 @@ -94,7 +94,7 @@ * * @author Costin Manolache */ -public class ChannelSocket extends JkChannel implements Channel { +public class ChannelSocket extends Channel { int port; InetAddress inet; @@ -103,8 +103,6 @@ int linger=100; int socketTimeout; - Worker worker; - ThreadPool tp=new ThreadPool(); /* ==================== Tcp socket options ==================== */ @@ -117,14 +115,6 @@ this.port=port; } - public void setWorker( Worker w ) { - worker=w; - } - - public Worker getWorker() { - return worker; - } - public void setAddress(InetAddress inet) { this.inet=inet; } @@ -214,10 +204,70 @@ } } - public void write( Endpoint ep, byte[] b, int offset, int len) throws IOException { + public int send( Msg msg, Endpoint ep) + throws IOException + { + msg.end(); // Write the packet header + byte buf[]=msg.getBuffer(); + int len=msg.getLen(); + + if(dL > 5 ) + d("send() " + len + " " + buf[4] ); + OutputStream os=(OutputStream)ep.getNote( osNote ); + os.write( buf, 0, len ); + return len; + } + + public int receive( Msg msg, Endpoint ep ) + throws IOException + { + if (dL > 0) { + d("receive()"); + } + + byte buf[]=msg.getBuffer(); + int hlen=msg.getHeaderLength(); + + // XXX If the length in the packet header doesn't agree with the + // actual number of bytes read, it should probably return an error + // value. Also, callers of this method never use the length + // returned -- should probably return true/false instead. + + int rd = this.read(ep, buf, 0, hlen ); + + if(rd < 0) { + // Most likely normal apache restart. + return rd; + } + + msg.processHeader(); - os.write( b, offset, len ); + /* After processing the header we know the body + length + */ + int blen=msg.getLen(); + + // XXX check if enough space - it's assert()-ed !!! + + int total_read = 0; + + total_read = this.read(ep, buf, hlen, blen); + + if (total_read <= 0) { + d("can't read body, waited #" + blen); + return -1; + } + + if (total_read != blen) { + d( "incomplete read, waited #" + blen + + " got only " + total_read); + return -2; + } + + if (dL > 0) + d("receive: total read = " + total_read); + return total_read; } /** @@ -228,24 +278,27 @@ * * from read() Linux manual * - * On success, the number of bytes read is returned (zero indicates end of file), - * and the file position is advanced by this number. - * It is not an error if this number is smaller than the number of bytes requested; - * this may happen for example because fewer bytes - * are actually available right now (maybe because we were close to end-of-file, - * or because we are reading from a pipe, or from a + * On success, the number of bytes read is returned (zero indicates end + * of file),and the file position is advanced by this number. + * It is not an error if this number is smaller than the number of bytes + * requested; this may happen for example because fewer bytes + * are actually available right now (maybe because we were close to + * end-of-file, or because we are reading from a pipe, or from a * terminal), or because read() was interrupted by a signal. * On error, -1 is returned, and errno is set appropriately. In this * case it is left unspecified whether the file position (if any) changes. * **/ - public int read( Endpoint ep, byte[] b, int offset, int len) throws IOException { + public int read( Endpoint ep, byte[] b, int offset, int len) + throws IOException + { InputStream is=(InputStream)ep.getNote( isNote ); int pos = 0; int got; if (dL > 5) { - d("reading # " + b + " " + (b==null ? 0: b.length) + " " + offset + " " + len); + d("reading # " + b + " " + (b==null ? 0: b.length) + " " + + offset + " " + len); } while(pos < len) { got = is.read(b, pos + offset, len - pos); @@ -266,8 +319,6 @@ } return pos; } - - public Endpoint createEndpoint() { return new Endpoint(); @@ -279,7 +330,7 @@ */ void acceptConnections() { if( dL>0 ) - d("Accepting ajp connections"); + d("Accepting ajp connections on " + port); while( running ) { try { Endpoint ep=this.createEndpoint(); @@ -301,8 +352,12 @@ try { MsgAjp recv=new MsgAjp(); while( running ) { - recv.receive( this, ep ); + this.receive( recv, ep ); int status=we.processCallbacks( this, ep, recv ); + if( status!= Handler.OK ) { + d("processCallbacks status " + status ); + break; + } } this.close( ep ); } catch( Exception ex ) { 1.5 +64 -13 jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelUn.java Index: ChannelUn.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelUn.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ChannelUn.java 16 Jan 2002 15:38:29 -0000 1.4 +++ ChannelUn.java 26 Jan 2002 07:25:09 -0000 1.5 @@ -77,10 +77,9 @@ * * @author Costin Manolache */ -public class ChannelUn extends JkChannel implements Channel { +public class ChannelUn extends Channel { String file; - Worker worker; ThreadPool tp=new ThreadPool(); String jkHome; @@ -90,14 +89,6 @@ return tp; } - public void setWorker( Worker w ) { - worker=w; - } - - public Worker getWorker() { - return worker; - } - public void setFile( String f ) { file=f; } @@ -172,11 +163,71 @@ e.printStackTrace(); } } + public int send( Msg msg, Endpoint ep) + throws IOException + { + msg.end(); // Write the packet header + byte buf[]=msg.getBuffer(); + int len=msg.getLen(); + + if(dL > 5 ) + d("send() " + len + " " + buf[4] ); - public void write( Endpoint ep, byte[] b, int offset, int len) throws IOException { Long s=(Long)ep.getNote( socketNote ); - apr.unWrite( gPool, s.longValue(), b, offset, len ); + apr.unWrite( gPool, s.longValue(), buf, 0, len ); + return len; + } + + public int receive( Msg msg, Endpoint ep ) + throws IOException + { + if (dL > 0) { + d("receive()"); + } + + byte buf[]=msg.getBuffer(); + int hlen=msg.getHeaderLength(); + + // XXX If the length in the packet header doesn't agree with the + // actual number of bytes read, it should probably return an error + // value. Also, callers of this method never use the length + // returned -- should probably return true/false instead. + + int rd = this.read(ep, buf, 0, hlen ); + + if(rd < 0) { + // Most likely normal apache restart. + return rd; + } + + msg.processHeader(); + + /* After processing the header we know the body + length + */ + int blen=msg.getLen(); + + // XXX check if enough space - it's assert()-ed !!! + + int total_read = 0; + + total_read = this.read(ep, buf, hlen, blen); + + if (total_read <= 0) { + d("can't read body, waited #" + blen); + return -1; + } + + if (total_read != blen) { + d( "incomplete read, waited #" + blen + + " got only " + total_read); + return -2; + } + + if (dL > 0) + d("receive: total read = " + total_read); + return total_read; } /** @@ -255,7 +306,7 @@ try { MsgAjp recv=new MsgAjp(); while( running ) { - int res=recv.receive( this, ep ); + int res=this.receive( recv, ep ); if( res<0 ) { // EOS break;
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>