summaryrefslogtreecommitdiff
path: root/libjava/java/net/DatagramSocket.java
diff options
context:
space:
mode:
authorWarren Levy <warrenl@cygnus.com>1999-05-28 19:29:53 +0000
committerWarren Levy <warrenl@gcc.gnu.org>1999-05-28 19:29:53 +0000
commit07515641a55ffacad7a289e32702831f54630d07 (patch)
tree2be352b9baec3fecd8a60eda2e771c4cb2819327 /libjava/java/net/DatagramSocket.java
parent930248932e3864264cdfe7d40b00a0544f3d4de9 (diff)
DatagramSocket.java (laddr): Removed.
* java/net/DatagramSocket.java (laddr): Removed. (DatagramSocket): Removed attempts to get or set laddr if null. (getLocalAddress): Reimplemented per spec. * java/net/MulticastSocket.java (setTimeToLive): Throw exception when ttl is 0. (joinGroup): Throw NullPointerException if any argument is null. (leaveGroup): ditto. * java/net/PlainDatagramSocketImpl.java: Updated comments. * java/net/PlainSocketImpl.java (timeout): Added. (getInputStream): Added FIXME comment on how to support timeouts for TCP. * java/net/ServerSocket.java (ServerSocket): Added FIXME comment. * java/net/Socket.java: Added FIXME comments to identify conflicting specs between the JCL and JDK 1.2 documents. * java/net/natPlainDatagramSocketImpl.cc (bind): Use INADDR_ANY if host is null. Get localport value resolved by kernel if bind lport is 0. (receive): Implemented support for timeouts in UDP. (setOption): Implemented based on natPlainSocketImpl version. (getOption): ditto. * java/net/natPlainSocketImpl.cc (bind): Get localport value resolved by kernel if bind lport is 0. (connect): Get localport value resolved by kernel if bind wasn't done to set localport. (accept): Implemented support for timeouts for ServerSocket. (setOption): Save value for SO_TIMEOUT. (getOption): Return timeout for SO_TIMEOUT. From-SVN: r27230
Diffstat (limited to 'libjava/java/net/DatagramSocket.java')
-rw-r--r--libjava/java/net/DatagramSocket.java48
1 files changed, 34 insertions, 14 deletions
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java
index 3bfb0327c49..96d9555590b 100644
--- a/libjava/java/net/DatagramSocket.java
+++ b/libjava/java/net/DatagramSocket.java
@@ -25,8 +25,6 @@ import java.io.IOException;
public class DatagramSocket
{
DatagramSocketImpl impl;
- // FIXME: Shouldn't this be determined by getsockname() instead?
- InetAddress laddr;
public DatagramSocket() throws SocketException
{
@@ -53,23 +51,12 @@ public class DatagramSocket
impl = (DatagramSocketImpl) Class.forName("java.net." + propVal +
"DatagramSocketImpl").newInstance();
impl.create();
- // TBD: if this is right then the same should be done in Socket().
- try
- {
- if (laddr == null)
- laddr = InetAddress.getLocalHost();
- }
- catch (UnknownHostException e)
- {
- throw new BindException(e.getMessage());
- }
// For multicasting, set the socket to be reused (Stevens pp. 195-6).
if (this instanceof MulticastSocket)
impl.setOption(SocketOptions.SO_REUSEADDR, new Boolean(true));
impl.bind(port, laddr);
- this.laddr = laddr;
}
public void close()
@@ -79,7 +66,40 @@ public class DatagramSocket
public InetAddress getLocalAddress()
{
- return laddr;
+ SecurityManager s = System.getSecurityManager();
+ // FIXME: JCL p. 510 says this should call checkConnect. But what
+ // string should be used as the hostname? Maybe this is just a side
+ // effect of calling InetAddress.getLocalHost.
+ //
+ // And is getOption with SO_BINDADDR the right way to get the address?
+ // Doesn't seem to be since this method doesn't throw a SocketException
+ // and SO_BINADDR can throw one.
+ //
+ // Also see RETURNS section in JCL p. 510 about returning any local
+ // addr "if the current execution context is not allowed to connect to
+ // the network interface that is actually bound to this datagram socket."
+ // How is that done? via InetAddress.getLocalHost? But that throws
+ // an UnknownHostException and this method doesn't.
+ //
+ // if (s != null)
+ // s.checkConnect("localhost", -1);
+ try
+ {
+ return (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR);
+ }
+ catch (SocketException ex)
+ {
+ }
+
+ try
+ {
+ return InetAddress.getLocalHost();
+ }
+ catch (UnknownHostException ex)
+ {
+ // FIXME: This should never happen, so how can we avoid this construct?
+ return null;
+ }
}
public int getLocalPort()