From de22da61863ed89fa877fb423904f31ab26730fc Mon Sep 17 00:00:00 2001 From: Jeroen Frijters Date: Tue, 19 Sep 2006 05:47:38 +0000 Subject: 2006-09-19 Jeroen Frijters * 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. --- java/net/ServerSocket.java | 22 +++++++++++----------- java/net/Socket.java | 14 ++------------ 2 files changed, 13 insertions(+), 23 deletions(-) (limited to 'java') diff --git a/java/net/ServerSocket.java b/java/net/ServerSocket.java index b689cf1d1..116227f8f 100644 --- a/java/net/ServerSocket.java +++ b/java/net/ServerSocket.java @@ -39,7 +39,6 @@ exception statement from your version. */ 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 @@ public class ServerSocket * 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 @@ public class ServerSocket 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 class ServerSocket */ public void close() throws IOException { - if (isClosed()) - return; - - impl.close(); + if (impl != null) + { + impl.close(); + impl = null; + } } /** @@ -422,10 +424,8 @@ public class ServerSocket */ 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 @@ public class ServerSocket return "ServerSocket[unbound]"; return ("ServerSocket[addr=" + getInetAddress() + ",port=" - + impl.getPort() + ",localport=" + impl.getLocalPort() + "]"); + + port + ",localport=" + getLocalPort() + "]"); } /** diff --git a/java/net/Socket.java b/java/net/Socket.java index 76140e526..63ba43727 100644 --- a/java/net/Socket.java +++ b/java/net/Socket.java @@ -39,7 +39,6 @@ exception statement from your version. */ 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 class Socket */ 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()); } /** -- cgit v1.2.1