diff options
author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-09-25 17:14:09 +0000 |
---|---|---|
committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-09-25 17:14:09 +0000 |
commit | c7380abc488ba82e7803c576eafb5eb75ff11a9e (patch) | |
tree | c7f727fc4330f40bf9d00f1200993bfa6656a8ab /libjava/java/net/Socket.java | |
parent | d84ea0df0818b1ed9ee39badf2d7961c550c7d66 (diff) | |
download | gcc-c7380abc488ba82e7803c576eafb5eb75ff11a9e.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@57501 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/net/Socket.java')
-rw-r--r-- | libjava/java/net/Socket.java | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java index 9f01b78012a..82265dd32f9 100644 --- a/libjava/java/net/Socket.java +++ b/libjava/java/net/Socket.java @@ -39,6 +39,7 @@ package java.net; import java.io.*; import java.nio.channels.SocketChannel; +import java.nio.channels.IllegalBlockingModeException; /* Written using on-line Java Platform 1.2 API Specification. * Status: I believe all methods are implemented. @@ -80,7 +81,7 @@ public class Socket SocketImpl impl; SocketChannel ch; // this field must have been set if created by SocketChannel - + // Constructors /** @@ -310,7 +311,8 @@ public class Socket * * @exception IOException If an error occurs * @exception IllegalArgumentException If the addess type is not supported - * @exception IllegalBlockingModeException FIXME + * @exception IllegalBlockingModeException If this socket has an associated + * channel, and the channel is in non-blocking mode * * @since 1.4 */ @@ -320,6 +322,9 @@ public class Socket if (! (endpoint instanceof InetSocketAddress)) throw new IllegalArgumentException ("Address type not supported"); + if (ch != null && !ch.isBlocking ()) + throw new IllegalBlockingModeException (); + impl.connect (endpoint, 0); } @@ -332,7 +337,8 @@ public class Socket * * @exception IOException If an error occurs * @exception IllegalArgumentException If the address type is not supported - * @exception IllegalBlockingModeException FIXME + * @exception IllegalBlockingModeException If this socket has an associated + * channel, and the channel is in non-blocking mode * @exception SocketTimeoutException If the timeout is reached * * @since 1.4 @@ -343,6 +349,9 @@ public class Socket if (! (endpoint instanceof InetSocketAddress)) throw new IllegalArgumentException ("Address type not supported"); + if (ch != null && !ch.isBlocking ()) + throw new IllegalBlockingModeException (); + impl.connect (endpoint, timeout); } @@ -432,16 +441,10 @@ public class Socket */ public SocketAddress getLocalSocketAddress() { - InetAddress addr; + InetAddress addr = getLocalAddress (); - try - { - addr = (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR); - } - catch (SocketException e) - { - return null; - } + if (addr == null) + return null; return new InetSocketAddress (addr, impl.getLocalPort()); } @@ -454,8 +457,7 @@ public class Socket */ public SocketAddress getRemoteSocketAddress() { - // FIXME: Implement this - return null; + return new InetSocketAddress (impl.getInetAddress (), impl.getPort ()); } /** @@ -701,7 +703,7 @@ public class Socket * @param size The new send buffer size. * * @exception SocketException If an error occurs or Socket not connected - * @exception IllegalArgumentException FIXME + * @exception IllegalArgumentException If size is 0 or negative * * @since 1.2 */ @@ -990,4 +992,12 @@ public class Socket impl.setOption (SocketOptions.IP_TOS, new Integer (tc)); } + + /** + * Checks if the socket is already bound. + */ + public boolean isBound () + { + return getLocalAddress () != null; + } } |