diff options
author | Michael Koch <konqueror@gmx.de> | 2002-09-25 09:05:53 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2002-09-25 09:05:53 +0000 |
commit | df79dc1a89017f6b70525fcafc94c1ec476fead0 (patch) | |
tree | eba53548213d388013da79db4a20b091267a80e9 /libjava/java/net/Socket.java | |
parent | 33c31b33b58b9a17c94ba1451f79723dabee1961 (diff) | |
download | gcc-df79dc1a89017f6b70525fcafc94c1ec476fead0.zip gcc-df79dc1a89017f6b70525fcafc94c1ec476fead0.tar.gz gcc-df79dc1a89017f6b70525fcafc94c1ec476fead0.tar.bz2 |
2002-09-25 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
(DatagramSocket): Exception documentation added.
(bind): Exception documentation added, addded SecurityManager check,
added SocketAddress type check.
(getSoTimeout): Check impl.
(receive): Fix SecurityManager check, check impl, documentation added.
(send): Check channel mode, documentation added.
(connect): New method.
(disconnect): Implemented.
(getLocalSocketAddress): New method.
(getReceiveBufferSize): Check impl.
(setReuseAddress): Check impl.
(getReuseAddress): Check impl.
(setBroadcast): Check impl.
(getBroadcast): Check impl.
(setTrafficClass): Check impl, Documentation cleared.
(getTrafficClass): Check impl.
(getSendBufferSize): Check impl.
(setReceiveBufferSize): Check impl, documentation added.
(setSendBufferSize): Documentation added.
(setDatagramSocketImplFactory): New method.
* java/net/HttpURLConnection.java
(HTTP_INTERNAL_ERROR): The correct code is 500.
(HTTP_NOT_IMPLEMENTED): Added new constant.
(setFollowRedirects): Documentation added.
(getInstanceFollowRedirects): New method.
(setInstanceFollowRedirects): New method.
(setRequestMethod): Documentation added.
(getResponseCode): Documentation added.
(getResponseMessage): Documentation added.
* java/net/JarURLConnection.java
(JarURLConnection): protected since JDK 1.4.
(getJarEntry): java.io.IOException to IOException, documentation added.
(getJarFile): Documentation added.
* java/net/ServerSocket.java
(ServerSocket): Private to public, exception added.
(ServerSocket): java.io.IOException to IOException, documentation added.
(bind): Check socket address type, documentation added.
(bind): java.io.IOException to IOException, documentation added.
(accept): Documentation added.
(implAccept): Check ch is not non-blocking, documentation added.
(setSoTimeout): Documentation fixed.
(setReceiveBufferSize): Documentation added.
* java/net/Socket.java
(Socket): Documentation added.
(bind): Documentation added.
(connect): Check socket address type, documentation added.
(getRemoteSocketAddress): New method.
From-SVN: r57494
Diffstat (limited to 'libjava/java/net/Socket.java')
-rw-r--r-- | libjava/java/net/Socket.java | 145 |
1 files changed, 144 insertions, 1 deletions
diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java index 25f077b..9f01b78 100644 --- a/libjava/java/net/Socket.java +++ b/libjava/java/net/Socket.java @@ -129,6 +129,8 @@ public class Socket * @exception UnknownHostException If the hostname cannot be resolved to a * network address. * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkConnect method doesn't allow the operation */ public Socket (String host, int port) throws UnknownHostException, IOException @@ -144,6 +146,8 @@ public class Socket * @param port The port number to connect to * * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkConnect method doesn't allow the operation */ public Socket (InetAddress address, int port) throws IOException @@ -183,6 +187,8 @@ public class Socket * @param localPort The local port to connect to * * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkConnect method doesn't allow the operation */ public Socket (InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException @@ -202,6 +208,8 @@ public class Socket * for a datagram socket * * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkConnect method doesn't allow the operation * * @deprecated Use the <code>DatagramSocket</code> class to create * datagram oriented sockets. @@ -223,6 +231,8 @@ public class Socket * <code>false</code> to create a datagram socket. * * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkConnect method doesn't allow the operation * * @deprecated Use the <code>DatagramSocket</code> class to create * datagram oriented sockets. @@ -246,6 +256,8 @@ public class Socket * @param stream true for a stream socket, false for a datagram socket * * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkConnect method doesn't allow the operation */ private Socket(InetAddress raddr, int rport, InetAddress laddr, int lport, boolean stream) throws IOException @@ -275,7 +287,10 @@ public class Socket * * @param bindpoint The address/port to bind to * - * @exception If an error occurs + * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkConnect method doesn't allow the operation + * @exception IllegalArgumentException If the address type is not supported * * @since 1.4 */ @@ -294,12 +309,17 @@ public class Socket * @param endpoint The address to connect to * * @exception IOException If an error occurs + * @exception IllegalArgumentException If the addess type is not supported + * @exception IllegalBlockingModeException FIXME * * @since 1.4 */ public void connect (SocketAddress endpoint) throws IOException { + if (! (endpoint instanceof InetSocketAddress)) + throw new IllegalArgumentException ("Address type not supported"); + impl.connect (endpoint, 0); } @@ -311,12 +331,18 @@ public class Socket * @param endpoint The address to connect to * * @exception IOException If an error occurs + * @exception IllegalArgumentException If the address type is not supported + * @exception IllegalBlockingModeException FIXME + * @exception SocketTimeoutException If the timeout is reached * * @since 1.4 */ public void connect (SocketAddress endpoint, int timeout) throws IOException { + if (! (endpoint instanceof InetSocketAddress)) + throw new IllegalArgumentException ("Address type not supported"); + impl.connect (endpoint, timeout); } @@ -399,6 +425,40 @@ public class Socket } /** + * If the socket is already bound this returns the local SocketAddress, + * otherwise null + * + * @since 1.4 + */ + public SocketAddress getLocalSocketAddress() + { + InetAddress addr; + + try + { + addr = (InetAddress) impl.getOption (SocketOptions.SO_BINDADDR); + } + catch (SocketException e) + { + return null; + } + + return new InetSocketAddress (addr, impl.getLocalPort()); + } + + /** + * If the socket is already connected this returns the remote SocketAddress, + * otherwise null + * + * @since 1.4 + */ + public SocketAddress getRemoteSocketAddress() + { + // FIXME: Implement this + return null; + } + + /** * Returns an InputStream for reading from this socket. * * @return The InputStream object @@ -479,6 +539,7 @@ public class Socket * SO_LINGER not set. * * @exception SocketException If an error occurs or Socket not connected + * @exception IllegalArgumentException If linger is negative */ public void setSoLinger(boolean on, int linger) throws SocketException { @@ -640,6 +701,7 @@ public class Socket * @param size The new send buffer size. * * @exception SocketException If an error occurs or Socket not connected + * @exception IllegalArgumentException FIXME * * @since 1.2 */ @@ -686,6 +748,7 @@ public class Socket * @param size The new receive buffer size. * * @exception SocketException If an error occurs or Socket is not connected + * @exception IllegalArgumentException If size is 0 or negative * * @since 1.2 */ @@ -847,4 +910,84 @@ public class Socket { return ch; } + + /** + * Checks if the SO_REUSEADDR option is enabled + * + * @exception SocketException If an error occurs + * + * @since 1.4 + */ + public boolean getReuseAddress () throws SocketException + { + if (impl == null) + throw new SocketException ("Cannot initialize Socket implementation"); + + Object reuseaddr = impl.getOption (SocketOptions.SO_REUSEADDR); + + if (!(reuseaddr instanceof Boolean)) + throw new SocketException ("Internal Error"); + + return ((Boolean) reuseaddr).booleanValue (); + } + + /** + * Enables/Disables the SO_REUSEADDR option + * + * @exception SocketException If an error occurs + * + * @since 1.4 + */ + public void setReuseAddress (boolean on) throws SocketException + { + if (impl == null) + throw new SocketException ("Cannot initialize Socket implementation"); + + impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on)); + } + + /** + * Returns the current traffic class + * + * @exception SocketException If an error occurs + * + * @see Socket:setTrafficClass + * + * @since 1.4 + */ + public int getTrafficClass () throws SocketException + { + if (impl == null) + throw new SocketException ("Cannot initialize Socket implementation"); + + Object obj = impl.getOption(SocketOptions.IP_TOS); + + if (obj instanceof Integer) + return ((Integer) obj).intValue (); + else + throw new SocketException ("Unexpected type"); + } + + /** + * Sets the traffic class value + * + * @param tc The traffic class + * + * @exception SocketException If an error occurs + * @exception IllegalArgumentException If tc value is illegal + * + * @see Socket:getTrafficClass + * + * @since 1.4 + */ + public void setTrafficClass (int tc) throws SocketException + { + if (impl == null) + throw new SocketException ("Cannot initialize Socket implementation"); + + if (tc < 0 || tc > 255) + throw new IllegalArgumentException(); + + impl.setOption (SocketOptions.IP_TOS, new Integer (tc)); + } } |