From: <hag...@us...> - 2006-12-14 13:00:17
|
Revision: 2927 http://jnode.svn.sourceforge.net/jnode/?rev=2927&view=rev Author: hagar-wize Date: 2006-12-14 05:00:14 -0800 (Thu, 14 Dec 2006) Log Message: ----------- Classpath patches Modified Paths: -------------- trunk/core/src/classpath/java/java/net/DatagramSocket.java Modified: trunk/core/src/classpath/java/java/net/DatagramSocket.java =================================================================== --- trunk/core/src/classpath/java/java/net/DatagramSocket.java 2006-12-14 12:58:38 UTC (rev 2926) +++ trunk/core/src/classpath/java/java/net/DatagramSocket.java 2006-12-14 13:00:14 UTC (rev 2927) @@ -1,5 +1,5 @@ /* DatagramSocket.java -- A class to model UDP sockets - Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005 + Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -8,7 +8,7 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -42,12 +42,10 @@ import gnu.java.net.PlainDatagramSocketImpl; import gnu.java.nio.DatagramChannelImpl; -import gnu.java.security.action.GetPropertyAction; import java.io.IOException; import java.nio.channels.DatagramChannel; import java.nio.channels.IllegalBlockingModeException; -import java.security.AccessController; /** @@ -56,47 +54,47 @@ * Status: Believed complete and correct. */ /** - * This class models a connectionless datagram socket that sends + * This class models a connectionless datagram socket that sends * individual packets of data across the network. In the TCP/IP world, * this means UDP. Datagram packets do not have guaranteed delivery, * or any guarantee about the order the data will be received on the * remote host. - * + * * @author Aaron M. Renn (ar...@ur...) * @author Warren Levy (wa...@cy...) * @date May 3, 1999. */ public class DatagramSocket { - /** - * This is the user DatagramSocketImplFactory for this class. If this - * variable is null, a default factory is used. - */ + /** + * This is the user DatagramSocketImplFactory for this class. If this + * variable is null, a default factory is used. + */ private static DatagramSocketImplFactory factory; - /** - * This is the implementation object used by this socket. - */ + /** + * This is the implementation object used by this socket. + */ private DatagramSocketImpl impl; - /** + /** * True if socket implementation was created. - */ + */ private boolean implCreated; - /** - * This is the address we are "connected" to - */ - private InetAddress remoteAddress; + /** + * This is the address we are "connected" to + */ + private InetAddress remoteAddress; - /** - * This is the port we are "connected" to - */ - private int remotePort = -1; + /** + * This is the port we are "connected" to + */ + private int remotePort = -1; - /** + /** * True if socket is bound. - */ + */ private boolean bound; /** @@ -118,77 +116,83 @@ this.remotePort = -1; } - /** - * Initializes a new instance of <code>DatagramSocket</code> that binds to - * a random port and every address on the local machine. - * - * @exception SocketException If an error occurs. - * @exception SecurityException If a security manager exists and + /** + * Initializes a new instance of <code>DatagramSocket</code> that binds to + * a random port and every address on the local machine. + * + * @exception SocketException If an error occurs. + * @exception SecurityException If a security manager exists and * its <code>checkListen</code> method doesn't allow the operation. - */ + */ public DatagramSocket() throws SocketException { this(new InetSocketAddress(0)); - } + } - /** - * Initializes a new instance of <code>DatagramSocket</code> that binds to - * the specified port and every address on the local machine. - * - * @param port The local port number to bind to. - * - * @exception SecurityException If a security manager exists and its + /** + * Initializes a new instance of <code>DatagramSocket</code> that binds to + * the specified port and every address on the local machine. + * + * @param port The local port number to bind to. + * + * @exception SecurityException If a security manager exists and its * <code>checkListen</code> method doesn't allow the operation. - * @exception SocketException If an error occurs. - */ + * @exception SocketException If an error occurs. + */ public DatagramSocket(int port) throws SocketException { this(new InetSocketAddress(port)); - } + } - /** - * Initializes a new instance of <code>DatagramSocket</code> that binds to - * the specified local port and address. - * - * @param port The local port number to bind to. + /** + * Initializes a new instance of <code>DatagramSocket</code> that binds to + * the specified local port and address. + * + * @param port The local port number to bind to. * @param addr The local address to bind to. - * - * @exception SecurityException If a security manager exists and its - * checkListen method doesn't allow the operation. - * @exception SocketException If an error occurs. - */ + * + * @exception SecurityException If a security manager exists and its + * checkListen method doesn't allow the operation. + * @exception SocketException If an error occurs. + */ public DatagramSocket(int port, InetAddress addr) throws SocketException { this(new InetSocketAddress(addr, port)); - } + } - /** - * Initializes a new instance of <code>DatagramSocket</code> that binds to - * the specified local port and address. - * + /** + * Initializes a new instance of <code>DatagramSocket</code> that binds to + * the specified local port and address. + * * @param address The local address and port number to bind to. - * - * @exception SecurityException If a security manager exists and its + * + * @exception SecurityException If a security manager exists and its * <code>checkListen</code> method doesn't allow the operation. - * @exception SocketException If an error occurs. - * - * @since 1.4 - */ + * @exception SocketException If an error occurs. + * + * @since 1.4 + */ public DatagramSocket(SocketAddress address) throws SocketException { - // @classpath-bugfix Security - //String propVal = SystemProperties.getProperty("impl.prefix"); - //if (propVal == null || propVal.equals("")) - String propVal = (String)AccessController.doPrivileged(new GetPropertyAction("impl.prefix")); - // @classpath-bugfix-end - - // @classpath-bugfix Use factory - //if (propVal == null || propVal.equals("")) - if (factory != null) { - impl = factory.createDatagramSocketImpl(); - } else if (propVal == null || propVal.equals("")) - // @classpath-bugfix-end - impl = new PlainDatagramSocketImpl(); + String propVal = SystemProperties.getProperty("impl.prefix"); + if (propVal == null || propVal.equals("")) + { + if (factory != null) + impl = factory.createDatagramSocketImpl(); + else + { + try + { + impl = new PlainDatagramSocketImpl(); + } + catch (IOException ioe) + { + SocketException se = new SocketException(); + se.initCause(ioe); + throw se; + } + } + } else try { @@ -201,7 +205,16 @@ { System.err.println("Could not instantiate class: java.net." + propVal + "DatagramSocketImpl"); - impl = new PlainDatagramSocketImpl(); + try + { + impl = new PlainDatagramSocketImpl(); + } + catch (IOException ioe) + { + SocketException se = new SocketException(); + se.initCause(ioe); + throw se; + } } if (address != null) @@ -217,21 +230,21 @@ { impl.create(); implCreated = true; - } + } return impl; - } + } catch (IOException e) { SocketException se = new SocketException(); se.initCause(e); throw se; - } - } + } + } - /** - * Closes this datagram socket. - */ + /** + * Closes this datagram socket. + */ public void close() { if (isClosed()) @@ -261,47 +274,47 @@ { // Do nothing. } - } + } - /** - * This method returns the remote address to which this socket is - * connected. If this socket is not connected, then this method will - * return <code>null</code>. - * - * @return The remote address. - * - * @since 1.2 - */ + /** + * This method returns the remote address to which this socket is + * connected. If this socket is not connected, then this method will + * return <code>null</code>. + * + * @return The remote address. + * + * @since 1.2 + */ public InetAddress getInetAddress() { - return remoteAddress; - } + return remoteAddress; + } - /** - * This method returns the remote port to which this socket is - * connected. If this socket is not connected, then this method will - * return -1. - * - * @return The remote port. - * - * @since 1.2 - */ + /** + * This method returns the remote port to which this socket is + * connected. If this socket is not connected, then this method will + * return -1. + * + * @return The remote port. + * + * @since 1.2 + */ public int getPort() { - return remotePort; - } + return remotePort; + } - /** - * Returns the local address this datagram socket is bound to. - * + /** + * Returns the local address this datagram socket is bound to. + * * @return The local address is the socket is bound or null * - * @since 1.1 - */ + * @since 1.1 + */ public InetAddress getLocalAddress() { if (! isBound()) - return null; + return null; InetAddress localAddr; @@ -312,7 +325,7 @@ SecurityManager s = System.getSecurityManager(); if (s != null) - s.checkConnect(localAddr.getHostName(), -1); + s.checkConnect(localAddr.getHostAddress(), -1); } catch (SecurityException e) { @@ -325,13 +338,13 @@ } return localAddr; - } + } - /** - * Returns the local port this socket is bound to. - * - * @return The local port number. - */ + /** + * Returns the local port this socket is bound to. + * + * @return The local port number. + */ public int getLocalPort() { if (isClosed()) @@ -346,18 +359,18 @@ // This cannot happen as we are bound. return 0; } - } + } - /** - * Returns the value of the socket's SO_TIMEOUT setting. If this method - * returns 0 then SO_TIMEOUT is disabled. - * - * @return The current timeout in milliseconds. - * - * @exception SocketException If an error occurs. - * - * @since 1.1 - */ + /** + * Returns the value of the socket's SO_TIMEOUT setting. If this method + * returns 0 then SO_TIMEOUT is disabled. + * + * @return The current timeout in milliseconds. + * + * @exception SocketException If an error occurs. + * + * @since 1.1 + */ public synchronized int getSoTimeout() throws SocketException { if (isClosed()) @@ -369,41 +382,41 @@ return ((Integer) buf).intValue(); throw new SocketException("unexpected type"); - } + } - /** - * Sets the value of the socket's SO_TIMEOUT value. A value of 0 will - * disable SO_TIMEOUT. Any other value is the number of milliseconds - * a socket read/write will block before timing out. - * - * @param timeout The new SO_TIMEOUT value in milliseconds. - * - * @exception SocketException If an error occurs. - * - * @since 1.1 - */ + /** + * Sets the value of the socket's SO_TIMEOUT value. A value of 0 will + * disable SO_TIMEOUT. Any other value is the number of milliseconds + * a socket read/write will block before timing out. + * + * @param timeout The new SO_TIMEOUT value in milliseconds. + * + * @exception SocketException If an error occurs. + * + * @since 1.1 + */ public synchronized void setSoTimeout(int timeout) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - if (timeout < 0) + if (timeout < 0) throw new IllegalArgumentException("Invalid timeout: " + timeout); getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout)); - } + } - /** - * This method returns the value of the system level socket option - * SO_SNDBUF, which is used by the operating system to tune buffer - * sizes for data transfers. - * - * @return The send buffer size. - * - * @exception SocketException If an error occurs. - * - * @since 1.2 - */ + /** + * This method returns the value of the system level socket option + * SO_SNDBUF, which is used by the operating system to tune buffer + * sizes for data transfers. + * + * @return The send buffer size. + * + * @exception SocketException If an error occurs. + * + * @since 1.2 + */ public int getSendBufferSize() throws SocketException { if (isClosed()) @@ -415,42 +428,42 @@ return ((Integer) buf).intValue(); throw new SocketException("unexpected type"); - } + } - /** - * This method sets the value for the system level socket option - * SO_SNDBUF to the specified value. Note that valid values for this - * option are specific to a given operating system. - * - * @param size The new send buffer size. - * - * @exception SocketException If an error occurs. - * @exception IllegalArgumentException If size is 0 or negative. - * - * @since 1.2 - */ + /** + * This method sets the value for the system level socket option + * SO_SNDBUF to the specified value. Note that valid values for this + * option are specific to a given operating system. + * + * @param size The new send buffer size. + * + * @exception SocketException If an error occurs. + * @exception IllegalArgumentException If size is 0 or negative. + * + * @since 1.2 + */ public void setSendBufferSize(int size) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - if (size < 0) - throw new IllegalArgumentException("Buffer size is less than 0"); + if (size < 0) + throw new IllegalArgumentException("Buffer size is less than 0"); getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size)); - } + } - /** - * This method returns the value of the system level socket option - * SO_RCVBUF, which is used by the operating system to tune buffer - * sizes for data transfers. - * - * @return The receive buffer size. - * - * @exception SocketException If an error occurs. - * - * @since 1.2 - */ + /** + * This method returns the value of the system level socket option + * SO_RCVBUF, which is used by the operating system to tune buffer + * sizes for data transfers. + * + * @return The receive buffer size. + * + * @exception SocketException If an error occurs. + * + * @since 1.2 + */ public int getReceiveBufferSize() throws SocketException { if (isClosed()) @@ -462,58 +475,57 @@ return ((Integer) buf).intValue(); throw new SocketException("unexpected type"); - } + } - /** - * This method sets the value for the system level socket option - * SO_RCVBUF to the specified value. Note that valid values for this - * option are specific to a given operating system. - * - * @param size The new receive buffer size. - * - * @exception SocketException If an error occurs. - * @exception IllegalArgumentException If size is 0 or negative. - * - * @since 1.2 - */ + /** + * This method sets the value for the system level socket option + * SO_RCVBUF to the specified value. Note that valid values for this + * option are specific to a given operating system. + * + * @param size The new receive buffer size. + * + * @exception SocketException If an error occurs. + * @exception IllegalArgumentException If size is 0 or negative. + * + * @since 1.2 + */ public void setReceiveBufferSize(int size) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - if (size < 0) - throw new IllegalArgumentException("Buffer size is less than 0"); + if (size < 0) + throw new IllegalArgumentException("Buffer size is less than 0"); getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size)); - } + } - /** - * This method connects this socket to the specified address and port. - * When a datagram socket is connected, it will only send or receive + /** + * This method connects this socket to the specified address and port. + * When a datagram socket is connected, it will only send or receive * packets to and from the host to which it is connected. A multicast - * socket that is connected may only send and not receive packets. - * + * socket that is connected may only send and not receive packets. + * * @param address The address to connect this socket to. - * @param port The port to connect this socket to. - * - * @exception SocketException If an error occurs. + * @param port The port to connect this socket to. + * * @exception IllegalArgumentException If address or port are invalid. * @exception SecurityException If the caller is not allowed to send * datagrams to or receive from this address and port. - * - * @since 1.2 - */ + * + * @since 1.2 + */ public void connect(InetAddress address, int port) { if (address == null) throw new IllegalArgumentException("Connect address may not be null"); - if ((port < 1) || (port > 65535)) + if ((port < 1) || (port > 65535)) throw new IllegalArgumentException("Port number is illegal: " + port); - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkConnect(address.getHostName(), port); + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkConnect(address.getHostAddress(), port); try { @@ -525,15 +537,15 @@ { // This means simply not connected or connect not implemented. } - } + } - /** + /** * This method disconnects this socket from the address/port it was - * connected to. If the socket was not connected in the first place, - * this method does nothing. - * - * @since 1.2 - */ + * connected to. If the socket was not connected in the first place, + * this method does nothing. + * + * @since 1.2 + */ public void disconnect() { if (! isConnected()) @@ -552,16 +564,16 @@ remoteAddress = null; remotePort = -1; } - } + } - /** - * Reads a datagram packet from the socket. Note that this method - * will block until a packet is received from the network. On return, - * the passed in <code>DatagramPacket</code> is populated with the data - * received and all the other information about the packet. - * - * @param p A <code>DatagramPacket</code> for storing the data - * + /** + * Reads a datagram packet from the socket. Note that this method + * will block until a packet is received from the network. On return, + * the passed in <code>DatagramPacket</code> is populated with the data + * received and all the other information about the packet. + * + * @param p A <code>DatagramPacket</code> for storing the data + * * @exception IOException If an error occurs. * @exception SocketTimeoutException If setSoTimeout was previously called * and the timeout has expired. @@ -572,7 +584,7 @@ * channel, and the channel is in non-blocking mode. * @exception SecurityException If a security manager exists and its * checkAccept method doesn't allow the receive. - */ + */ public synchronized void receive(DatagramPacket p) throws IOException { if (isClosed()) @@ -586,43 +598,49 @@ && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation()) throw new IllegalBlockingModeException(); - getImpl().receive(p); + DatagramPacket p2 = new DatagramPacket(p.getData(), p.getOffset(), p.maxlen); + getImpl().receive(p2); + p.length = p2.length; + if (p2.getAddress() != null) + p.setAddress(p2.getAddress()); + if (p2.getPort() != -1) + p.setPort(p2.getPort()); - SecurityManager s = System.getSecurityManager(); - if (s != null && isConnected()) - s.checkAccept(p.getAddress().getHostName(), p.getPort()); - } + SecurityManager s = System.getSecurityManager(); + if (s != null && isConnected()) + s.checkAccept(p.getAddress().getHostAddress(), p.getPort()); + } - /** - * Sends the specified packet. The host and port to which the packet - * are to be sent should be set inside the packet. - * - * @param p The datagram packet to send. - * - * @exception IOException If an error occurs. - * @exception SecurityException If a security manager exists and its - * checkMulticast or checkConnect method doesn't allow the send. - * @exception PortUnreachableException If the socket is connected to a - * currently unreachable destination. Note, there is no guarantee that the - * exception will be thrown. - * @exception IllegalBlockingModeException If this socket has an associated - * channel, and the channel is in non-blocking mode. - */ + /** + * Sends the specified packet. The host and port to which the packet + * are to be sent should be set inside the packet. + * + * @param p The datagram packet to send. + * + * @exception IOException If an error occurs. + * @exception SecurityException If a security manager exists and its + * checkMulticast or checkConnect method doesn't allow the send. + * @exception PortUnreachableException If the socket is connected to a + * currently unreachable destination. Note, there is no guarantee that the + * exception will be thrown. + * @exception IllegalBlockingModeException If this socket has an associated + * channel, and the channel is in non-blocking mode. + */ public void send(DatagramPacket p) throws IOException { if (isClosed()) throw new SocketException("socket is closed"); // JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api. - SecurityManager s = System.getSecurityManager(); + SecurityManager s = System.getSecurityManager(); if (s != null && ! isConnected()) { - InetAddress addr = p.getAddress(); - if (addr.isMulticastAddress()) - s.checkMulticast(addr); - else - s.checkConnect(addr.getHostAddress(), p.getPort()); - } + InetAddress addr = p.getAddress(); + if (addr.isMulticastAddress()) + s.checkMulticast(addr); + else + s.checkConnect(addr.getHostAddress(), p.getPort()); + } if (isConnected()) { @@ -630,7 +648,7 @@ && (remoteAddress != p.getAddress() || remotePort != p.getPort())) throw new IllegalArgumentException ("DatagramPacket address does not match remote address"); - } + } // FIXME: if this is a subclass of MulticastSocket, // use getTimeToLive for TTL val. @@ -639,24 +657,27 @@ throw new IllegalBlockingModeException(); getImpl().send(p); - } + } - /** - * Binds the socket to the given socket address. - * - * @param address The socket address to bind to. - * - * @exception SocketException If an error occurs. - * @exception SecurityException If a security manager exists and - * its checkListen method doesn't allow the operation. - * @exception IllegalArgumentException If address type is not supported. - * - * @since 1.4 - */ + /** + * Binds the socket to the given socket address. + * + * @param address The socket address to bind to. + * + * @exception SocketException If an error occurs. + * @exception SecurityException If a security manager exists and + * its checkListen method doesn't allow the operation. + * @exception IllegalArgumentException If address type is not supported. + * + * @since 1.4 + */ public void bind(SocketAddress address) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); + + if (address == null) + address = new InetSocketAddress(InetAddress.ANY_IF, 0); if (! (address instanceof InetSocketAddress)) throw new IllegalArgumentException("unsupported address type"); @@ -667,8 +688,8 @@ if (port < 0 || port > 65535) throw new IllegalArgumentException("Invalid port: " + port); - SecurityManager s = System.getSecurityManager(); - if (s != null) + SecurityManager s = System.getSecurityManager(); + if (s != null) s.checkListen(port); if (addr == null) @@ -706,30 +727,30 @@ public boolean isClosed() { return impl == null; - } + } - /** - * Returns the datagram channel assoziated with this datagram socket. - * + /** + * Returns the datagram channel assoziated with this datagram socket. + * * @return The associated <code>DatagramChannel</code> object or null * - * @since 1.4 - */ + * @since 1.4 + */ public DatagramChannel getChannel() { return null; - } + } - /** - * Connects the datagram socket to a specified socket address. - * - * @param address The socket address to connect to. - * - * @exception SocketException If an error occurs. - * @exception IllegalArgumentException If address type is not supported. - * - * @since 1.4 - */ + /** + * Connects the datagram socket to a specified socket address. + * + * @param address The socket address to connect to. + * + * @exception SocketException If an error occurs. + * @exception IllegalArgumentException If address type is not supported. + * + * @since 1.4 + */ public void connect(SocketAddress address) throws SocketException { if (isClosed()) @@ -739,90 +760,90 @@ throw new IllegalArgumentException("unsupported address type"); InetSocketAddress tmp = (InetSocketAddress) address; - connect(tmp.getAddress(), tmp.getPort()); - } + connect(tmp.getAddress(), tmp.getPort()); + } - /** - * Returns the binding state of the socket. - * + /** + * Returns the binding state of the socket. + * * @return True if socket bound, false otherwise. * - * @since 1.4 - */ + * @since 1.4 + */ public boolean isBound() { return bound; - } + } - /** - * Returns the connection state of the socket. - * + /** + * Returns the connection state of the socket. + * * @return True if socket is connected, false otherwise. * - * @since 1.4 - */ + * @since 1.4 + */ public boolean isConnected() { - return remoteAddress != null; - } + return remoteAddress != null; + } - /** - * Returns the SocketAddress of the host this socket is conneted to - * or null if this socket is not connected. - * + /** + * Returns the SocketAddress of the host this socket is conneted to + * or null if this socket is not connected. + * * @return The socket address of the remote host if connected or null * - * @since 1.4 - */ + * @since 1.4 + */ public SocketAddress getRemoteSocketAddress() { if (! isConnected()) - return null; + return null; - return new InetSocketAddress(remoteAddress, remotePort); - } + return new InetSocketAddress(remoteAddress, remotePort); + } - /** + /** * Returns the local SocketAddress this socket is bound to. * * @return The local SocketAddress or null if the socket is not bound. - * - * @since 1.4 - */ + * + * @since 1.4 + */ public SocketAddress getLocalSocketAddress() { if (! isBound()) - return null; + return null; return new InetSocketAddress(getLocalAddress(), getLocalPort()); - } + } - /** - * Enables/Disables SO_REUSEADDR. - * - * @param on Whether or not to have SO_REUSEADDR turned on. - * - * @exception SocketException If an error occurs. - * - * @since 1.4 - */ + /** + * Enables/Disables SO_REUSEADDR. + * + * @param on Whether or not to have SO_REUSEADDR turned on. + * + * @exception SocketException If an error occurs. + * + * @since 1.4 + */ public void setReuseAddress(boolean on) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on)); - } + } - /** - * Checks if SO_REUSEADDR is enabled. - * + /** + * Checks if SO_REUSEADDR is enabled. + * * @return True if SO_REUSEADDR is set on the socket, false otherwise. * - * @exception SocketException If an error occurs. - * - * @since 1.4 - */ + * @exception SocketException If an error occurs. + * + * @since 1.4 + */ public boolean getReuseAddress() throws SocketException { if (isClosed()) @@ -834,34 +855,34 @@ return ((Boolean) buf).booleanValue(); throw new SocketException("unexpected type"); - } + } - /** - * Enables/Disables SO_BROADCAST - * + /** + * Enables/Disables SO_BROADCAST + * * @param enable True if SO_BROADCAST should be enabled, false otherwise. - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ + * + * @exception SocketException If an error occurs + * + * @since 1.4 + */ public void setBroadcast(boolean enable) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); getImpl().setOption(SocketOptions.SO_BROADCAST, Boolean.valueOf(enable)); - } + } - /** - * Checks if SO_BROADCAST is enabled - * + /** + * Checks if SO_BROADCAST is enabled + * * @return Whether SO_BROADCAST is set * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ + * @exception SocketException If an error occurs + * + * @since 1.4 + */ public boolean getBroadcast() throws SocketException { if (isClosed()) @@ -873,42 +894,42 @@ return ((Boolean) buf).booleanValue(); 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 - * + /** + * Sets the traffic class value + * + * @param tc The traffic class + * + * @exception SocketException If an error occurs + * @exception IllegalArgumentException If tc value is illegal + * * @see DatagramSocket#getTrafficClass() - * - * @since 1.4 - */ + * + * @since 1.4 + */ public void setTrafficClass(int tc) throws SocketException { if (isClosed()) throw new SocketException("socket is closed"); - if (tc < 0 || tc > 255) - throw new IllegalArgumentException(); + if (tc < 0 || tc > 255) + throw new IllegalArgumentException(); getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc)); - } + } - /** - * Returns the current traffic class - * + /** + * Returns the current traffic class + * * @return The current traffic class. * * @see DatagramSocket#setTrafficClass(int tc) - * - * @exception SocketException If an error occurs - * - * @since 1.4 - */ + * + * @exception SocketException If an error occurs + * + * @since 1.4 + */ public int getTrafficClass() throws SocketException { if (isClosed()) @@ -920,28 +941,28 @@ return ((Integer) buf).intValue(); throw new SocketException("unexpected type"); - } + } - /** - * Sets the datagram socket implementation factory for the application - * - * @param fac The factory to set - * - * @exception IOException If an error occurs - * @exception SocketException If the factory is already defined - * @exception SecurityException If a security manager exists and its - * checkSetFactory method doesn't allow the operation - */ - public static void setDatagramSocketImplFactory(DatagramSocketImplFactory fac) + /** + * Sets the datagram socket implementation factory for the application + * + * @param fac The factory to set + * + * @exception IOException If an error occurs + * @exception SocketException If the factory is already defined + * @exception SecurityException If a security manager exists and its + * checkSetFactory method doesn't allow the operation + */ + public static void setDatagramSocketImplFactory(DatagramSocketImplFactory fac) throws IOException { - if (factory != null) - throw new SocketException("DatagramSocketImplFactory already defined"); + if (factory != null) + throw new SocketException("DatagramSocketImplFactory already defined"); - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkSetFactory(); + SecurityManager sm = System.getSecurityManager(); + if (sm != null) + sm.checkSetFactory(); - factory = fac; - } + factory = fac; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |