src/share/classes/sun/nio/ch/SocketAdaptor.java

Print this page
rev 6099 : [mq]: io-trace

@@ -32,10 +32,13 @@
 import java.nio.channels.*;
 import java.security.AccessController;
 import java.security.PrivilegedExceptionAction;
 import java.util.*;
 
+import sun.misc.IoTrace;
+import sun.misc.IoTraceContext;
+
 
 // Make a socket channel look like a socket.
 //
 // The only aspects of java.net.Socket-hood that we don't attempt to emulate
 // here are the interrupted-I/O exceptions (which our Solaris implementations

@@ -189,14 +192,16 @@
                     throw new IllegalBlockingModeException();
                 if (timeout == 0)
                     return sc.read(bb);
                 sc.configureBlocking(false);
 
+                int n = 0;
+                IoTraceContext traceContext = IoTrace.socketReadBegin(getInetAddress(), getPort(), timeout);
                 try {
-                    int n;
-                    if ((n = sc.read(bb)) != 0)
+                    if ((n = sc.read(bb)) != 0) {
                         return n;
+                    }
                     long to = timeout;
                     for (;;) {
                         if (!sc.isOpen())
                             throw new ClosedChannelException();
                         long st = System.currentTimeMillis();

@@ -208,10 +213,11 @@
                         to -= System.currentTimeMillis() - st;
                         if (to <= 0)
                             throw new SocketTimeoutException();
                     }
                 } finally {
+                    IoTrace.socketReadEnd(traceContext, n > 0 ? n : 0);
                     if (sc.isOpen())
                         sc.configureBlocking(true);
                 }
 
             }