From fc44b85de78353cb3930e3d59346863bf344ef93 Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Wed, 25 Sep 2002 17:14:09 +0000 Subject: 2002-09-25 Michael Koch * 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 --- libjava/java/net/Socket.java | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'libjava/java/net/Socket.java') 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; + } } -- cgit v1.2.3