rubys 02/03/05 02:00:51
Modified: java/src/org/apache/axis/utils tcpmon.java
Log:
> I run into 2 small bugs - the diff solves the problem for me,
> maybe for others :-)
>
> First, on some VMs the SocketRR will hung for a very long time.
> That's because even if close() is called on the socket, the
> read() will remain blocked. Adding a soTimeout and
> checking for done solves this.
>
> The other - with some servers, if available() returns
> 0 we read a single byte, and then send it. Then we'll
> send a second packet with the rest of the request.
> That will confuse at least apache (who would see
> OST instead of POST - still trying to figure out why ).
> I see no reason to read a single byte - we'll block
> anyway.
Submitted by Costin Manolache
Revision Changes Path
1.27 +34 -8 xml-axis/java/src/org/apache/axis/utils/tcpmon.java
Index: tcpmon.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/tcpmon.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- tcpmon.java 19 Feb 2002 12:55:39 -0000 1.26
+++ tcpmon.java 5 Mar 2002 10:00:51 -0000 1.27
@@ -443,19 +443,41 @@
int reqSaved = 0 ;
int thisIndent, nextIndent=0 ;
-
+ inSocket.setSoTimeout(10 );
+ outSocket.setSoTimeout(10 );
+
for ( ;; ) {
+ if( done ) break;
len = in.available();
- if ( len == 0 ) len = 1 ;
+ // Used to be 1, but if we block it doesn't matter
+ // however 1 will break with some servers, including apache
+ if ( len == 0 ) len = 4096 ;
if ( saved+len > 4096 ) len = 4096-saved ;
- len = in.read(buffer,saved,len);
+ int len1=0;
+ while( len1==0 ) {
+ try {
+ len1 = in.read(buffer,saved,len);
+ } catch( java.io.InterruptedIOException ex ) {
+ //System.out.println("Interrupted exception reading" +
this +
+ // " " + done);
+ len1=0;
+ if( done ) return;
+ }
+ }
+ // System.out.println("XXX Read result: " + this + " " +len1 +
" " + out);
+ len=len1;
if ( len == -1 ) break ;
+ //System.out.println("Read: " + " " + saved + " " +
+ // len + " " + new String( buffer, saved, 20
));
+
// No matter how we may (or may not) format it, send it
// on unformatted - we don't want to mess with how its
// sent to the other side, just how its displayed
- if ( out != null )
+ if ( out != null ) {
out.write( buffer, saved, len );
+ //System.out.println("Write: " + len );
+ }
if ( tmodel != null && reqSaved < 50 ) {
String old = (String) tmodel.getValueAt( tableIndex,
@@ -515,18 +537,21 @@
else {
textArea.append( new String( buffer, 0, len ) );
}
+ // System.out.println("Sleep 3");
this.sleep(3); // Let other threads have a chance to run
}
this.sleep(3); // Let other threads have a chance to run
// halt();
done = true ;
+ //System.out.println("Done reading " + this);
}
catch( Exception e ) {
- // e.printStackTrace();
+ e.printStackTrace();
}
}
- public void halt() {
+ public void halt() {
try {
+ //System.out.println("Closing " +this + " " + inSocket + " " +
outSocket );
if ( inSocket != null ) inSocket.close();
if ( outSocket != null ) outSocket.close();
inSocket = null ;
@@ -535,8 +560,8 @@
if ( out != null ) out.close();
in = null ;
out = null ;
- }
- catch( Exception e ) {
+ done=true;
+ } catch( Exception e ) {
e.printStackTrace();
}
}
@@ -741,6 +766,7 @@
// while( !rr2.isDone() ) {
Thread.sleep( 10 );
}
+ // System.out.println("Done ");
rr1.halt();
rr2.halt();