Hi,

I committed the previously discussed patch (minus the SocketChannelImpl
import that I accidentally removed).

Regards,
Jeroen

2006-09-19  Jeroen Frijters  <[EMAIL PROTECTED]>

        * gnu/java/nio/SocketChannelImpl.java: Removed unused import.
        * java/net/ServerSocket.java
        (port): New field.
        (bind): Set port field.
        (close): Set impl to null.
        (isClosed): Check impl and channel instead of using VMChannel.
        (toString): Use port field and getLocalPort() method.
        * java/net/Socket.java
        (isClosed): Check impl and channel instead of using VMChannel.
Index: java/net/ServerSocket.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/ServerSocket.java,v
retrieving revision 1.46
diff -u -r1.46 ServerSocket.java
--- java/net/ServerSocket.java  17 Sep 2006 07:31:42 -0000      1.46
+++ java/net/ServerSocket.java  18 Sep 2006 06:38:45 -0000
@@ -39,7 +39,6 @@
 package java.net;
 
 import gnu.java.net.PlainSocketImpl;
-import gnu.java.nio.VMChannel;
 
 import java.io.IOException;
 import java.nio.channels.IllegalBlockingModeException;
@@ -80,6 +79,7 @@
    * We need to retain the local address even after the socket is closed.
    */
   private InetSocketAddress local;
+  private int port;
 
   /*
    * This constructor is only used by java.nio.
@@ -238,7 +238,8 @@
 
     try
       {
-       impl.bind(addr, tmp.getPort());
+        port = tmp.getPort();
+       impl.bind(addr, port);
        impl.listen(backlog);
        local = new InetSocketAddress(
             (InetAddress) impl.getOption(SocketOptions.SO_BINDADDR),
@@ -379,10 +380,11 @@
    */
   public void close() throws IOException
   {
-    if (isClosed())
-      return;
-
-    impl.close();
+    if (impl != null)
+      {
+        impl.close();
+        impl = null;
+      }
   }
 
   /**
@@ -422,10 +424,8 @@
    */
   public boolean isClosed()
   {
-    VMChannel vmchannel = ((PlainSocketImpl) impl).getVMChannel();
-    if (vmchannel == null) // Not created yet.
-      return false;
-    return vmchannel.getState().isClosed();
+    ServerSocketChannel channel = getChannel();
+    return impl == null || (channel != null && ! channel.isOpen());
   }
 
   /**
@@ -573,7 +573,7 @@
       return "ServerSocket[unbound]";
 
     return ("ServerSocket[addr=" + getInetAddress() + ",port="
-           + impl.getPort() + ",localport=" + impl.getLocalPort() + "]");
+           + port + ",localport=" + getLocalPort() + "]");
   }
 
   /**
Index: java/net/Socket.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/Socket.java,v
retrieving revision 1.57
diff -u -r1.57 Socket.java
--- java/net/Socket.java        17 Sep 2006 07:31:42 -0000      1.57
+++ java/net/Socket.java        18 Sep 2006 06:37:18 -0000
@@ -39,7 +39,6 @@
 package java.net;
 
 import gnu.java.net.PlainSocketImpl;
-import gnu.java.nio.VMChannel;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -1223,17 +1222,8 @@
    */
   public boolean isClosed()
   {
-    if (impl == null)
-      return true;
-    if (impl instanceof PlainSocketImpl)
-      {
-        VMChannel vmchannel = ((PlainSocketImpl) impl).getVMChannel();
-        if (vmchannel == null)
-          return false;  // Not created yet.
-        VMChannel.State state = vmchannel.getState();
-        return state.isClosed();
-      }
-    return false;
+    SocketChannel channel = getChannel();
+    return impl == null || (channel != null && ! channel.isOpen());
   }
 
   /**

Reply via email to