diff options
| author | Michael Koch <konqueror@gmx.de> | 2002-09-25 17:14:09 +0000 |
|---|---|---|
| committer | Michael Koch <mkoch@gcc.gnu.org> | 2002-09-25 17:14:09 +0000 |
| commit | fc44b85de78353cb3930e3d59346863bf344ef93 (patch) | |
| tree | c7f727fc4330f40bf9d00f1200993bfa6656a8ab /libjava/java/net/DatagramSocket.java | |
| parent | 6f950405a0751ab26cab5dbca5e4fbcecfa60350 (diff) | |
2002-09-25 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
(DatagramSocket): Initialize new instance variables.
(close): Reset new instance variables.
(getLocalAddress): Remove unneeded SecurityManager usage.
(getLocalPort): Check if socket is already bound.
(isConnected): New method.
(getInetAddress): Implemented.
(getPort): Better Implementation, documentation fixed.
(getRemoteSocketAddress): New method.
* java/net/JarURLConnection.java
(element): Typo fixed.
(getMainAttributes): New method.
(getAttributes): New method (stub only).
(getManifest): New method (stub only).
* java/net/NetPermission.java: Added serialVersionsUID.
* java/net/Socket.java
(connect): Check blocking mode of associated channel,
documentation added.
(getLocalSocketAddress): Better implementation.
(getRemoteSocketAddress): Implemented.
(isBound): New method.
(setSendBufferSize): Documentation added.
* java/net/SocketAddress.java: Added serialVersionsUID.
* java/net/SocketPermission.java: Added serialVersionsUID.
* java/net/URL.java
(URL): Wrap for shorter lines, initialize new instance variables,
documentation added.
(equals): Check new instance variables too.
(getContent): Documentation added.
(getPath): Documentation added.
(getAuthority): New method.
(getHost): Documentation added.
(getPort): Documentation added.
(getDefaultPort): New method.
(getProtocol): Documentation added.
(getUserInfo): Documentation added.
(set): Initialize new instance variables, documentation added.
* java/net/URLStreamHandler.java
(setURL): New method.
* java/net/natPlainDatagramSocketImpl.cc
(connect): Fix exception name.
(disconnect): Fix exception name.
From-SVN: r57501
Diffstat (limited to 'libjava/java/net/DatagramSocket.java')
| -rw-r--r-- | libjava/java/net/DatagramSocket.java | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java index eef638db091..dfbce3bcf7d 100644 --- a/libjava/java/net/DatagramSocket.java +++ b/libjava/java/net/DatagramSocket.java @@ -37,6 +37,9 @@ public class DatagramSocket DatagramChannel ch; + private InetAddress remoteAddress; + private int remotePort; + /** * Creates a DatagramSocket * @@ -59,6 +62,8 @@ public class DatagramSocket protected DatagramSocket (DatagramSocketImpl impl) { this.impl = impl; + this.remoteAddress = null; + this.remotePort = -1; } /** @@ -134,6 +139,9 @@ public class DatagramSocket impl.setOption(SocketOptions.SO_REUSEADDR, new Boolean(true)); impl.bind(port, laddr == null ? InetAddress.ANY_IF : laddr); + + remoteAddress = null; + remotePort = -1; } /** @@ -169,6 +177,8 @@ public class DatagramSocket public void close() { impl.close(); + remoteAddress = null; + remotePort = -1; } /** @@ -198,7 +208,6 @@ public class DatagramSocket */ public InetAddress getLocalAddress() { - 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. @@ -241,6 +250,9 @@ public class DatagramSocket */ public int getLocalPort() { + if (!isBound ()) + return -1; + return impl.getLocalPort(); } @@ -417,6 +429,16 @@ public class DatagramSocket } /** + * Returns the connection state of the socket + * + * @since 1.4 + */ + public boolean isConnected() + { + return remoteAddress != null; + } + + /** * Returns the InetAddress the socket is connected to * or null if the socket is not connected * @@ -424,18 +446,37 @@ public class DatagramSocket */ public InetAddress getInetAddress() { - // FIXME: - return null; + if (!isConnected ()) + return null; + + return remoteAddress; } /** - * Returns the local port number of the socket + * Returns the port number the socket is connected to or -1 if not connected * * @since 1.2 */ public int getPort() { - return impl.localPort; + if (!isConnected ()) + return -1; + + return remotePort; + } + + /** + * Returns the SocketAddress of the host this socket is conneted to + * or null if this socket is not connected + * + * @since 1.4 + */ + public SocketAddress getRemoteSocketAddress() + { + if (!isConnected ()) + return null; + + return new InetSocketAddress (remoteAddress, remotePort); } /** |
