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

Print this page
rev 6052 : [mq]: jdk.patch

@@ -31,11 +31,11 @@
 import java.nio.ByteBuffer;
 import java.nio.channels.*;
 import java.nio.channels.spi.*;
 import java.util.*;
 import sun.net.NetHooks;
-
+import sun.misc.IoTrace;
 
 /**
  * An implementation of SocketChannels
  */
 

@@ -78,12 +78,12 @@
     private static final int ST_KILLPENDING = 3;
     private static final int ST_KILLED = 4;
     private int state = ST_UNINITIALIZED;
 
     // Binding
-    private SocketAddress localAddress;
-    private SocketAddress remoteAddress;
+    private InetSocketAddress localAddress;
+    private InetSocketAddress remoteAddress;
 
     // Input/Output open
     private boolean isInputOpen = true;
     private boolean isOutputOpen = true;
     private boolean readyToConnect = false;

@@ -276,10 +276,15 @@
             throw new NullPointerException();
 
         synchronized (readLock) {
             if (!ensureReadOpen())
                 return -1;
+            Object traceHandle = null;
+            if (isBlocking()) {
+                traceHandle = IoTrace.socketReadBegin(remoteAddress.getAddress(),
+                                                      remoteAddress.getPort(), 0);
+            }
             int n = 0;
             try {
 
                 // Set up the interruption machinery; see
                 // AbstractInterruptibleChannel for details

@@ -383,10 +388,12 @@
                 // interrupted at the exact moment that a non-blocking I/O
                 // request is made.
                 //
                 end(n > 0 || (n == IOStatus.UNAVAILABLE));
 
+                IoTrace.socketReadEnd(traceHandle, IOStatus.normalize(n));
+
                 // Extra case for socket channels: Asynchronous shutdown
                 //
                 synchronized (stateLock) {
                     if ((n <= 0) && (!isInputOpen))
                         return IOStatus.EOF;

@@ -405,10 +412,15 @@
             throw new IndexOutOfBoundsException();
         synchronized (readLock) {
             if (!ensureReadOpen())
                 return -1;
             long n = 0;
+            Object traceHandle = null;
+            if (isBlocking()) {
+                traceHandle = IoTrace.socketReadBegin(remoteAddress.getAddress(),
+                                                      remoteAddress.getPort(), 0);
+            }
             try {
                 begin();
                 synchronized (stateLock) {
                     if (!isOpen())
                         return 0;

@@ -422,10 +434,11 @@
                     return IOStatus.normalize(n);
                 }
             } finally {
                 readerCleanup();
                 end(n > 0 || (n == IOStatus.UNAVAILABLE));
+                IoTrace.socketReadEnd(traceHandle, IOStatus.normalize(n));
                 synchronized (stateLock) {
                     if ((n <= 0) && (!isInputOpen))
                         return IOStatus.EOF;
                 }
                 assert IOStatus.check(n);

@@ -437,10 +450,14 @@
         if (buf == null)
             throw new NullPointerException();
         synchronized (writeLock) {
             ensureWriteOpen();
             int n = 0;
+            Object traceHandle =
+                IoTrace.socketWriteBegin(remoteAddress.getAddress(),
+                                         remoteAddress.getPort());
+
             try {
                 begin();
                 synchronized (stateLock) {
                     if (!isOpen())
                         return 0;

@@ -453,10 +470,11 @@
                     return IOStatus.normalize(n);
                 }
             } finally {
                 writerCleanup();
                 end(n > 0 || (n == IOStatus.UNAVAILABLE));
+                IoTrace.socketWriteEnd(traceHandle, IOStatus.normalize(n));
                 synchronized (stateLock) {
                     if ((n <= 0) && (!isOutputOpen))
                         throw new AsynchronousCloseException();
                 }
                 assert IOStatus.check(n);

@@ -470,10 +488,13 @@
         if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
             throw new IndexOutOfBoundsException();
         synchronized (writeLock) {
             ensureWriteOpen();
             long n = 0;
+            Object traceHandle =
+                IoTrace.socketWriteBegin(remoteAddress.getAddress(),
+                                         remoteAddress.getPort());
             try {
                 begin();
                 synchronized (stateLock) {
                     if (!isOpen())
                         return 0;

@@ -486,10 +507,11 @@
                     return IOStatus.normalize(n);
                 }
             } finally {
                 writerCleanup();
                 end((n > 0) || (n == IOStatus.UNAVAILABLE));
+                IoTrace.socketWriteEnd(traceHandle, IOStatus.normalize(n));
                 synchronized (stateLock) {
                     if ((n <= 0) && (!isOutputOpen))
                         throw new AsynchronousCloseException();
                 }
                 assert IOStatus.check(n);