From dcbb69e84e9c71073608efebeefaa86de4bd97d3 Mon Sep 17 00:00:00 2001 From: mkoch Date: Tue, 25 Nov 2003 10:09:48 +0000 Subject: 2003-11-25 Michael Koch * java/net/DatagramSocket.java (factory): Made private. (closed): Removed. (DatagramSocket): Check impl argument, use constructor with SocketAddress argument. (close): Set impl to null, use isClosed(). (isClosed): Check for impl == null. (getLocalAddress): Use isClosed(). (getLocalPort): Check if socket is closed. (getSoTimeout): Likewise. (setSoTimeout): Likewise. (getSendBufferSize): Likewise. (setSendBufferSize): Likewise. (getReceiveBufferSize): Likewise. (setReceiveBufferSize): Likewise. (receive): Likewise. (send): Likewise. (bind): Likewise. (connect): Likewise. (setReuseAddress): Likewise. (getReuseAddress): Likewise. (setBroadcast): Likewise. (getBroadcast): Likewise. (setTrafficClass): Likewise. (getTrafficClass): Likewise. * java/net/MulticastSocket.java (getInterface): Check if socket is closed. (getTTL): Likewise. (getTimeToLive): Likewise. (setInterface): Likewise. (setNetworkInterface): Likewise. (getNetworkInterface): Likewise. (setLoopbackMode): Likewise. (setTTL): Likewise. (setTimeToLive): Likewise. (joinGroup): Likewise. (leaveGroup): Likewise. (send): Likewise. * java/net/ServerSocket.java (closed): Removed. (close): Check if socket is closed, set impl to null. (isClosed): Check impl == null; (ServerSocket): Check impl argument. (getInetAddress): Check if socket is bound. (getLocalPort): Likewise. (getLocalSocketAddress): Likewise. (bind): Check if socket is closed. (implAccept): Likewise. (setSoTimeout): Likewise. (getSoTimeout): Likewise. (setReuseAddress): Likewise. (getReuseAddress): Likewise. (setReceiveBufferSize): Likewise. (getReceiveBufferSize): Likewise. (toString): Make output compliant to JDK 1.4.2. * java/net/Socket.java (closed): Removed. (Socket): Fixed documentation. (connect): Check if socket is closed, changed exception text, fixed documentation. (getInputStream): Check of socket is closed and connected. (getOutputStream): Likewise. (bind): Check if socket is closed. (setTcpNoDelay): Likewise. (getTcpNoDelay): Likewise. (setSoLinger): Likewise. (getSoLinger): Likewise. (sendUrgentData): Likewise. (setOOBInline): Likewise. (getOOBInline): Likewise. (setSoTimeout): Likewise. (getSoTimeout): Likewise. (setSendBufferSize): Likewise. (getSendBufferSize): Likewise. (setReceiveBufferSize): Likewise. (getReceiveBufferSize): Likewise. (setKeepAlive): Likewise. (getKeepAlive): Likewise. (close): Likewise. (shutdownInput): Likewise. (shutdownOutput): Likewise. (getReuseAddress): Likewise. (getTrafficClass): Likewise. (setTrafficClass): Likewise. (isClosed): Check impl == null. (toString): Added missing ']'. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@73918 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/net/MulticastSocket.java | 51 ++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) (limited to 'libjava/java/net/MulticastSocket.java') diff --git a/libjava/java/net/MulticastSocket.java b/libjava/java/net/MulticastSocket.java index 097d52e9a5c..9c4d3e20490 100644 --- a/libjava/java/net/MulticastSocket.java +++ b/libjava/java/net/MulticastSocket.java @@ -125,6 +125,9 @@ public class MulticastSocket extends DatagramSocket */ public InetAddress getInterface() throws SocketException { + if (isClosed()) + throw new SocketException("socket is closed"); + return (InetAddress) impl.getOption(SocketOptions.IP_MULTICAST_IF); } @@ -143,6 +146,9 @@ public class MulticastSocket extends DatagramSocket */ public byte getTTL() throws IOException { + if (isClosed()) + throw new SocketException("socket is closed"); + // Use getTTL here rather than getTimeToLive in case we're using an impl // other than the default PlainDatagramSocketImpl and it doesn't have // getTimeToLive yet. @@ -161,6 +167,9 @@ public class MulticastSocket extends DatagramSocket */ public int getTimeToLive() throws IOException { + if (isClosed()) + throw new SocketException("socket is closed"); + return impl.getTimeToLive(); } @@ -175,6 +184,9 @@ public class MulticastSocket extends DatagramSocket */ public void setInterface(InetAddress addr) throws SocketException { + if (isClosed()) + throw new SocketException("socket is closed"); + impl.setOption(SocketOptions.IP_MULTICAST_IF, addr); } @@ -192,9 +204,8 @@ public class MulticastSocket extends DatagramSocket public void setNetworkInterface(NetworkInterface netIf) throws SocketException { - if (impl == null) - throw new SocketException ( - "MulticastSocket: Cant access socket implementation"); + if (isClosed()) + throw new SocketException("socket is closed"); Enumeration e = netIf.getInetAddresses (); @@ -219,9 +230,8 @@ public class MulticastSocket extends DatagramSocket public NetworkInterface getNetworkInterface() throws SocketException { - if (impl == null) - throw new SocketException ( - "MulticastSocket: Cant access socket implementation"); + if (isClosed()) + throw new SocketException("socket is closed"); InetAddress address = (InetAddress) impl.getOption (SocketOptions.IP_MULTICAST_IF); @@ -246,9 +256,8 @@ public class MulticastSocket extends DatagramSocket */ public void setLoopbackMode(boolean disable) throws SocketException { - if (impl == null) - throw new SocketException ( - "MulticastSocket: Cant access socket implementation"); + if (isClosed()) + throw new SocketException("socket is closed"); impl.setOption (SocketOptions.IP_MULTICAST_LOOP, new Boolean (disable)); } @@ -262,6 +271,9 @@ public class MulticastSocket extends DatagramSocket */ public boolean getLoopbackMode() throws SocketException { + if (isClosed()) + throw new SocketException("socket is closed"); + Object obj = impl.getOption (SocketOptions.IP_MULTICAST_LOOP); if (obj instanceof Boolean) @@ -284,6 +296,9 @@ public class MulticastSocket extends DatagramSocket */ public void setTTL(byte ttl) throws IOException { + if (isClosed()) + throw new SocketException("socket is closed"); + // Use setTTL here rather than setTimeToLive in case we're using an impl // other than the default PlainDatagramSocketImpl and it doesn't have // setTimeToLive yet. @@ -302,6 +317,9 @@ public class MulticastSocket extends DatagramSocket */ public void setTimeToLive(int ttl) throws IOException { + if (isClosed()) + throw new SocketException("socket is closed"); + if (ttl <= 0 || ttl > 255) throw new IllegalArgumentException("Invalid ttl: " + ttl); @@ -319,6 +337,9 @@ public class MulticastSocket extends DatagramSocket */ public void joinGroup(InetAddress mcastaddr) throws IOException { + if (isClosed()) + throw new SocketException("socket is closed"); + if (! mcastaddr.isMulticastAddress()) throw new IOException("Not a Multicast address"); @@ -340,6 +361,9 @@ public class MulticastSocket extends DatagramSocket */ public void leaveGroup(InetAddress mcastaddr) throws IOException { + if (isClosed()) + throw new SocketException("socket is closed"); + if (! mcastaddr.isMulticastAddress()) throw new IOException("Not a Multicast address"); @@ -371,6 +395,9 @@ public class MulticastSocket extends DatagramSocket public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException { + if (isClosed()) + throw new SocketException("socket is closed"); + if (! (mcastaddr instanceof InetSocketAddress)) throw new IllegalArgumentException ("SocketAddress type not supported"); @@ -406,6 +433,9 @@ public class MulticastSocket extends DatagramSocket public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException { + if (isClosed()) + throw new SocketException("socket is closed"); + InetSocketAddress tmp = (InetSocketAddress) mcastaddr; if (! tmp.getAddress ().isMulticastAddress ()) @@ -434,6 +464,9 @@ public class MulticastSocket extends DatagramSocket */ public synchronized void send(DatagramPacket p, byte ttl) throws IOException { + if (isClosed()) + throw new SocketException("socket is closed"); + SecurityManager s = System.getSecurityManager(); if (s != null) { -- cgit v1.2.1