src/share/classes/java/net/SocketInputStream.java

Print this page
rev 5501 : imported patch io-trace

@@ -28,10 +28,11 @@
 import java.io.FileDescriptor;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.nio.channels.FileChannel;
 
+import sun.misc.IoTrace;
 import sun.net.ConnectionResetException;
 
 /**
  * This stream extends FileInputStream to implement a
  * SocketInputStream. Note that this class should <b>NOT</b> be

@@ -120,11 +121,11 @@
     public int read(byte b[], int off, int length) throws IOException {
         return read(b, off, length, impl.getTimeout());
     }
 
     int read(byte b[], int off, int length, int timeout) throws IOException {
-        int n;
+        int n = 0;
 
         // EOF already encountered
         if (eof) {
             return -1;
         }

@@ -142,10 +143,11 @@
             throw new ArrayIndexOutOfBoundsException();
         }
 
         boolean gotReset = false;
 
+        Object traceContext = IoTrace.socketReadBegin(impl.address, impl.port, timeout);
         // acquire file descriptor and do the read
         FileDescriptor fd = impl.acquireFD();
         try {
             n = socketRead0(fd, b, off, length, timeout);
             if (n > 0) {

@@ -153,27 +155,30 @@
             }
         } catch (ConnectionResetException rstExc) {
             gotReset = true;
         } finally {
             impl.releaseFD();
+            IoTrace.socketReadEnd(traceContext, n > 0 ? n : 0);
         }
 
         /*
          * We receive a "connection reset" but there may be bytes still
          * buffered on the socket
          */
         if (gotReset) {
+            traceContext = IoTrace.socketReadBegin(impl.address, impl.port, timeout);
             impl.setConnectionResetPending();
             impl.acquireFD();
             try {
                 n = socketRead0(fd, b, off, length, timeout);
                 if (n > 0) {
                     return n;
                 }
             } catch (ConnectionResetException rstExc) {
             } finally {
                 impl.releaseFD();
+                IoTrace.socketReadEnd(traceContext, n > 0 ? n : 0);
             }
         }
 
         /*
          * If we get here we are at EOF, the socket has been closed,