Commit 4aa74bd3 by Michael Koch Committed by Michael Koch

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

	* java/net/DatagramSocket.java
	(impl): Made private.
	(bound): New private member variable.
	(DatagramSocket): Fixed documentation, use getImpl().
	(getImpl): New package-private method.
	(isClosed): Use getImpl().
	(getLocalAddress): Completed documentation, use getImpl().
	(getLocalPort): Use getImpl().
	(getSoTimeout): Likewise.
	(setSoTimeout): Likewise.
	(getSendBufferSize): Likewise.
	(setSendBufferSize): Likewise.
	(getReceiveBufferSize): Likewise.
	(setReceiveBufferSize): Likewise.
	(connect): Likewise.
	(disconnect): Likewise.
	(receive): Likewise.
	(send): Likewise.
	(setReuseAddress): Likewise.
	(setTrafficClass): Likewise.
	(bind): Added message to exception.
	(isClosed): Completed documentation.
	(getChannel): Likewise.
	(connect): Added missing exception, refined exception message.
	(isBound): Completed documentation, just return bound.
	(isConnected): Completed documentation.
	(getRemoteSocketAddress): Likewise.
	(getReuseAddress): Completed documentation, use getImpl().
	(setSoBroadcast): Likewise.
	(getSoBroadcast): Likewise.
	(getTrafficClass): Likewise.
	(getLocalSocketAddress): Simplified.
	* java/net/MulticastSocket.java
	(MulticastSocket): Removed comment not applying anymore.
	(getInterface): Use getImpl().
	(getTTL): Likewise.
	(getTimeToLive): Likewise.
	(setInterface): Likewise.
	(setNetworkInterface): Likewise.
	(getNetworkInterface): Likewise.
	(setLoopback): Likewise.
	(getLoopback): Likewise.
	(setTTL): Likewise.
	(setTimeToLive): Likewise.
	(joinGroup): Likewise.
	(leaveGroup): Likewise.
	(send): Likewise.

From-SVN: r73951
parent 88096b2a
2003-11-26 Michael Koch <konqueror@gmx.de> 2003-11-26 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
(impl): Made private.
(bound): New private member variable.
(DatagramSocket): Fixed documentation, use getImpl().
(getImpl): New package-private method.
(isClosed): Use getImpl().
(getLocalAddress): Completed documentation, use getImpl().
(getLocalPort): Use getImpl().
(getSoTimeout): Likewise.
(setSoTimeout): Likewise.
(getSendBufferSize): Likewise.
(setSendBufferSize): Likewise.
(getReceiveBufferSize): Likewise.
(setReceiveBufferSize): Likewise.
(connect): Likewise.
(disconnect): Likewise.
(receive): Likewise.
(send): Likewise.
(setReuseAddress): Likewise.
(setTrafficClass): Likewise.
(bind): Added message to exception.
(isClosed): Completed documentation.
(getChannel): Likewise.
(connect): Added missing exception, refined exception message.
(isBound): Completed documentation, just return bound.
(isConnected): Completed documentation.
(getRemoteSocketAddress): Likewise.
(getReuseAddress): Completed documentation, use getImpl().
(setSoBroadcast): Likewise.
(getSoBroadcast): Likewise.
(getTrafficClass): Likewise.
(getLocalSocketAddress): Simplified.
* java/net/MulticastSocket.java
(MulticastSocket): Removed comment not applying anymore.
(getInterface): Use getImpl().
(getTTL): Likewise.
(getTimeToLive): Likewise.
(setInterface): Likewise.
(setNetworkInterface): Likewise.
(getNetworkInterface): Likewise.
(setLoopback): Likewise.
(getLoopback): Likewise.
(setTTL): Likewise.
(setTimeToLive): Likewise.
(joinGroup): Likewise.
(leaveGroup): Likewise.
(send): Likewise.
2003-11-26 Michael Koch <konqueror@gmx.de>
* java/net/Socket.java * java/net/Socket.java
(implCreated): Dont set default value explicitely, added (implCreated): Dont set default value explicitely, added
documentation. documentation.
......
...@@ -72,7 +72,12 @@ public class DatagramSocket ...@@ -72,7 +72,12 @@ public class DatagramSocket
/** /**
* This is the implementation object used by this socket. * This is the implementation object used by this socket.
*/ */
DatagramSocketImpl impl; private DatagramSocketImpl impl;
/**
* True if socket implementation was created.
*/
private boolean implCreated;
/** /**
* This is the address we are "connected" to * This is the address we are "connected" to
...@@ -85,6 +90,11 @@ public class DatagramSocket ...@@ -85,6 +90,11 @@ public class DatagramSocket
private int remotePort = -1; private int remotePort = -1;
/** /**
* True if socket is bound.
*/
private boolean bound;
/**
* Creates a <code>DatagramSocket</code> from a specified * Creates a <code>DatagramSocket</code> from a specified
* <code>DatagramSocketImpl</code> instance * <code>DatagramSocketImpl</code> instance
* *
...@@ -151,8 +161,7 @@ public class DatagramSocket ...@@ -151,8 +161,7 @@ public class DatagramSocket
* Initializes a new instance of <code>DatagramSocket</code> that binds to * Initializes a new instance of <code>DatagramSocket</code> that binds to
* the specified local port and address. * the specified local port and address.
* *
* @param port The local port number to bind to. * @param address The local address and port number to bind to.
* @param laddr The local address to bind to.
* *
* @exception SecurityException If a security manager exists and its * @exception SecurityException If a security manager exists and its
* <code>checkListen</code> method doesn't allow the operation. * <code>checkListen</code> method doesn't allow the operation.
...@@ -177,7 +186,6 @@ public class DatagramSocket ...@@ -177,7 +186,6 @@ public class DatagramSocket
propVal + "DatagramSocketImpl"); propVal + "DatagramSocketImpl");
impl = new PlainDatagramSocketImpl(); impl = new PlainDatagramSocketImpl();
} }
impl.create();
if (address == null) if (address == null)
return; return;
...@@ -200,25 +208,45 @@ public class DatagramSocket ...@@ -200,25 +208,45 @@ public class DatagramSocket
try try
{ {
impl.bind(port, addr); getImpl().bind(port, addr);
} }
catch (SocketException exception) catch (SocketException exception)
{ {
impl.close(); getImpl().close();
throw exception; throw exception;
} }
catch (RuntimeException exception) catch (RuntimeException exception)
{ {
impl.close(); getImpl().close();
throw exception; throw exception;
} }
catch (Error error) catch (Error error)
{ {
impl.close(); getImpl().close();
throw error; throw error;
} }
} }
// This needs to be accessible from java.net.MulticastSocket
DatagramSocketImpl getImpl()
throws SocketException
{
try
{
if (!implCreated)
{
impl.create();
implCreated = true;
}
return impl;
}
catch (IOException e)
{
throw new SocketException(e.getMessage());
}
}
/** /**
* Closes this datagram socket. * Closes this datagram socket.
*/ */
...@@ -226,10 +254,20 @@ public class DatagramSocket ...@@ -226,10 +254,20 @@ public class DatagramSocket
{ {
if (!isClosed()) if (!isClosed())
{ {
impl.close(); try
impl = null; {
getImpl().close();
}
catch (SocketException e)
{
// Ignore this case, just close the socket in finally clause.
}
finally
{
remoteAddress = null; remoteAddress = null;
remotePort = -1; remotePort = -1;
impl = null;
}
} }
} }
...@@ -264,6 +302,8 @@ public class DatagramSocket ...@@ -264,6 +302,8 @@ public class DatagramSocket
/** /**
* Returns the local address this datagram socket is bound to. * Returns the local address this datagram socket is bound to.
* *
* @return The local address is the socket is bound or null
*
* @since 1.1 * @since 1.1
*/ */
public InetAddress getLocalAddress() public InetAddress getLocalAddress()
...@@ -275,7 +315,7 @@ public class DatagramSocket ...@@ -275,7 +315,7 @@ public class DatagramSocket
try try
{ {
localAddr = (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR); localAddr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR);
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
...@@ -287,6 +327,7 @@ public class DatagramSocket ...@@ -287,6 +327,7 @@ public class DatagramSocket
} }
catch (SocketException e) catch (SocketException e)
{ {
// This cannot happen as we are bound.
return null; return null;
} }
...@@ -303,7 +344,15 @@ public class DatagramSocket ...@@ -303,7 +344,15 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
return -1; return -1;
return impl.getLocalPort(); try
{
return getImpl().getLocalPort();
}
catch (SocketException e)
{
// This cannot happen as we are bound.
return 0;
}
} }
/** /**
...@@ -321,12 +370,12 @@ public class DatagramSocket ...@@ -321,12 +370,12 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT); Object buf = getImpl().getOption(SocketOptions.SO_TIMEOUT);
if (timeout instanceof Integer) if (buf instanceof Integer)
return ((Integer)timeout).intValue(); return ((Integer) buf).intValue();
else
return 0; throw new SocketException("unexpected type");
} }
/** /**
...@@ -348,7 +397,7 @@ public class DatagramSocket ...@@ -348,7 +397,7 @@ public class DatagramSocket
if (timeout < 0) if (timeout < 0)
throw new IllegalArgumentException("Invalid timeout: " + timeout); throw new IllegalArgumentException("Invalid timeout: " + timeout);
impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout)); getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
} }
/** /**
...@@ -367,12 +416,12 @@ public class DatagramSocket ...@@ -367,12 +416,12 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object obj = impl.getOption(SocketOptions.SO_SNDBUF); Object buf = getImpl().getOption(SocketOptions.SO_SNDBUF);
if (obj instanceof Integer) if (buf instanceof Integer)
return(((Integer)obj).intValue()); return ((Integer) buf).intValue();
else
throw new SocketException("Unexpected type"); throw new SocketException("unexpected type");
} }
/** /**
...@@ -395,7 +444,7 @@ public class DatagramSocket ...@@ -395,7 +444,7 @@ public class DatagramSocket
if (size < 0) if (size < 0)
throw new IllegalArgumentException("Buffer size is less than 0"); throw new IllegalArgumentException("Buffer size is less than 0");
impl.setOption(SocketOptions.SO_SNDBUF, new Integer(size)); getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size));
} }
/** /**
...@@ -414,12 +463,12 @@ public class DatagramSocket ...@@ -414,12 +463,12 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object obj = impl.getOption(SocketOptions.SO_RCVBUF); Object buf = getImpl().getOption(SocketOptions.SO_RCVBUF);
if (obj instanceof Integer) if (buf instanceof Integer)
return(((Integer)obj).intValue()); return ((Integer) buf).intValue();
else
throw new SocketException("Unexpected type"); throw new SocketException("unexpected type");
} }
/** /**
...@@ -442,7 +491,7 @@ public class DatagramSocket ...@@ -442,7 +491,7 @@ public class DatagramSocket
if (size < 0) if (size < 0)
throw new IllegalArgumentException("Buffer size is less than 0"); throw new IllegalArgumentException("Buffer size is less than 0");
impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size)); getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
} }
/** /**
...@@ -475,7 +524,7 @@ public class DatagramSocket ...@@ -475,7 +524,7 @@ public class DatagramSocket
try try
{ {
impl.connect (address, port); getImpl().connect (address, port);
remoteAddress = address; remoteAddress = address;
remotePort = port; remotePort = port;
} }
...@@ -494,10 +543,23 @@ public class DatagramSocket ...@@ -494,10 +543,23 @@ public class DatagramSocket
*/ */
public void disconnect() public void disconnect()
{ {
impl.disconnect(); if (!isConnected())
return;
try
{
getImpl().disconnect();
}
catch (SocketException e)
{
// This cannot happen as we are connected.
}
finally
{
remoteAddress = null; remoteAddress = null;
remotePort = -1; remotePort = -1;
} }
}
/** /**
* Reads a datagram packet from the socket. Note that this method * Reads a datagram packet from the socket. Note that this method
...@@ -532,7 +594,7 @@ public class DatagramSocket ...@@ -532,7 +594,7 @@ public class DatagramSocket
&& !getChannel().isBlocking ()) && !getChannel().isBlocking ())
throw new IllegalBlockingModeException (); throw new IllegalBlockingModeException ();
impl.receive(p); getImpl().receive(p);
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null && isConnected ()) if (s != null && isConnected ())
...@@ -585,7 +647,7 @@ public class DatagramSocket ...@@ -585,7 +647,7 @@ public class DatagramSocket
&& !getChannel().isBlocking ()) && !getChannel().isBlocking ())
throw new IllegalBlockingModeException (); throw new IllegalBlockingModeException ();
impl.send(p); getImpl().send(p);
} }
/** /**
...@@ -607,7 +669,7 @@ public class DatagramSocket ...@@ -607,7 +669,7 @@ public class DatagramSocket
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
if (! (address instanceof InetSocketAddress)) if (! (address instanceof InetSocketAddress))
throw new IllegalArgumentException (); throw new IllegalArgumentException("unsupported address type");
InetSocketAddress tmp = (InetSocketAddress) address; InetSocketAddress tmp = (InetSocketAddress) address;
...@@ -615,12 +677,15 @@ public class DatagramSocket ...@@ -615,12 +677,15 @@ public class DatagramSocket
if (s != null) if (s != null)
s.checkListen(tmp.getPort ()); s.checkListen(tmp.getPort ());
impl.bind (tmp.getPort (), tmp.getAddress ()); getImpl().bind (tmp.getPort (), tmp.getAddress ());
bound = true;
} }
/** /**
* Checks if the datagram socket is closed. * Checks if the datagram socket is closed.
* *
* @return True if socket is closed, false otherwise.
*
* @since 1.4 * @since 1.4
*/ */
public boolean isClosed() public boolean isClosed()
...@@ -631,6 +696,8 @@ public class DatagramSocket ...@@ -631,6 +696,8 @@ public class DatagramSocket
/** /**
* Returns the datagram channel assoziated with this datagram socket. * Returns the datagram channel assoziated with this datagram socket.
* *
* @return The associated <code>DatagramChannel</code> object or null
*
* @since 1.4 * @since 1.4
*/ */
public DatagramChannel getChannel() public DatagramChannel getChannel()
...@@ -651,37 +718,32 @@ public class DatagramSocket ...@@ -651,37 +718,32 @@ public class DatagramSocket
public void connect (SocketAddress address) throws SocketException public void connect (SocketAddress address) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed");
if ( !(address instanceof InetSocketAddress) ) if ( !(address instanceof InetSocketAddress) )
throw new IllegalArgumentException ( throw new IllegalArgumentException("unsupported address type");
"SocketAddress is not InetSocketAddress");
InetSocketAddress tmp = (InetSocketAddress) address; InetSocketAddress tmp = (InetSocketAddress) address;
connect( tmp.getAddress(), tmp.getPort()); connect(tmp.getAddress(), tmp.getPort());
} }
/** /**
* Returns the binding state of the socket. * Returns the binding state of the socket.
* *
* @return True if socket bound, false otherwise.
*
* @since 1.4 * @since 1.4
*/ */
public boolean isBound() public boolean isBound()
{ {
try return bound;
{
Object bindaddr = impl.getOption (SocketOptions.SO_BINDADDR);
}
catch (SocketException e)
{
return false;
}
return true;
} }
/** /**
* Returns the connection state of the socket. * Returns the connection state of the socket.
* *
* @return True if socket is connected, false otherwise.
*
* @since 1.4 * @since 1.4
*/ */
public boolean isConnected() public boolean isConnected()
...@@ -693,6 +755,8 @@ public class DatagramSocket ...@@ -693,6 +755,8 @@ public class DatagramSocket
* Returns the SocketAddress of the host this socket is conneted to * Returns the SocketAddress of the host this socket is conneted to
* or null if this socket is not connected. * or null if this socket is not connected.
* *
* @return The socket address of the remote host if connected or null
*
* @since 1.4 * @since 1.4
*/ */
public SocketAddress getRemoteSocketAddress() public SocketAddress getRemoteSocketAddress()
...@@ -704,25 +768,18 @@ public class DatagramSocket ...@@ -704,25 +768,18 @@ public class DatagramSocket
} }
/** /**
* Returns the local SocketAddress this socket is bound to * Returns the local SocketAddress this socket is bound to.
* or null if it is not bound. *
* @return The local SocketAddress or null if the socket is not bound.
* *
* @since 1.4 * @since 1.4
*/ */
public SocketAddress getLocalSocketAddress() public SocketAddress getLocalSocketAddress()
{ {
InetAddress addr; if (!isBound())
try
{
addr = (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR);
}
catch (SocketException e)
{
return null; return null;
}
return new InetSocketAddress (addr, impl.localPort); return new InetSocketAddress (getLocalAddress(), getLocalPort());
} }
/** /**
...@@ -739,12 +796,14 @@ public class DatagramSocket ...@@ -739,12 +796,14 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on)); getImpl().setOption (SocketOptions.SO_REUSEADDR, new Boolean (on));
} }
/** /**
* Checks if SO_REUSEADDR is enabled. * Checks if SO_REUSEADDR is enabled.
* *
* @return True if SO_REUSEADDR is set on the socket, false otherwise.
*
* @exception SocketException If an error occurs. * @exception SocketException If an error occurs.
* *
* @since 1.4 * @since 1.4
...@@ -754,34 +813,36 @@ public class DatagramSocket ...@@ -754,34 +813,36 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object obj = impl.getOption (SocketOptions.SO_REUSEADDR); Object buf = getImpl().getOption (SocketOptions.SO_REUSEADDR);
if (obj instanceof Boolean) if (buf instanceof Boolean)
return(((Boolean) obj).booleanValue ()); return ((Boolean) buf).booleanValue();
else
throw new SocketException ("Unexpected type"); throw new SocketException("unexpected type");
} }
/** /**
* Enables/Disables SO_BROADCAST * Enables/Disables SO_BROADCAST
* *
* @param on Whether or not to have SO_BROADCAST turned on * @param enable True if SO_BROADCAST should be enabled, false otherwise.
* *
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
* @since 1.4 * @since 1.4
*/ */
public void setBroadcast(boolean on) throws SocketException public void setBroadcast(boolean enable) throws SocketException
{ {
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
impl.setOption (SocketOptions.SO_BROADCAST, new Boolean (on)); getImpl().setOption(SocketOptions.SO_BROADCAST, new Boolean(enable));
} }
/** /**
* Checks if SO_BROADCAST is enabled * Checks if SO_BROADCAST is enabled
* *
* @return Whether SO_BROADCAST is set
*
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
* *
* @since 1.4 * @since 1.4
...@@ -791,12 +852,12 @@ public class DatagramSocket ...@@ -791,12 +852,12 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object obj = impl.getOption (SocketOptions.SO_BROADCAST); Object buf = getImpl().getOption(SocketOptions.SO_BROADCAST);
if (obj instanceof Boolean) if (buf instanceof Boolean)
return ((Boolean) obj).booleanValue (); return ((Boolean) buf).booleanValue();
else
throw new SocketException ("Unexpected type"); throw new SocketException("unexpected type");
} }
/** /**
...@@ -820,12 +881,14 @@ public class DatagramSocket ...@@ -820,12 +881,14 @@ public class DatagramSocket
if (tc < 0 || tc > 255) if (tc < 0 || tc > 255)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
impl.setOption (SocketOptions.IP_TOS, new Integer (tc)); getImpl().setOption (SocketOptions.IP_TOS, new Integer (tc));
} }
/** /**
* Returns the current traffic class * Returns the current traffic class
* *
* @return The current traffic class.
*
* @see DatagramSocket#setTrafficClass(int tc) * @see DatagramSocket#setTrafficClass(int tc)
* *
* @exception SocketException If an error occurs * @exception SocketException If an error occurs
...@@ -837,12 +900,12 @@ public class DatagramSocket ...@@ -837,12 +900,12 @@ public class DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object obj = impl.getOption(SocketOptions.IP_TOS); Object buf = getImpl().getOption(SocketOptions.IP_TOS);
if (obj instanceof Integer) if (buf instanceof Integer)
return ((Integer) obj).intValue (); return ((Integer) buf).intValue();
else
throw new SocketException ("Unexpected type"); throw new SocketException("unexpected type");
} }
/** /**
......
...@@ -67,10 +67,6 @@ import java.util.Enumeration; ...@@ -67,10 +67,6 @@ import java.util.Enumeration;
*/ */
public class MulticastSocket extends DatagramSocket public class MulticastSocket extends DatagramSocket
{ {
// FIXME: the local addr bound to the multicast socket can be reused;
// unlike unicast sockets. It binds to any available network interface.
// See p.1159 JCL book.
/** /**
* Create a MulticastSocket that this not bound to any address * Create a MulticastSocket that this not bound to any address
* *
...@@ -128,7 +124,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -128,7 +124,7 @@ public class MulticastSocket extends DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
return (InetAddress) impl.getOption(SocketOptions.IP_MULTICAST_IF); return (InetAddress) getImpl().getOption(SocketOptions.IP_MULTICAST_IF);
} }
/** /**
...@@ -152,7 +148,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -152,7 +148,7 @@ public class MulticastSocket extends DatagramSocket
// 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.
return impl.getTTL(); return getImpl().getTTL();
} }
/** /**
...@@ -170,7 +166,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -170,7 +166,7 @@ public class MulticastSocket extends DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
return impl.getTimeToLive(); return getImpl().getTimeToLive();
} }
/** /**
...@@ -187,7 +183,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -187,7 +183,7 @@ public class MulticastSocket extends DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
impl.setOption(SocketOptions.IP_MULTICAST_IF, addr); getImpl().setOption(SocketOptions.IP_MULTICAST_IF, addr);
} }
/** /**
...@@ -210,10 +206,10 @@ public class MulticastSocket extends DatagramSocket ...@@ -210,10 +206,10 @@ public class MulticastSocket extends DatagramSocket
Enumeration e = netIf.getInetAddresses (); Enumeration e = netIf.getInetAddresses ();
if (!e.hasMoreElements ()) if (!e.hasMoreElements ())
throw new SocketException ("MulticastSocket: Error"); throw new SocketException("no network devices found");
InetAddress address = (InetAddress) e.nextElement (); InetAddress address = (InetAddress) e.nextElement ();
impl.setOption (SocketOptions.IP_MULTICAST_IF, address); getImpl().setOption (SocketOptions.IP_MULTICAST_IF, address);
} }
/** /**
...@@ -234,7 +230,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -234,7 +230,7 @@ public class MulticastSocket extends DatagramSocket
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
InetAddress address = InetAddress address =
(InetAddress) impl.getOption (SocketOptions.IP_MULTICAST_IF); (InetAddress) getImpl().getOption (SocketOptions.IP_MULTICAST_IF);
NetworkInterface netIf = NetworkInterface.getByInetAddress (address); NetworkInterface netIf = NetworkInterface.getByInetAddress (address);
return netIf; return netIf;
...@@ -259,7 +255,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -259,7 +255,7 @@ public class MulticastSocket extends DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
impl.setOption (SocketOptions.IP_MULTICAST_LOOP, new Boolean (disable)); getImpl().setOption (SocketOptions.IP_MULTICAST_LOOP, new Boolean (disable));
} }
/** /**
...@@ -274,12 +270,12 @@ public class MulticastSocket extends DatagramSocket ...@@ -274,12 +270,12 @@ public class MulticastSocket extends DatagramSocket
if (isClosed()) if (isClosed())
throw new SocketException("socket is closed"); throw new SocketException("socket is closed");
Object obj = impl.getOption (SocketOptions.IP_MULTICAST_LOOP); Object buf = getImpl().getOption (SocketOptions.IP_MULTICAST_LOOP);
if (obj instanceof Boolean) if (buf instanceof Boolean)
return ((Boolean) obj).booleanValue (); return ((Boolean) buf).booleanValue();
else
throw new SocketException ("Unexpected type"); throw new SocketException("unexpected type");
} }
/** /**
...@@ -302,7 +298,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -302,7 +298,7 @@ public class MulticastSocket extends DatagramSocket
// 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.
impl.setTTL(ttl); getImpl().setTTL(ttl);
} }
/** /**
...@@ -323,7 +319,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -323,7 +319,7 @@ public class MulticastSocket extends DatagramSocket
if (ttl <= 0 || ttl > 255) if (ttl <= 0 || ttl > 255)
throw new IllegalArgumentException("Invalid ttl: " + ttl); throw new IllegalArgumentException("Invalid ttl: " + ttl);
impl.setTimeToLive(ttl); getImpl().setTimeToLive(ttl);
} }
/** /**
...@@ -347,7 +343,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -347,7 +343,7 @@ public class MulticastSocket extends DatagramSocket
if (s != null) if (s != null)
s.checkMulticast(mcastaddr); s.checkMulticast(mcastaddr);
impl.join(mcastaddr); getImpl().join(mcastaddr);
} }
/** /**
...@@ -371,7 +367,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -371,7 +367,7 @@ public class MulticastSocket extends DatagramSocket
if (s != null) if (s != null)
s.checkMulticast(mcastaddr); s.checkMulticast(mcastaddr);
impl.leave(mcastaddr); getImpl().leave(mcastaddr);
} }
/** /**
...@@ -410,7 +406,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -410,7 +406,7 @@ public class MulticastSocket extends DatagramSocket
if (s != null) if (s != null)
s.checkMulticast (tmp.getAddress ()); s.checkMulticast (tmp.getAddress ());
impl.joinGroup (mcastaddr, netIf); getImpl().joinGroup (mcastaddr, netIf);
} }
/** /**
...@@ -445,7 +441,7 @@ public class MulticastSocket extends DatagramSocket ...@@ -445,7 +441,7 @@ public class MulticastSocket extends DatagramSocket
if (s != null) if (s != null)
s.checkMulticast (tmp.getAddress ()); s.checkMulticast (tmp.getAddress ());
impl.leaveGroup (mcastaddr, netIf); getImpl().leaveGroup (mcastaddr, netIf);
} }
/** /**
...@@ -479,9 +475,9 @@ public class MulticastSocket extends DatagramSocket ...@@ -479,9 +475,9 @@ public class MulticastSocket extends DatagramSocket
s.checkConnect(addr.getHostAddress(), p.getPort()); s.checkConnect(addr.getHostAddress(), p.getPort());
} }
int oldttl = impl.getTimeToLive(); int oldttl = getImpl().getTimeToLive();
impl.setTimeToLive(((int) ttl) & 0xFF); getImpl().setTimeToLive(((int) ttl) & 0xFF);
impl.send(p); getImpl().send(p);
impl.setTimeToLive(oldttl); getImpl().setTimeToLive(oldttl);
} }
} // class MulticastSocket } // class MulticastSocket
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