Commit 66e5d61f by Michael Koch Committed by Michael Koch

2003-11-25 Michael Koch <konqueror@gmx.de>

	* 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 ']'.

From-SVN: r73918
parent dcb5fe8b
2003-11-25 Michael Koch <konqueror@gmx.de>
* 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 ']'.
2003-11-24 Tom Tromey <tromey@redhat.com> 2003-11-24 Tom Tromey <tromey@redhat.com>
* Makefile.in: Rebuilt. * Makefile.in: Rebuilt.
......
...@@ -67,7 +67,7 @@ public class DatagramSocket ...@@ -67,7 +67,7 @@ public class DatagramSocket
* This is the user DatagramSocketImplFactory for this class. If this * This is the user DatagramSocketImplFactory for this class. If this
* variable is null, a default factory is used. * variable is null, a default factory is used.
*/ */
static DatagramSocketImplFactory factory; private static DatagramSocketImplFactory factory;
/** /**
* This is the implementation object used by this socket. * This is the implementation object used by this socket.
...@@ -85,11 +85,6 @@ public class DatagramSocket ...@@ -85,11 +85,6 @@ public class DatagramSocket
private int remotePort = -1; private int remotePort = -1;
/** /**
* Indicates when the socket is closed.
*/
private boolean closed = false;
/**
* Creates a <code>DatagramSocket</code> from a specified * Creates a <code>DatagramSocket</code> from a specified
* <code>DatagramSocketImpl</code> instance * <code>DatagramSocketImpl</code> instance
* *
...@@ -100,6 +95,9 @@ public class DatagramSocket ...@@ -100,6 +95,9 @@ public class DatagramSocket
*/ */
protected DatagramSocket (DatagramSocketImpl impl) protected DatagramSocket (DatagramSocketImpl impl)
{ {
if (impl == null)
throw new NullPointerException("impl may not be null");
this.impl = impl; this.impl = impl;
this.remoteAddress = null; this.remoteAddress = null;
this.remotePort = -1; this.remotePort = -1;
...@@ -115,7 +113,7 @@ public class DatagramSocket ...@@ -115,7 +113,7 @@ public class DatagramSocket
*/ */
public DatagramSocket() throws SocketException public DatagramSocket() throws SocketException
{ {
this(0, null); this(new InetSocketAddress(0));
} }
/** /**
...@@ -130,7 +128,7 @@ public class DatagramSocket ...@@ -130,7 +128,7 @@ public class DatagramSocket
*/ */
public DatagramSocket(int port) throws SocketException public DatagramSocket(int port) throws SocketException
{ {
this(port, null); this(new InetSocketAddress(port));
} }
/** /**
...@@ -226,12 +224,12 @@ public class DatagramSocket ...@@ -226,12 +224,12 @@ public class DatagramSocket
*/ */
public void close() public void close()
{ {
if (!closed) if (!isClosed())
{ {
impl.close(); impl.close();
impl = null;
remoteAddress = null; remoteAddress = null;
remotePort = -1; remotePort = -1;
closed = true;
} }
} }
...@@ -270,8 +268,7 @@ public class DatagramSocket ...@@ -270,8 +268,7 @@ public class DatagramSocket
*/ */
public InetAddress getLocalAddress() public InetAddress getLocalAddress()
{ {
if (impl == null if (isClosed())
|| closed)
return null; return null;
InetAddress localAddr; InetAddress localAddr;
...@@ -303,6 +300,9 @@ public class DatagramSocket ...@@ -303,6 +300,9 @@ public class DatagramSocket
*/ */
public int getLocalPort() public int getLocalPort()
{ {
if (isClosed())
return -1;
return impl.getLocalPort(); return impl.getLocalPort();
} }
...@@ -318,8 +318,8 @@ public class DatagramSocket ...@@ -318,8 +318,8 @@ public class DatagramSocket
*/ */
public synchronized int getSoTimeout() throws SocketException public synchronized int getSoTimeout() throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT); Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
...@@ -342,6 +342,9 @@ public class DatagramSocket ...@@ -342,6 +342,9 @@ public class DatagramSocket
*/ */
public synchronized void setSoTimeout(int timeout) throws SocketException public synchronized void setSoTimeout(int timeout) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (timeout < 0) if (timeout < 0)
throw new IllegalArgumentException("Invalid timeout: " + timeout); throw new IllegalArgumentException("Invalid timeout: " + timeout);
...@@ -361,8 +364,8 @@ public class DatagramSocket ...@@ -361,8 +364,8 @@ public class DatagramSocket
*/ */
public int getSendBufferSize() throws SocketException public int getSendBufferSize() throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
Object obj = impl.getOption(SocketOptions.SO_SNDBUF); Object obj = impl.getOption(SocketOptions.SO_SNDBUF);
...@@ -386,6 +389,9 @@ public class DatagramSocket ...@@ -386,6 +389,9 @@ public class DatagramSocket
*/ */
public void setSendBufferSize(int size) throws SocketException public void setSendBufferSize(int size) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (size < 0) if (size < 0)
throw new IllegalArgumentException("Buffer size is less than 0"); throw new IllegalArgumentException("Buffer size is less than 0");
...@@ -405,8 +411,8 @@ public class DatagramSocket ...@@ -405,8 +411,8 @@ public class DatagramSocket
*/ */
public int getReceiveBufferSize() throws SocketException public int getReceiveBufferSize() throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
Object obj = impl.getOption(SocketOptions.SO_RCVBUF); Object obj = impl.getOption(SocketOptions.SO_RCVBUF);
...@@ -430,8 +436,8 @@ public class DatagramSocket ...@@ -430,8 +436,8 @@ public class DatagramSocket
*/ */
public void setReceiveBufferSize(int size) throws SocketException public void setReceiveBufferSize(int size) throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
if (size < 0) if (size < 0)
throw new IllegalArgumentException("Buffer size is less than 0"); throw new IllegalArgumentException("Buffer size is less than 0");
...@@ -514,12 +520,13 @@ public class DatagramSocket ...@@ -514,12 +520,13 @@ public class DatagramSocket
*/ */
public synchronized void receive(DatagramPacket p) throws IOException public synchronized void receive(DatagramPacket p) throws IOException
{ {
if (impl == null) if (isClosed())
throw new IOException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
if (remoteAddress != null && remoteAddress.isMulticastAddress ()) if (remoteAddress != null
throw new IOException ( && remoteAddress.isMulticastAddress())
"Socket connected to a multicast address my not receive"); throw new IOException
("Socket connected to a multicast address my not receive");
if (getChannel() != null if (getChannel() != null
&& !getChannel().isBlocking ()) && !getChannel().isBlocking ())
...@@ -549,6 +556,9 @@ public class DatagramSocket ...@@ -549,6 +556,9 @@ public class DatagramSocket
*/ */
public void send(DatagramPacket p) throws IOException public void send(DatagramPacket p) throws IOException
{ {
if (isClosed())
throw new SocketException("socket is closed");
// JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api. // JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api.
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null && !isConnected ()) if (s != null && !isConnected ())
...@@ -593,6 +603,9 @@ public class DatagramSocket ...@@ -593,6 +603,9 @@ public class DatagramSocket
public void bind (SocketAddress address) public void bind (SocketAddress address)
throws SocketException throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (! (address instanceof InetSocketAddress)) if (! (address instanceof InetSocketAddress))
throw new IllegalArgumentException (); throw new IllegalArgumentException ();
...@@ -612,7 +625,7 @@ public class DatagramSocket ...@@ -612,7 +625,7 @@ public class DatagramSocket
*/ */
public boolean isClosed() public boolean isClosed()
{ {
return closed; return impl == null;
} }
/** /**
...@@ -637,6 +650,8 @@ public class DatagramSocket ...@@ -637,6 +650,8 @@ public class DatagramSocket
*/ */
public void connect (SocketAddress address) throws SocketException public void connect (SocketAddress address) throws SocketException
{ {
if (isClosed())
if ( !(address instanceof InetSocketAddress) ) if ( !(address instanceof InetSocketAddress) )
throw new IllegalArgumentException ( throw new IllegalArgumentException (
"SocketAddress is not InetSocketAddress"); "SocketAddress is not InetSocketAddress");
...@@ -721,8 +736,8 @@ public class DatagramSocket ...@@ -721,8 +736,8 @@ public class DatagramSocket
*/ */
public void setReuseAddress(boolean on) throws SocketException public void setReuseAddress(boolean on) throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on)); impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on));
} }
...@@ -736,8 +751,8 @@ public class DatagramSocket ...@@ -736,8 +751,8 @@ public class DatagramSocket
*/ */
public boolean getReuseAddress() throws SocketException public boolean getReuseAddress() throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
Object obj = impl.getOption (SocketOptions.SO_REUSEADDR); Object obj = impl.getOption (SocketOptions.SO_REUSEADDR);
...@@ -758,8 +773,8 @@ public class DatagramSocket ...@@ -758,8 +773,8 @@ public class DatagramSocket
*/ */
public void setBroadcast(boolean on) throws SocketException public void setBroadcast(boolean on) throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
impl.setOption (SocketOptions.SO_BROADCAST, new Boolean (on)); impl.setOption (SocketOptions.SO_BROADCAST, new Boolean (on));
} }
...@@ -773,8 +788,8 @@ public class DatagramSocket ...@@ -773,8 +788,8 @@ public class DatagramSocket
*/ */
public boolean getBroadcast() throws SocketException public boolean getBroadcast() throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
Object obj = impl.getOption (SocketOptions.SO_BROADCAST); Object obj = impl.getOption (SocketOptions.SO_BROADCAST);
...@@ -799,8 +814,8 @@ public class DatagramSocket ...@@ -799,8 +814,8 @@ public class DatagramSocket
public void setTrafficClass(int tc) public void setTrafficClass(int tc)
throws SocketException throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ("Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
if (tc < 0 || tc > 255) if (tc < 0 || tc > 255)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
...@@ -819,8 +834,8 @@ public class DatagramSocket ...@@ -819,8 +834,8 @@ public class DatagramSocket
*/ */
public int getTrafficClass() throws SocketException public int getTrafficClass() throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException( "Cannot initialize Socket implementation"); throw new SocketException("socket is closed");
Object obj = impl.getOption(SocketOptions.IP_TOS); Object obj = impl.getOption(SocketOptions.IP_TOS);
......
...@@ -125,6 +125,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -125,6 +125,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public InetAddress getInterface() throws SocketException public InetAddress getInterface() throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
return (InetAddress) impl.getOption(SocketOptions.IP_MULTICAST_IF); return (InetAddress) impl.getOption(SocketOptions.IP_MULTICAST_IF);
} }
...@@ -143,6 +146,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -143,6 +146,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public byte getTTL() throws IOException 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 // Use getTTL here rather than getTimeToLive in case we're using an impl
// other than the default PlainDatagramSocketImpl and it doesn't have // other than the default PlainDatagramSocketImpl and it doesn't have
// getTimeToLive yet. // getTimeToLive yet.
...@@ -161,6 +167,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -161,6 +167,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public int getTimeToLive() throws IOException public int getTimeToLive() throws IOException
{ {
if (isClosed())
throw new SocketException("socket is closed");
return impl.getTimeToLive(); return impl.getTimeToLive();
} }
...@@ -175,6 +184,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -175,6 +184,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public void setInterface(InetAddress addr) throws SocketException public void setInterface(InetAddress addr) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
impl.setOption(SocketOptions.IP_MULTICAST_IF, addr); impl.setOption(SocketOptions.IP_MULTICAST_IF, addr);
} }
...@@ -192,9 +204,8 @@ public class MulticastSocket extends DatagramSocket ...@@ -192,9 +204,8 @@ public class MulticastSocket extends DatagramSocket
public void setNetworkInterface(NetworkInterface netIf) public void setNetworkInterface(NetworkInterface netIf)
throws SocketException throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ( throw new SocketException("socket is closed");
"MulticastSocket: Cant access socket implementation");
Enumeration e = netIf.getInetAddresses (); Enumeration e = netIf.getInetAddresses ();
...@@ -219,9 +230,8 @@ public class MulticastSocket extends DatagramSocket ...@@ -219,9 +230,8 @@ public class MulticastSocket extends DatagramSocket
public NetworkInterface getNetworkInterface() public NetworkInterface getNetworkInterface()
throws SocketException throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ( throw new SocketException("socket is closed");
"MulticastSocket: Cant access socket implementation");
InetAddress address = InetAddress address =
(InetAddress) impl.getOption (SocketOptions.IP_MULTICAST_IF); (InetAddress) impl.getOption (SocketOptions.IP_MULTICAST_IF);
...@@ -246,9 +256,8 @@ public class MulticastSocket extends DatagramSocket ...@@ -246,9 +256,8 @@ public class MulticastSocket extends DatagramSocket
*/ */
public void setLoopbackMode(boolean disable) throws SocketException public void setLoopbackMode(boolean disable) throws SocketException
{ {
if (impl == null) if (isClosed())
throw new SocketException ( throw new SocketException("socket is closed");
"MulticastSocket: Cant access socket implementation");
impl.setOption (SocketOptions.IP_MULTICAST_LOOP, new Boolean (disable)); impl.setOption (SocketOptions.IP_MULTICAST_LOOP, new Boolean (disable));
} }
...@@ -262,6 +271,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -262,6 +271,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public boolean getLoopbackMode() throws SocketException public boolean getLoopbackMode() throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object obj = impl.getOption (SocketOptions.IP_MULTICAST_LOOP); Object obj = impl.getOption (SocketOptions.IP_MULTICAST_LOOP);
if (obj instanceof Boolean) if (obj instanceof Boolean)
...@@ -284,6 +296,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -284,6 +296,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public void setTTL(byte ttl) throws IOException 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 // Use setTTL here rather than setTimeToLive in case we're using an impl
// other than the default PlainDatagramSocketImpl and it doesn't have // other than the default PlainDatagramSocketImpl and it doesn't have
// setTimeToLive yet. // setTimeToLive yet.
...@@ -302,6 +317,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -302,6 +317,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public void setTimeToLive(int ttl) throws IOException public void setTimeToLive(int ttl) throws IOException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (ttl <= 0 || ttl > 255) if (ttl <= 0 || ttl > 255)
throw new IllegalArgumentException("Invalid ttl: " + ttl); throw new IllegalArgumentException("Invalid ttl: " + ttl);
...@@ -319,6 +337,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -319,6 +337,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public void joinGroup(InetAddress mcastaddr) throws IOException public void joinGroup(InetAddress mcastaddr) throws IOException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (! mcastaddr.isMulticastAddress()) if (! mcastaddr.isMulticastAddress())
throw new IOException("Not a Multicast address"); throw new IOException("Not a Multicast address");
...@@ -340,6 +361,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -340,6 +361,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public void leaveGroup(InetAddress mcastaddr) throws IOException public void leaveGroup(InetAddress mcastaddr) throws IOException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (! mcastaddr.isMulticastAddress()) if (! mcastaddr.isMulticastAddress())
throw new IOException("Not a Multicast address"); throw new IOException("Not a Multicast address");
...@@ -371,6 +395,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -371,6 +395,9 @@ public class MulticastSocket extends DatagramSocket
public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
throws IOException throws IOException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (! (mcastaddr instanceof InetSocketAddress)) if (! (mcastaddr instanceof InetSocketAddress))
throw new IllegalArgumentException ("SocketAddress type not supported"); throw new IllegalArgumentException ("SocketAddress type not supported");
...@@ -406,6 +433,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -406,6 +433,9 @@ public class MulticastSocket extends DatagramSocket
public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
throws IOException throws IOException
{ {
if (isClosed())
throw new SocketException("socket is closed");
InetSocketAddress tmp = (InetSocketAddress) mcastaddr; InetSocketAddress tmp = (InetSocketAddress) mcastaddr;
if (! tmp.getAddress ().isMulticastAddress ()) if (! tmp.getAddress ().isMulticastAddress ())
...@@ -434,6 +464,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -434,6 +464,9 @@ public class MulticastSocket extends DatagramSocket
*/ */
public synchronized void send(DatagramPacket p, byte ttl) throws IOException public synchronized void send(DatagramPacket p, byte ttl) throws IOException
{ {
if (isClosed())
throw new SocketException("socket is closed");
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
{ {
......
...@@ -73,8 +73,6 @@ public class ServerSocket ...@@ -73,8 +73,6 @@ public class ServerSocket
*/ */
private SocketImpl impl; private SocketImpl impl;
private boolean closed = false;
/* /*
* This constructor is only used by java.nio. * This constructor is only used by java.nio.
*/ */
...@@ -82,6 +80,9 @@ public class ServerSocket ...@@ -82,6 +80,9 @@ public class ServerSocket
//ServerSocket (PlainSocketImpl impl) throws IOException //ServerSocket (PlainSocketImpl impl) throws IOException
ServerSocket (SocketImpl impl) throws IOException ServerSocket (SocketImpl impl) throws IOException
{ {
if (impl == null)
throw new NullPointerException("impl may not be null");
this.impl = impl; this.impl = impl;
this.impl.create (true); this.impl.create (true);
} }
...@@ -208,8 +209,8 @@ public class ServerSocket ...@@ -208,8 +209,8 @@ public class ServerSocket
*/ */
public void bind (SocketAddress endpoint, int backlog) throws IOException public void bind (SocketAddress endpoint, int backlog) throws IOException
{ {
if (closed) if (isClosed())
throw new SocketException ("ServerSocket is closed"); throw new SocketException("ServerSocket is closed");
if (! (endpoint instanceof InetSocketAddress)) if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ("Address type not supported"); throw new IllegalArgumentException ("Address type not supported");
...@@ -249,12 +250,16 @@ public class ServerSocket ...@@ -249,12 +250,16 @@ public class ServerSocket
*/ */
public InetAddress getInetAddress() public InetAddress getInetAddress()
{ {
if (!isBound())
return null;
try try
{ {
return (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR); return (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR);
} }
catch (SocketException e) catch (SocketException e)
{ {
// This never happens as we are bound.
return null; return null;
} }
} }
...@@ -266,6 +271,9 @@ public class ServerSocket ...@@ -266,6 +271,9 @@ public class ServerSocket
*/ */
public int getLocalPort() public int getLocalPort()
{ {
if (!isBound())
return -1;
return impl.getLocalPort(); return impl.getLocalPort();
} }
...@@ -276,12 +284,10 @@ public class ServerSocket ...@@ -276,12 +284,10 @@ public class ServerSocket
*/ */
public SocketAddress getLocalSocketAddress() public SocketAddress getLocalSocketAddress()
{ {
InetAddress addr = getInetAddress(); if (!isBound())
if (addr != null)
return new InetSocketAddress (getInetAddress(), getLocalPort());
return null; return null;
return new InetSocketAddress(getInetAddress(), getLocalPort());
} }
/** /**
...@@ -303,10 +309,9 @@ public class ServerSocket ...@@ -303,10 +309,9 @@ public class ServerSocket
if (sm != null) if (sm != null)
sm.checkListen (impl.getLocalPort ()); sm.checkListen (impl.getLocalPort ());
Socket s = new Socket(); Socket socket = new Socket();
implAccept (s); implAccept (socket);
return socket;
return s;
} }
/** /**
...@@ -322,14 +327,17 @@ public class ServerSocket ...@@ -322,14 +327,17 @@ public class ServerSocket
* *
* @since 1.1 * @since 1.1
*/ */
protected final void implAccept (Socket s) protected final void implAccept (Socket socket)
throws IOException throws IOException
{ {
if (isClosed())
throw new SocketException("ServerSocket is closed");
if (getChannel() != null if (getChannel() != null
&& !getChannel().isBlocking()) && !getChannel().isBlocking())
throw new IllegalBlockingModeException(); throw new IllegalBlockingModeException();
impl.accept(s.impl); impl.accept(socket.getImpl());
} }
/** /**
...@@ -339,12 +347,15 @@ public class ServerSocket ...@@ -339,12 +347,15 @@ public class ServerSocket
*/ */
public void close () throws IOException public void close () throws IOException
{ {
impl.close (); if (!isClosed())
{
impl.close();
if (getChannel() != null) if (getChannel() != null)
getChannel().close (); getChannel().close();
closed = true; impl = null;
}
} }
/** /**
...@@ -387,7 +398,7 @@ public class ServerSocket ...@@ -387,7 +398,7 @@ public class ServerSocket
*/ */
public boolean isClosed() public boolean isClosed()
{ {
return closed; return impl == null;
} }
/** /**
...@@ -404,6 +415,9 @@ public class ServerSocket ...@@ -404,6 +415,9 @@ public class ServerSocket
*/ */
public void setSoTimeout (int timeout) throws SocketException public void setSoTimeout (int timeout) throws SocketException
{ {
if (isClosed())
throw new SocketException("ServerSocket is closed");
if (timeout < 0) if (timeout < 0)
throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0"); throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0");
...@@ -424,6 +438,9 @@ public class ServerSocket ...@@ -424,6 +438,9 @@ public class ServerSocket
*/ */
public int getSoTimeout () throws IOException public int getSoTimeout () throws IOException
{ {
if (isClosed())
throw new SocketException("ServerSocket is closed");
Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT); Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
if (!(timeout instanceof Integer)) if (!(timeout instanceof Integer))
...@@ -442,6 +459,9 @@ public class ServerSocket ...@@ -442,6 +459,9 @@ public class ServerSocket
public void setReuseAddress (boolean on) public void setReuseAddress (boolean on)
throws SocketException throws SocketException
{ {
if (isClosed())
throw new SocketException("ServerSocket is closed");
impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on)); impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on));
} }
...@@ -455,6 +475,9 @@ public class ServerSocket ...@@ -455,6 +475,9 @@ public class ServerSocket
public boolean getReuseAddress() public boolean getReuseAddress()
throws SocketException throws SocketException
{ {
if (isClosed())
throw new SocketException("ServerSocket is closed");
Object reuseaddr = impl.getOption (SocketOptions.SO_REUSEADDR); Object reuseaddr = impl.getOption (SocketOptions.SO_REUSEADDR);
if (!(reuseaddr instanceof Boolean)) if (!(reuseaddr instanceof Boolean))
...@@ -478,6 +501,9 @@ public class ServerSocket ...@@ -478,6 +501,9 @@ public class ServerSocket
public void setReceiveBufferSize (int size) public void setReceiveBufferSize (int size)
throws SocketException throws SocketException
{ {
if (isClosed())
throw new SocketException("ServerSocket is closed");
if (size <= 0) if (size <= 0)
throw new IllegalArgumentException ("SO_RCVBUF value must be > 0"); throw new IllegalArgumentException ("SO_RCVBUF value must be > 0");
...@@ -498,6 +524,9 @@ public class ServerSocket ...@@ -498,6 +524,9 @@ public class ServerSocket
public int getReceiveBufferSize () public int getReceiveBufferSize ()
throws SocketException throws SocketException
{ {
if (isClosed())
throw new SocketException("ServerSocket is closed");
Object buf = impl.getOption (SocketOptions.SO_RCVBUF); Object buf = impl.getOption (SocketOptions.SO_RCVBUF);
if (!(buf instanceof Integer)) if (!(buf instanceof Integer))
...@@ -513,10 +542,14 @@ public class ServerSocket ...@@ -513,10 +542,14 @@ public class ServerSocket
*/ */
public String toString () public String toString ()
{ {
return "ServerSocket" + impl.toString(); if (!isBound())
} return "ServerSocket[unbound]";
// Class methods return ("ServerSocket[addr=" + impl.getInetAddress()
+ ",port=" + impl.getPort()
+ ",localport=" + impl.getLocalPort()
+ "]");
}
/** /**
* Sets the <code>SocketImplFactory</code> for all * Sets the <code>SocketImplFactory</code> for all
......
...@@ -68,29 +68,22 @@ import java.nio.channels.IllegalBlockingModeException; ...@@ -68,29 +68,22 @@ import java.nio.channels.IllegalBlockingModeException;
*/ */
public class Socket public class Socket
{ {
// Class Variables
/** /**
* This is the user SocketImplFactory for this class. If this variable is * This is the user SocketImplFactory for this class. If this variable is
* null, a default factory is used. * null, a default factory is used.
*/ */
static SocketImplFactory factory; static SocketImplFactory factory;
// Instance Variables
/** /**
* The implementation object to which calls are redirected * The implementation object to which calls are redirected
*/ */
SocketImpl impl; private SocketImpl impl;
private boolean implCreated = false; private boolean implCreated = false;
private boolean inputShutdown = false; private boolean inputShutdown = false;
private boolean outputShutdown = false; private boolean outputShutdown = false;
private boolean closed = false;
/** /**
* Initializes a new instance of <code>Socket</code> object without * Initializes a new instance of <code>Socket</code> object without
* connecting to a remote host. This useful for subclasses of socket that * connecting to a remote host. This useful for subclasses of socket that
...@@ -175,7 +168,7 @@ public class Socket ...@@ -175,7 +168,7 @@ public class Socket
* *
* @param host The name of the remote host to connect to. * @param host The name of the remote host to connect to.
* @param port The remote port to connect to. * @param port The remote port to connect to.
* @param loadAddr The local address to bind to. * @param localAddr The local address to bind to.
* @param localPort The local port to bind to. * @param localPort The local port to bind to.
* *
* @exception SecurityException If the <code>SecurityManager</code> * @exception SecurityException If the <code>SecurityManager</code>
...@@ -298,7 +291,8 @@ public class Socket ...@@ -298,7 +291,8 @@ public class Socket
// that default. JDK 1.2 doc infers not to do a bind. // that default. JDK 1.2 doc infers not to do a bind.
} }
private SocketImpl getImpl() // This has to be accessible from java.net.ServerSocket.
SocketImpl getImpl()
throws SocketException throws SocketException
{ {
try try
...@@ -331,8 +325,8 @@ public class Socket ...@@ -331,8 +325,8 @@ public class Socket
*/ */
public void bind (SocketAddress bindpoint) throws IOException public void bind (SocketAddress bindpoint) throws IOException
{ {
if (closed) if (isClosed())
throw new SocketException ("Socket is closed"); throw new SocketException("socket is closed");
// XXX: JDK 1.4.1 API documentation says that if bindpoint is null the // XXX: JDK 1.4.1 API documentation says that if bindpoint is null the
// socket will be bound to an ephemeral port and a valid local address. // socket will be bound to an ephemeral port and a valid local address.
...@@ -390,6 +384,8 @@ public class Socket ...@@ -390,6 +384,8 @@ public class Socket
* until established or an error occurs. * until established or an error occurs.
* *
* @param endpoint The address to connect to * @param endpoint The address to connect to
* @param timeout The length of the timeout in milliseconds, or
* 0 to indicate no timeout.
* *
* @exception IOException If an error occurs * @exception IOException If an error occurs
* @exception IllegalArgumentException If the address type is not supported * @exception IllegalArgumentException If the address type is not supported
...@@ -402,11 +398,11 @@ public class Socket ...@@ -402,11 +398,11 @@ public class Socket
public void connect (SocketAddress endpoint, int timeout) public void connect (SocketAddress endpoint, int timeout)
throws IOException throws IOException
{ {
if (closed) if (isClosed())
throw new SocketException ("Socket is closed"); throw new SocketException("socket is closed");
if (! (endpoint instanceof InetSocketAddress)) if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ("Address type not supported"); throw new IllegalArgumentException("unsupported address type");
if (getChannel() != null if (getChannel() != null
&& !getChannel().isBlocking ()) && !getChannel().isBlocking ())
...@@ -598,10 +594,13 @@ public class Socket ...@@ -598,10 +594,13 @@ public class Socket
*/ */
public InputStream getInputStream () throws IOException public InputStream getInputStream () throws IOException
{ {
if (getImpl() != null) if (isClosed())
return getImpl().getInputStream(); throw new SocketException("socket is closed");
if (!isConnected())
throw new IOException("not connected");
throw new IOException("Not connected"); return getImpl().getInputStream();
} }
/** /**
...@@ -613,10 +612,13 @@ public class Socket ...@@ -613,10 +612,13 @@ public class Socket
*/ */
public OutputStream getOutputStream () throws IOException public OutputStream getOutputStream () throws IOException
{ {
if (getImpl() != null) if (isClosed())
return getImpl().getOutputStream(); throw new SocketException("socket is closed");
throw new IOException("Not connected"); if (!isConnected())
throw new IOException("not connected");
return getImpl().getOutputStream();
} }
/** /**
...@@ -630,6 +632,9 @@ public class Socket ...@@ -630,6 +632,9 @@ public class Socket
*/ */
public void setTcpNoDelay (boolean on) throws SocketException public void setTcpNoDelay (boolean on) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
getImpl().setOption(SocketOptions.TCP_NODELAY, new Boolean(on)); getImpl().setOption(SocketOptions.TCP_NODELAY, new Boolean(on));
} }
...@@ -647,6 +652,9 @@ public class Socket ...@@ -647,6 +652,9 @@ public class Socket
*/ */
public boolean getTcpNoDelay() throws SocketException public boolean getTcpNoDelay() throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object on = getImpl().getOption(SocketOptions.TCP_NODELAY); Object on = getImpl().getOption(SocketOptions.TCP_NODELAY);
if (on instanceof Boolean) if (on instanceof Boolean)
...@@ -674,6 +682,9 @@ public class Socket ...@@ -674,6 +682,9 @@ public class Socket
*/ */
public void setSoLinger(boolean on, int linger) throws SocketException public void setSoLinger(boolean on, int linger) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (on == true) if (on == true)
{ {
if (linger < 0) if (linger < 0)
...@@ -708,6 +719,9 @@ public class Socket ...@@ -708,6 +719,9 @@ public class Socket
*/ */
public int getSoLinger() throws SocketException public int getSoLinger() throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object linger = getImpl().getOption(SocketOptions.SO_LINGER); Object linger = getImpl().getOption(SocketOptions.SO_LINGER);
if (linger instanceof Integer) if (linger instanceof Integer)
...@@ -728,6 +742,9 @@ public class Socket ...@@ -728,6 +742,9 @@ public class Socket
*/ */
public void sendUrgentData (int data) throws IOException public void sendUrgentData (int data) throws IOException
{ {
if (isClosed())
throw new SocketException("socket is closed");
getImpl().sendUrgentData (data); getImpl().sendUrgentData (data);
} }
...@@ -742,18 +759,26 @@ public class Socket ...@@ -742,18 +759,26 @@ public class Socket
*/ */
public void setOOBInline (boolean on) throws SocketException public void setOOBInline (boolean on) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
getImpl().setOption(SocketOptions.SO_OOBINLINE, new Boolean(on)); getImpl().setOption(SocketOptions.SO_OOBINLINE, new Boolean(on));
} }
/** /**
* Returns the current setting of the SO_OOBINLINE option for this socket * Returns the current setting of the SO_OOBINLINE option for this socket
* *
* @return True if SO_OOBINLINE is set, false otherwise.
*
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
* @since 1.4 * @since 1.4
*/ */
public boolean getOOBInline () throws SocketException public boolean getOOBInline () throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_OOBINLINE); Object buf = getImpl().getOption(SocketOptions.SO_OOBINLINE);
if (buf instanceof Boolean) if (buf instanceof Boolean)
...@@ -781,6 +806,9 @@ public class Socket ...@@ -781,6 +806,9 @@ public class Socket
*/ */
public synchronized void setSoTimeout (int timeout) throws SocketException public synchronized void setSoTimeout (int timeout) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (timeout < 0) if (timeout < 0)
throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0"); throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0");
...@@ -806,6 +834,9 @@ public class Socket ...@@ -806,6 +834,9 @@ public class Socket
*/ */
public synchronized int getSoTimeout () throws SocketException public synchronized int getSoTimeout () throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object timeout = getImpl().getOption(SocketOptions.SO_TIMEOUT); Object timeout = getImpl().getOption(SocketOptions.SO_TIMEOUT);
if (timeout instanceof Integer) if (timeout instanceof Integer)
return(((Integer)timeout).intValue()); return(((Integer)timeout).intValue());
...@@ -827,6 +858,9 @@ public class Socket ...@@ -827,6 +858,9 @@ public class Socket
*/ */
public void setSendBufferSize (int size) throws SocketException public void setSendBufferSize (int size) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (size <= 0) if (size <= 0)
throw new IllegalArgumentException("SO_SNDBUF value must be > 0"); throw new IllegalArgumentException("SO_SNDBUF value must be > 0");
...@@ -846,6 +880,9 @@ public class Socket ...@@ -846,6 +880,9 @@ public class Socket
*/ */
public int getSendBufferSize () throws SocketException public int getSendBufferSize () throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF); Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF);
if (buf instanceof Integer) if (buf instanceof Integer)
...@@ -868,6 +905,9 @@ public class Socket ...@@ -868,6 +905,9 @@ public class Socket
*/ */
public void setReceiveBufferSize (int size) throws SocketException public void setReceiveBufferSize (int size) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (size <= 0) if (size <= 0)
throw new IllegalArgumentException("SO_RCVBUF value must be > 0"); throw new IllegalArgumentException("SO_RCVBUF value must be > 0");
...@@ -887,6 +927,9 @@ public class Socket ...@@ -887,6 +927,9 @@ public class Socket
*/ */
public int getReceiveBufferSize () throws SocketException public int getReceiveBufferSize () throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF); Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF);
if (buf instanceof Integer) if (buf instanceof Integer)
...@@ -907,6 +950,9 @@ public class Socket ...@@ -907,6 +950,9 @@ public class Socket
*/ */
public void setKeepAlive (boolean on) throws SocketException public void setKeepAlive (boolean on) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
getImpl().setOption(SocketOptions.SO_KEEPALIVE, new Boolean(on)); getImpl().setOption(SocketOptions.SO_KEEPALIVE, new Boolean(on));
} }
...@@ -922,6 +968,9 @@ public class Socket ...@@ -922,6 +968,9 @@ public class Socket
*/ */
public boolean getKeepAlive () throws SocketException public boolean getKeepAlive () throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object buf = getImpl().getOption(SocketOptions.SO_KEEPALIVE); Object buf = getImpl().getOption(SocketOptions.SO_KEEPALIVE);
if (buf instanceof Boolean) if (buf instanceof Boolean)
...@@ -937,13 +986,15 @@ public class Socket ...@@ -937,13 +986,15 @@ public class Socket
*/ */
public synchronized void close () throws IOException public synchronized void close () throws IOException
{ {
if (getImpl() != null) if (isClosed())
throw new SocketException("socket is closed");
getImpl().close(); getImpl().close();
if (getChannel() != null) if (getChannel() != null)
getChannel().close(); getChannel().close();
closed = true; impl = null;
} }
/** /**
...@@ -958,7 +1009,8 @@ public class Socket ...@@ -958,7 +1009,8 @@ public class Socket
if (isConnected()) if (isConnected())
return ("Socket[addr=" + getImpl().getInetAddress() return ("Socket[addr=" + getImpl().getInetAddress()
+ ",port=" + getImpl().getPort() + ",port=" + getImpl().getPort()
+ ",localport=" + getImpl().getLocalPort()); + ",localport=" + getImpl().getLocalPort()
+ "]");
} }
catch (SocketException e) catch (SocketException e)
{ {
...@@ -968,8 +1020,6 @@ public class Socket ...@@ -968,8 +1020,6 @@ public class Socket
return "Socket[unconnected]"; return "Socket[unconnected]";
} }
// Class Methods
/** /**
* Sets the <code>SocketImplFactory</code>. This may be done only once per * Sets the <code>SocketImplFactory</code>. This may be done only once per
* virtual machine. Subsequent attempts will generate a * virtual machine. Subsequent attempts will generate a
...@@ -1010,9 +1060,10 @@ public class Socket ...@@ -1010,9 +1060,10 @@ public class Socket
*/ */
public void shutdownInput() throws IOException public void shutdownInput() throws IOException
{ {
if (getImpl() != null) if (isClosed())
getImpl().shutdownInput(); throw new SocketException("socket is closed");
getImpl().shutdownInput();
inputShutdown = true; inputShutdown = true;
} }
...@@ -1025,9 +1076,10 @@ public class Socket ...@@ -1025,9 +1076,10 @@ public class Socket
*/ */
public void shutdownOutput() throws IOException public void shutdownOutput() throws IOException
{ {
if (getImpl() != null) if (isClosed())
getImpl().shutdownOutput(); throw new SocketException("socket is closed");
getImpl().shutdownOutput();
outputShutdown = true; outputShutdown = true;
} }
...@@ -1046,12 +1098,17 @@ public class Socket ...@@ -1046,12 +1098,17 @@ public class Socket
/** /**
* Checks if the SO_REUSEADDR option is enabled * Checks if the SO_REUSEADDR option is enabled
* *
* @return True if SO_REUSEADDR is set, false otherwise.
*
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
* @since 1.4 * @since 1.4
*/ */
public boolean getReuseAddress () throws SocketException public boolean getReuseAddress () throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object reuseaddr = getImpl().getOption (SocketOptions.SO_REUSEADDR); Object reuseaddr = getImpl().getOption (SocketOptions.SO_REUSEADDR);
if (!(reuseaddr instanceof Boolean)) if (!(reuseaddr instanceof Boolean))
...@@ -1063,6 +1120,8 @@ public class Socket ...@@ -1063,6 +1120,8 @@ public class Socket
/** /**
* Enables/Disables the SO_REUSEADDR option * Enables/Disables the SO_REUSEADDR option
* *
* @param reuseAddress True if SO_REUSEADDR should be set.
*
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
* @since 1.4 * @since 1.4
...@@ -1075,6 +1134,8 @@ public class Socket ...@@ -1075,6 +1134,8 @@ public class Socket
/** /**
* Returns the current traffic class * Returns the current traffic class
* *
* @return The current traffic class.
*
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
* @see Socket#setTrafficClass(int tc) * @see Socket#setTrafficClass(int tc)
...@@ -1083,6 +1144,9 @@ public class Socket ...@@ -1083,6 +1144,9 @@ public class Socket
*/ */
public int getTrafficClass () throws SocketException public int getTrafficClass () throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
Object obj = getImpl().getOption(SocketOptions.IP_TOS); Object obj = getImpl().getOption(SocketOptions.IP_TOS);
if (obj instanceof Integer) if (obj instanceof Integer)
...@@ -1105,6 +1169,9 @@ public class Socket ...@@ -1105,6 +1169,9 @@ public class Socket
*/ */
public void setTrafficClass (int tc) throws SocketException public void setTrafficClass (int tc) throws SocketException
{ {
if (isClosed())
throw new SocketException("socket is closed");
if (tc < 0 || tc > 255) if (tc < 0 || tc > 255)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
...@@ -1114,6 +1181,8 @@ public class Socket ...@@ -1114,6 +1181,8 @@ public class Socket
/** /**
* Checks if the socket is connected * Checks if the socket is connected
* *
* @return True if socket is connected, false otherwise.
*
* @since 1.4 * @since 1.4
*/ */
public boolean isConnected () public boolean isConnected ()
...@@ -1131,6 +1200,8 @@ public class Socket ...@@ -1131,6 +1200,8 @@ public class Socket
/** /**
* Checks if the socket is already bound. * Checks if the socket is already bound.
* *
* @return True if socket is bound, false otherwise.
*
* @since 1.4 * @since 1.4
*/ */
public boolean isBound () public boolean isBound ()
...@@ -1141,16 +1212,20 @@ public class Socket ...@@ -1141,16 +1212,20 @@ public class Socket
/** /**
* Checks if the socket is closed. * Checks if the socket is closed.
* *
* @return True if socket is closed, false otherwise.
*
* @since 1.4 * @since 1.4
*/ */
public boolean isClosed () public boolean isClosed ()
{ {
return closed; return impl == null;
} }
/** /**
* Checks if the socket's input stream is shutdown * Checks if the socket's input stream is shutdown
* *
* @return True if input is shut down.
*
* @since 1.4 * @since 1.4
*/ */
public boolean isInputShutdown () public boolean isInputShutdown ()
...@@ -1161,6 +1236,8 @@ public class Socket ...@@ -1161,6 +1236,8 @@ public class Socket
/** /**
* Checks if the socket's output stream is shutdown * Checks if the socket's output stream is shutdown
* *
* @return True if output is shut down.
*
* @since 1.4 * @since 1.4
*/ */
public boolean isOutputShutdown () public boolean isOutputShutdown ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment