harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r440907 [1/2] - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/
Date Thu, 07 Sep 2006 00:01:17 GMT
Author: ndbeyer
Date: Wed Sep  6 17:01:16 2006
New Revision: 440907

URL: http://svn.apache.org/viewvc?view=rev&rev=440907
Log:
Code cleanup; add braces, remove unecessary initialization and compiler warnings

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/GenericIPMreq.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainMulticastSocketImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainServerSocketImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl2.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/SocketImplProvider.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/SocketOutputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/Socks4Message.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/GenericIPMreq.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/GenericIPMreq.java?view=diff&rev=440907&r1=440906&r2=440907
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/GenericIPMreq.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/GenericIPMreq.java Wed Sep  6 17:01:16 2006
@@ -15,7 +15,6 @@
 
 package org.apache.harmony.luni.net;
 
-
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
@@ -29,20 +28,21 @@
  */
 final class GenericIPMreq {
 
-    // private members
     private InetAddress multiaddr;
 
+    @SuppressWarnings("unused")
     private InetAddress interfaceAddr;
 
+    @SuppressWarnings("unused")
     private boolean isIPV6Address;
 
+    @SuppressWarnings("unused")
     private int interfaceIdx;
 
     /**
      * This constructor is used to create an instance of the object
      * 
-     * @param addr
-     *            multicast address to join/leave
+     * @param addr multicast address to join/leave
      * 
      */
     GenericIPMreq(InetAddress addr) {
@@ -55,12 +55,9 @@
     /**
      * This constructor is used to create an instance of the object
      * 
-     * @param addr
-     *            multicast address to join/leave
-     * @param netInterface
-     *            the NetworkInterface object identifying the interface on which
-     *            to join/leave
-     * 
+     * @param addr multicast address to join/leave
+     * @param netInterface the NetworkInterface object identifying the interface
+     *        on which to join/leave
      */
     GenericIPMreq(InetAddress addr, NetworkInterface netInterface) {
         multiaddr = addr;
@@ -68,18 +65,18 @@
             // TODO  check if necessary
             //interfaceIdx = netInterface.getIndex();
 
-            // here we need to get the first IPV4 address as we only use it if
-            // we
-            // are settting the interface for an IPV4 multicast socket. For
-            // adds/drops on
-            // IPV6 addresses we use the index within the networkInterface
+            /*
+             * here we need to get the first IPV4 address as we only use it if
+             * we are setting the interface for an IPV4 multicast socket. For
+             * adds/drops on IPV6 addresses we use the index within the
+             * networkInterface
+             */
             interfaceAddr = null;
-            Enumeration theAddresses = netInterface.getInetAddresses();
+            Enumeration<InetAddress> theAddresses = netInterface.getInetAddresses();
             if ((addr instanceof Inet4Address) && (theAddresses != null)) {
                 boolean found = false;
                 while ((theAddresses.hasMoreElements()) && (found != true)) {
-                    InetAddress theAddress = (InetAddress) theAddresses
-                            .nextElement();
+                    InetAddress theAddress = theAddresses.nextElement();
                     if (theAddress instanceof Inet4Address) {
                         interfaceAddr = theAddress;
                         found = true;
@@ -87,9 +84,10 @@
                 }
             }
         } else {
-            // network interface is null so we just want to defer the decision
-            // to
-            // the system
+            /*
+             * network interface is null so we just want to defer the decision
+             * to the system
+             */
             interfaceIdx = 0;
             interfaceAddr = null;
         }
@@ -100,8 +98,10 @@
      * This method does any required initialization for the constructors
      */
     private void init() {
-        // set the flag indicating if the multicast address is an IPV6 address
-        // or not
+        /*
+         * set the flag indicating if the multicast address is an IPV6 address
+         * or not
+         */
         isIPV6Address = ((multiaddr != null) && (multiaddr instanceof Inet6Address));
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java?view=diff&rev=440907&r1=440906&r2=440907
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/NetUtil.java Wed Sep  6 17:01:16 2006
@@ -18,25 +18,23 @@
 import java.net.ProxySelector;
 import java.net.URI;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.List;
 
-import org.apache.harmony.luni.util.PriviAction;
-
 public class NetUtil {
-    
+
     /**
      * Answers whether to use a SOCKS proxy.
      * 
-     * @param proxy
-     *            java.net.Proxy <code>proxy</code> is used to determine
-     *            whether using SOCKS proxy.
+     * @param proxy java.net.Proxy <code>proxy</code> is used to determine
+     *        whether using SOCKS proxy.
      * @return true if only the type of <code>proxy</code> is
      *         Proxy.Type.SOCKS.
      */
     public static boolean usingSocks(Proxy proxy) {
-    	if(null != proxy && Proxy.Type.SOCKS == proxy.type()){
-    		return true;
-    	}
+        if (null != proxy && Proxy.Type.SOCKS == proxy.type()) {
+            return true;
+        }
         return false;
     }
 
@@ -46,9 +44,8 @@
      * @return boolean
      */
     public static boolean preferIPv6Addresses() {
-    	String result = AccessController.doPrivileged(new PriviAction<String>(
-    			"java.net.preferIPv6Addresses")); //$NON-NLS-1$
-    	return "true".equals(result); //$NON-NLS-1$
+        final Action a = new Action("java.net.preferIPv6Addresses");//$NON-NLS-1$
+        return AccessController.doPrivileged(a).booleanValue();
     }
 
     /**
@@ -57,23 +54,62 @@
      * @return boolean
      */
     public static boolean preferIPv4Stack() {
-    	String result = AccessController.doPrivileged(new PriviAction<String>(
-    			"java.net.preferIPv4Stack")); //$NON-NLS-1$
-        return "true".equals(result); //$NON-NLS-1$
+        final Action a = new Action("java.net.preferIPv4Stack");//$NON-NLS-1$
+        return AccessController.doPrivileged(a).booleanValue();
     }
 
     /**
-     * Gets proxy list according to the uri by system ProxySelector.
+     * Gets proxy list according to the URI by system ProxySelector.
+     * 
      * @param uri
-     * @return a list of proxy for the uri. Returns null if no proxy 
-     * 		   is available.
+     * @return a list of proxy for the URI. Returns null if no proxy is
+     *         available.
      */
-    public static List<Proxy> getProxyList(URI uri){
-		// use system default selector to get proxy list
-		ProxySelector selector = ProxySelector.getDefault();
-		if(null == selector){
-			return null;
-		}
-		return selector.select(uri);
+    public static List<Proxy> getProxyList(URI uri) {
+        // use system default selector to get proxy list
+        ProxySelector selector = ProxySelector.getDefault();
+        if (null == selector) {
+            return null;
+        }
+        return selector.select(uri);
+    }
+
+    private static final class Action implements PrivilegedAction<Boolean> {
+        private final String propertyName;
+
+        Action(String propertyName) {
+            super();
+            this.propertyName = propertyName;
+        }
+
+        public Boolean run() {
+            if (Boolean.getBoolean(propertyName)) {
+                return Boolean.TRUE;
+            }
+            return Boolean.FALSE;
+        }
+    }
+
+    static void intToBytes(int value, byte bytes[], int start) {
+        /*
+         * Shift the int so the current byte is right-most Use a byte mask of
+         * 255 to single out the last byte.
+         */
+        bytes[start] = (byte) ((value >> 24) & 255);
+        bytes[start + 1] = (byte) ((value >> 16) & 255);
+        bytes[start + 2] = (byte) ((value >> 8) & 255);
+        bytes[start + 3] = (byte) (value & 255);
+    }
+
+    static int bytesToInt(byte bytes[], int start) {
+        /*
+         * First mask the byte with 255, as when a negative signed byte converts
+         * to an integer, it has bits on in the first 3 bytes, we are only
+         * concerned about the right-most 8 bits. Then shift the rightmost byte
+         * to align with its position in the integer.
+         */
+        int value = ((bytes[start + 3] & 255)) | ((bytes[start + 2] & 255) << 8)
+                | ((bytes[start + 1] & 255) << 16) | ((bytes[start] & 255) << 24);
+        return value;
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java?view=diff&rev=440907&r1=440906&r2=440907
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java Wed Sep  6 17:01:16 2006
@@ -20,7 +20,6 @@
 import java.io.InterruptedIOException;
 import java.net.DatagramPacket;
 import java.net.DatagramSocketImpl;
-import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.NetworkInterface;
@@ -33,7 +32,6 @@
 
 import org.apache.harmony.luni.platform.INetworkSystem;
 import org.apache.harmony.luni.platform.Platform;
-
 import org.apache.harmony.luni.util.Msg;
 import org.apache.harmony.luni.util.PriviAction;
 
@@ -42,694 +40,380 @@
  * support security checks. Alternative types of DatagramSocketImpl's may be
  * used by setting the <code>impl.prefix</code> system property.
  */
-
 class PlainDatagramSocketImpl extends DatagramSocketImpl {
 
-	static final int MULTICAST_IF = 1;
+    static final int MULTICAST_IF = 1;
 
-	static final int MULTICAST_TTL = 2;
+    static final int MULTICAST_TTL = 2;
 
-	static final int TCP_NODELAY = 4;
+    static final int TCP_NODELAY = 4;
 
-	static final int FLAG_SHUTDOWN = 8;
+    static final int FLAG_SHUTDOWN = 8;
 
-	private final static int SO_BROADCAST = 32;
+    private final static int SO_BROADCAST = 32;
 
-	final static int IP_MULTICAST_ADD = 19;
+    final static int IP_MULTICAST_ADD = 19;
 
-	final static int IP_MULTICAST_DROP = 20;
+    final static int IP_MULTICAST_DROP = 20;
 
-	final static int IP_MULTICAST_TTL = 17;
+    final static int IP_MULTICAST_TTL = 17;
 
-	private boolean bindToDevice;
-
-	private byte[] ipaddress = { 0, 0, 0, 0 };
+    /**
+     * for datagram and multicast sockets we have to set REUSEADDR and REUSEPORT
+     * when REUSEADDR is set for other types of sockets we need to just set
+     * REUSEADDR therefore we have this other option which sets both if
+     * supported by the platform. this cannot be in SOCKET_OPTIONS because since
+     * it is a public interface it ends up being public even if it is not
+     * declared public
+     */
+    static final int REUSEADDR_AND_REUSEPORT = 10001;
 
-	private int ttl = 1;
+    private boolean bindToDevice;
 
-	private INetworkSystem netImpl = Platform.getNetworkSystem();
+    private byte[] ipaddress = { 0, 0, 0, 0 };
 
-	private volatile boolean isNativeConnected = false;
+    private int ttl = 1;
 
-	public int receiveTimeout = 0;
+    private INetworkSystem netImpl = Platform.getNetworkSystem();
 
-	public boolean streaming = true;
+    private volatile boolean isNativeConnected;
 
-	public boolean shutdownInput = false;
+    public int receiveTimeout;
 
-	// for datagram and multicast sockets we have to set
-	// REUSEADDR and REUSEPORT when REUSEADDR is set
-	// for other types of sockets we need to just set REUSEADDR
-	// therefore we have this other option which sets
-	// both if supported by the platform.
-	// this cannot be in SOCKET_OPTIONS because since it
-	// is a public interface it ends up being public even
-	// if it is not declared public
-	static final int REUSEADDR_AND_REUSEPORT = 10001;
+    public boolean streaming = true;
 
-	// used to keep address to which the socket was connected to at the
-	// native level
-	private InetAddress connectedAddress = null;
+    public boolean shutdownInput;
 
-	private int connectedPort = -1;
+    /**
+     * used to keep address to which the socket was connected to at the native
+     * level
+     */
+    private InetAddress connectedAddress;
 
-	// used to store the trafficClass value which is simply returned
-	// as the value that was set. We also need it to pass it to methods
-	// that specify an address packets are going to be sent to
-	private int trafficClass = 0;
+    private int connectedPort = -1;
 
-	// Fill in the JNI id caches
-	// private static native void oneTimeInitialization(boolean
-	// jcl_IPv6_support);
-	//
-	// static {
-	// oneTimeInitialization(true);
-	// }
+    /**
+     * used to store the trafficClass value which is simply returned as the
+     * value that was set. We also need it to pass it to methods that specify an
+     * address packets are going to be sent to
+     */
+    private int trafficClass;
 
-    
     public PlainDatagramSocketImpl(FileDescriptor fd, int localPort) {
         super();
         this.fd = fd;
         this.localPort = localPort;
     }
-    
-    public PlainDatagramSocketImpl(){
+
+    public PlainDatagramSocketImpl() {
         super();
     }
 
+    @Override
+    public void bind(int port, InetAddress addr) throws SocketException {
+        String prop = AccessController.doPrivileged(new PriviAction<String>("bindToDevice"));
+        boolean useBindToDevice = prop != null && prop.toLowerCase().equals("true");
+        bindToDevice = netImpl.bind2(fd, port, useBindToDevice, addr);
+        if (0 != port) {
+            localPort = port;
+        } else {
+            localPort = netImpl.getSocketLocalPort(fd, NetUtil.preferIPv6Addresses());
+        }
+
+        try {
+            // Ignore failures
+            setOption(SO_BROADCAST, Boolean.TRUE);
+        } catch (IOException e) {
+        }
+    }
+
+    @Override
+    public void close() {
+        synchronized (fd) {
+            if (fd.valid()) {
+                try {
+                    netImpl.socketClose(fd);
+                } catch (IOException e) {
+                }
+                fd = new FileDescriptor();
+            }
+        }
+    }
+
+    @Override
+    public void create() throws SocketException {
+        netImpl.createDatagramSocket(fd, NetUtil.preferIPv4Stack());
+    }
+
+    @Override
+    protected void finalize() {
+        close();
+    }
+
+    @Override
+    public Object getOption(int optID) throws SocketException {
+        if (optID == SocketOptions.SO_TIMEOUT) {
+            return new Integer(receiveTimeout);
+        } else if (optID == SocketOptions.IP_TOS) {
+            return new Integer(trafficClass);
+        } else {
+            // Call the native first so there will be
+            // an exception if the socket if closed.
+            Object result = netImpl.getSocketOption(fd, optID);
+            if (optID == SocketOptions.IP_MULTICAST_IF
+                    && (netImpl.getSocketFlags() & MULTICAST_IF) != 0) {
+                try {
+                    return InetAddress.getByAddress(ipaddress);
+                } catch (UnknownHostException e) {
+                    return null;
+                }
+            }
+            return result;
+        }
+    }
+
+    @Override
+    public int getTimeToLive() throws IOException {
+        // Call the native first so there will be an exception if the socket if
+        // closed.
+        int result = (((Byte) getOption(IP_MULTICAST_TTL)).byteValue()) & 0xFF;
+        if ((netImpl.getSocketFlags() & MULTICAST_TTL) != 0) {
+            return ttl;
+        }
+        return result;
+    }
+
+    @Override
+    public byte getTTL() throws IOException {
+        // Call the native first so there will be an exception if the socket if
+        // closed.
+        byte result = ((Byte) getOption(IP_MULTICAST_TTL)).byteValue();
+        if ((netImpl.getSocketFlags() & MULTICAST_TTL) != 0) {
+            return (byte) ttl;
+        }
+        return result;
+    }
+
+    @Override
+    public void join(InetAddress addr) throws IOException {
+        setOption(IP_MULTICAST_ADD, new GenericIPMreq(addr));
+    }
+
+    @Override
+    public void joinGroup(SocketAddress addr, NetworkInterface netInterface) throws IOException {
+        if (addr instanceof InetSocketAddress) {
+            InetAddress groupAddr = ((InetSocketAddress) addr).getAddress();
+            setOption(IP_MULTICAST_ADD, new GenericIPMreq(groupAddr, netInterface));
+        }
+    }
+
+    @Override
+    public void leave(InetAddress addr) throws IOException {
+        setOption(IP_MULTICAST_DROP, new GenericIPMreq(addr));
+    }
+
+    @Override
+    public void leaveGroup(SocketAddress addr, NetworkInterface netInterface)
+            throws IOException {
+        if (addr instanceof InetSocketAddress) {
+            InetAddress groupAddr = ((InetSocketAddress) addr).getAddress();
+            setOption(IP_MULTICAST_DROP, new GenericIPMreq(groupAddr, netInterface));
+        }
+    }
+
+    @Override
+    protected int peek(InetAddress sender) throws IOException {
+        if (isNativeConnected) {
+            /*
+             * in this case we know the port and address from which the data
+             * must have be been received as the socket is connected. However,
+             * we still need to do the receive in order to know that there was
+             * data received. We use a short buffer as we don't actually need
+             * the packet, only the knowledge that it is there
+             */
+            byte[] storageArray = new byte[10];
+            DatagramPacket pack = new DatagramPacket(storageArray, storageArray.length);
+            netImpl.recvConnectedDatagram(fd, pack, pack.getData(), pack.getOffset(), pack
+                    .getLength(), receiveTimeout, true); // peek
+            // to set the sender ,we now use a native function
+            // sender.ipaddress = connectedAddress.getAddress();
+            netImpl.setInetAddress(sender, connectedAddress.getAddress());
+            return connectedPort;
+        }
+        return netImpl.peekDatagram(fd, sender, receiveTimeout);
+    }
+
+    @Override
+    public void receive(DatagramPacket pack) throws java.io.IOException {
+        try {
+            if (isNativeConnected) {
+                // do not peek
+                netImpl.recvConnectedDatagram(fd, pack, pack.getData(), pack.getOffset(), pack
+                        .getLength(), receiveTimeout, false);
+                updatePacketRecvAddress(pack);
+            } else {
+                // receiveDatagramImpl2
+                netImpl.receiveDatagram(fd, pack, pack.getData(), pack.getOffset(), pack
+                        .getLength(), receiveTimeout, false);
+            }
+        } catch (InterruptedIOException e) {
+            throw new SocketTimeoutException(e.getMessage());
+        }
+    }
+
+    @Override
+    public void send(DatagramPacket packet) throws IOException {
+
+        if (isNativeConnected) {
+            netImpl.sendConnectedDatagram(fd, packet.getData(), packet.getOffset(), packet
+                    .getLength(), bindToDevice);
+        } else {
+            // sendDatagramImpl2
+            netImpl.sendDatagram(fd, packet.getData(), packet.getOffset(), packet.getLength(),
+                    packet.getPort(), bindToDevice, trafficClass, packet.getAddress());
+        }
+    }
+
+    /**
+     * Set the nominated socket option. As the timeouts are not set as options
+     * in the IP stack, the value is stored in an instance field.
+     * 
+     * @throws SocketException thrown if the option value is unsupported or
+     *         invalid
+     */
+    @Override
+    public void setOption(int optID, Object val) throws SocketException {
+        /*
+         * for datagram sockets on some platforms we have to set both the
+         * REUSEADDR AND REUSEPORT so for REUSEADDR set this option option which
+         * tells the VM to set the two values as appropriate for the platform
+         */
+        if (optID == SocketOptions.SO_REUSEADDR) {
+            optID = REUSEADDR_AND_REUSEPORT;
+        }
+
+        if (optID == SocketOptions.SO_TIMEOUT) {
+            receiveTimeout = ((Integer) val).intValue();
+        } else {
+            int flags = netImpl.getSocketFlags();
+            try {
+                netImpl.setSocketOption(fd, optID | (flags << 16), val);
+            } catch (SocketException e) {
+                // we don't throw an exception for IP_TOS even if the platform
+                // won't let us set the requested value
+                if (optID != SocketOptions.IP_TOS) {
+                    throw e;
+                }
+            }
+            if (optID == SocketOptions.IP_MULTICAST_IF && (flags & MULTICAST_IF) != 0) {
+                InetAddress inet = (InetAddress) val;
+                if (NetUtil.bytesToInt(inet.getAddress(), 0) == 0 || inet.isLoopbackAddress()) {
+                    ipaddress = ((InetAddress) val).getAddress();
+                } else {
+                    InetAddress local = null;
+                    try {
+                        local = InetAddress.getLocalHost();
+                    } catch (UnknownHostException e) {
+                        throw new SocketException("getLocalHost(): " + e.toString());
+                    }
+                    if (inet.equals(local)) {
+                        ipaddress = ((InetAddress) val).getAddress();
+                    } else {
+                        throw new SocketException(val + " != getLocalHost(): " + local);
+                    }
+                }
+            }
+            /*
+             * save this value as it is actually used differently for IPv4 and
+             * IPv6 so we cannot get the value using the getOption. The option
+             * is actually only set for IPv4 and a masked version of the value
+             * will be set as only a subset of the values are allowed on the
+             * socket. Therefore we need to retain it to return the value that
+             * was set. We also need the value to be passed into a number of
+             * natives so that it can be used properly with IPv6
+             */
+            if (optID == SocketOptions.IP_TOS) {
+                trafficClass = ((Integer) val).intValue();
+            }
+        }
+    }
+
+    @Override
+    public void setTimeToLive(int ttl) throws java.io.IOException {
+        setOption(IP_MULTICAST_TTL, new Byte((byte) (ttl & 0xFF)));
+        if ((netImpl.getSocketFlags() & MULTICAST_TTL) != 0) {
+            this.ttl = ttl;
+        }
+    }
+
+    @Override
+    public void setTTL(byte ttl) throws java.io.IOException {
+        setOption(IP_MULTICAST_TTL, new Byte(ttl));
+        if ((netImpl.getSocketFlags() & MULTICAST_TTL) != 0) {
+            this.ttl = ttl;
+        }
+    }
+
+    @Override
+    public void connect(InetAddress inetAddr, int port) throws SocketException {
+
+        // connectDatagram impl2
+        netImpl.connectDatagram(fd, port, trafficClass, inetAddr);
+
+        // if we get here then we are connected at the native level
+        try {
+            connectedAddress = InetAddress.getByAddress(inetAddr.getAddress());
+        } catch (UnknownHostException e) {
+            // this is never expected to happen as we should not have gotten
+            // here if the address is not resolvable
+            throw new SocketException(Msg.getString("K0317", inetAddr.getHostName())); //$NON-NLS-1$
+        }
+        connectedPort = port;
+        isNativeConnected = true;
+    }
+
+    @Override
+    public void disconnect() {
+        try {
+            netImpl.disconnectDatagram(fd);
+        } catch (Exception e) {
+            // there is currently no way to return an error so just eat any
+            // exception
+        }
+        connectedPort = -1;
+        connectedAddress = null;
+        isNativeConnected = false;
+    }
+
+    @Override
+    public int peekData(DatagramPacket pack) throws IOException {
+        try {
+            if (isNativeConnected) {
+                netImpl.recvConnectedDatagram(fd, pack, pack.getData(), pack.getOffset(), pack
+                        .getLength(), receiveTimeout, true); // peek
+                updatePacketRecvAddress(pack);
+            } else {
+                // receiveDatagram 2
+                netImpl.receiveDatagram(fd, pack, pack.getData(), pack.getOffset(), pack
+                        .getLength(), receiveTimeout, true); // peek
+            }
+        } catch (InterruptedIOException e) {
+            throw new SocketTimeoutException(e.toString());
+        }
+        return pack.getPort();
+    }
+
     /**
-	 * Bind the datagram socket to the nominated localhost/port. Sockets must be
-	 * bound prior to attempting to send or receive data.
-	 * 
-	 * @param port
-	 *            the port on the localhost to bind
-	 * @param addr
-	 *            the address on the multihomed localhost to bind
-	 * 
-	 * @exception SocketException
-	 *                if an error occured during bind, such as if the port was
-	 *                already bound
-	 */
-	public void bind(int port, InetAddress addr) throws SocketException {
-		String prop = AccessController.doPrivileged(new PriviAction<String>(
-				"bindToDevice"));
-		boolean useBindToDevice = prop != null
-				&& prop.toLowerCase().equals("true");
-		bindToDevice = netImpl.bind2(fd, port, useBindToDevice, addr);
-		if (0 != port) {
-			localPort = port;
-		} else {
-			localPort = netImpl.getSocketLocalPort(fd,
-					NetUtil.preferIPv6Addresses());
-		}
-
-		try {
-			// Ignore failures
-			setOption(SO_BROADCAST, Boolean.TRUE);
-		} catch (IOException e) {
-		}
-	}
-
-	/**
-	 * Close the socket.
-	 */
-	public void close() {
-		synchronized (fd) {
-			if (fd.valid()) {
-				try {
-					netImpl.socketClose(fd);
-				} catch (IOException e) {
-					// TODO do nothing?
-				}
-				fd = new FileDescriptor();
-			}
-		}
-	}
-
-	/**
-	 * Allocate the socket descriptor in the IP stack.
-	 */
-	public void create() throws SocketException {
-		netImpl.createDatagramSocket(fd, NetUtil.preferIPv4Stack());
-	}
-
-	protected void finalize() {
-		close();
-	}
-
-	/**
-	 * Answer the nominated socket option. As the timeouts are not set as
-	 * options in the IP stack, the field value is returned.
-	 * 
-	 * @return Object the nominated socket option value
-	 */
-	public Object getOption(int optID) throws SocketException {
-		if (optID == SocketOptions.SO_TIMEOUT) {
-			return new Integer(receiveTimeout);
-		} else if (optID == SocketOptions.IP_TOS) {
-			return new Integer(trafficClass);
-		} else {
-			// Call the native first so there will be
-			// an exception if the socket if closed.
-			Object result = netImpl.getSocketOption(fd, optID);
-			if (optID == SocketOptions.IP_MULTICAST_IF
-					&& (netImpl.getSocketFlags() & MULTICAST_IF) != 0) {
-				try {
-					return Inet4Address.getByAddress(ipaddress);
-				} catch (UnknownHostException e) {
-					return null;
-				}
-			}
-			return result;
-		}
-	}
-
-	public int getTimeToLive() throws IOException {
-		// Call the native first so there will be an exception if the socket if
-		// closed.
-		int result = (((Byte) getOption(IP_MULTICAST_TTL)).byteValue()) & 0xFF;
-		if ((netImpl.getSocketFlags() & MULTICAST_TTL) != 0) {
-			return ttl;
-		}
-		return result;
-	}
-
-	public byte getTTL() throws IOException {
-		// Call the native first so there will be an exception if the socket if
-		// closed.
-		byte result = ((Byte) getOption(IP_MULTICAST_TTL)).byteValue();
-		if ((netImpl.getSocketFlags() & MULTICAST_TTL) != 0) {
-			return (byte) ttl;
-		}
-		return result;
-	}
-
-	/**
-	 * Add this socket to the multicast group. A socket must joint a group
-	 * before data may be received. A socket may be a member of multiple groups
-	 * but may join any group once.
-	 * 
-	 * @param addr
-	 *            the multicast group to be joined
-	 * @exception java.io.IOException
-	 *                may be thrown while joining a group
-	 */
-	public void join(InetAddress addr) throws IOException {
-		setOption(IP_MULTICAST_ADD, new GenericIPMreq(addr));
-	}
-
-	/**
-	 * Add this socket to the multicast group. A socket must join a group before
-	 * data may be received. A socket may be a member of multiple groups but may
-	 * join any group once.
-	 * 
-	 * @param addr
-	 *            the multicast group to be joined
-	 * @param netInterface
-	 *            the network interface on which the addresses should be dropped
-	 * @exception java.io.IOException
-	 *                may be thrown while joining a group
-	 */
-	public void joinGroup(SocketAddress addr, NetworkInterface netInterface)
-			throws IOException {
-		if (addr instanceof InetSocketAddress) {
-			InetAddress groupAddr = ((InetSocketAddress) addr).getAddress();
-			setOption(IP_MULTICAST_ADD, new GenericIPMreq(groupAddr,
-					netInterface));
-		}
-	}
-
-	/**
-	 * Remove the socket from the multicast group.
-	 * 
-	 * @param addr
-	 *            the multicast group to be left
-	 * @exception java.io.IOException
-	 *                May be thrown while leaving the group
-	 */
-	public void leave(InetAddress addr) throws IOException {
-		setOption(IP_MULTICAST_DROP, new GenericIPMreq(addr));
-	}
-
-	/**
-	 * Remove the socket from the multicast group.
-	 * 
-	 * @param addr
-	 *            the multicast group to be left
-	 * @param netInterface
-	 *            the network interface on which the addresses should be dropped
-	 * @exception java.io.IOException
-	 *                May be thrown while leaving the group
-	 */
-	public void leaveGroup(SocketAddress addr, NetworkInterface netInterface)
-			throws IOException {
-		if (addr instanceof InetSocketAddress) {
-			InetAddress groupAddr = ((InetSocketAddress) addr).getAddress();
-			setOption(IP_MULTICAST_DROP, new GenericIPMreq(groupAddr,
-					netInterface));
-		}
-	}
-
-	// /**
-	// * Connect the socket to a port and address
-	// *
-	// * @param aFD
-	// * the FileDescriptor to associate with the socket
-	// * @param port
-	// * the port to connect to
-	// * @param trafficClass
-	// * the traffic Class to be used then the connection is made
-	// * @param inetAddress
-	// * address to connect to.
-	// *
-	// * @exception SocketException
-	// * if the connect fails
-	// */
-	// protected static native void connectDatagramImpl2(FileDescriptor aFD,
-	// int port, int trafficClass, InetAddress inetAddress)
-	// throws SocketException;
-	//
-	// /**
-	// * Disconnect the socket to a port and address
-	// *
-	// * @param aFD
-	// * the FileDescriptor to associate with the socket
-	// *
-	// * @exception SocketException
-	// * if the disconnect fails
-	// */
-	// protected static native void disconnectDatagramImpl(FileDescriptor aFD)
-	// throws SocketException;
-	//
-	// /**
-	// * Allocate a datagram socket in the IP stack. The socket is associated
-	// with
-	// * the <code>aFD</code>.
-	// *
-	// * @param aFD
-	// * the FileDescriptor to associate with the socket
-	// * @param preferIPv4Stack
-	// * IP stack preference if underlying platform is V4/V6
-	// * @exception SocketException
-	// * upon an allocation error
-	// */
-	// protected static native void createDatagramSocketImpl(FileDescriptor aFD,
-	// boolean preferIPv4Stack) throws SocketException;
-	//
-	// /**
-	// * Bind the socket to the port/localhost in the IP stack.
-	// *
-	// * @param aFD
-	// * the socket descriptor
-	// * @param port
-	// * the option selector
-	// * @param bindToDevice
-	// * bind the socket to the specified interface
-	// * @param inetAddress
-	// * address to connect to.
-	// * @exception SocketException
-	// * thrown if bind operation fails
-	// */
-	// protected static native boolean socketBindImpl2(FileDescriptor aFD,
-	// int port, boolean bindToDevice, InetAddress inetAddress)
-	// throws SocketException;
-	//
-	// /**
-	// * Peek on the socket, update <code>sender</code> address and answer the
-	// * sender port.
-	// *
-	// * @param aFD
-	// * the socket FileDescriptor
-	// * @param sender
-	// * an InetAddress, to be updated with the sender's address
-	// * @param receiveTimeout
-	// * the maximum length of time the socket should block, reading
-	// * @return int the sender port
-	// *
-	// * @exception IOException
-	// * upon an read error or timeout
-	// */
-	// protected static native int peekDatagramImpl(FileDescriptor aFD,
-	// InetAddress sender, int receiveTimeout) throws IOException;
-	//
-	// /**
-	// * Recieve data on the socket into the specified buffer. The packet fields
-	// * <code>data</code> & <code>length</code> are passed in addition to
-	// * <code>packet</code> to eliminate the JNI field access calls.
-	// *
-	// * @param aFD
-	// * the socket FileDescriptor
-	// * @param packet
-	// * the DatagramPacket to receive into
-	// * @param data
-	// * the data buffer of the packet
-	// * @param offset
-	// * the offset in the data buffer
-	// * @param length
-	// * the length of the data buffer in the packet
-	// * @param receiveTimeout
-	// * the maximum length of time the socket should block, reading
-	// * @param peek
-	// * indicates to peek at the data
-	// * @exception IOException
-	// * upon an read error or timeout
-	// */
-	// protected static native int receiveDatagramImpl2(FileDescriptor aFD,
-	// DatagramPacket packet, byte[] data, int offset, int length,
-	// int receiveTimeout, boolean peek) throws IOException;
-	//
-	// /**
-	// * Recieve data on the connected socket into the specified buffer. The
-	// * packet fields <code>data</code> & <code>length</code> are passed in
-	// * addition to <code>packet</code> to eliminate the JNI field access
-	// * calls.
-	// *
-	// * @param aFD
-	// * the socket FileDescriptor
-	// * @param packet
-	// * the DatagramPacket to receive into
-	// * @param data
-	// * the data buffer of the packet
-	// * @param offset
-	// * the offset in the data buffer
-	// * @param length
-	// * the length of the data buffer in the packet
-	// * @param receiveTimeout
-	// * the maximum length of time the socket should block, reading
-	// * @param peek
-	// * indicates to peek at the data
-	// * @exception IOException
-	// * upon an read error or timeout
-	// */
-	// protected static native int recvConnectedDatagramImpl(FileDescriptor aFD,
-	// DatagramPacket packet, byte[] data, int offset, int length,
-	// int receiveTimeout, boolean peek) throws IOException;
-	//
-	// /**
-	// * Send the <code>data</code> to the nominated target <code>address</code>
-	// * and <code>port</code>. These values are derived from the
-	// * DatagramPacket to reduce the field calls within JNI.
-	// *
-	// * @param fd
-	// * the socket FileDescriptor
-	// * @param data
-	// * the data buffer of the packet
-	// * @param offset
-	// * the offset in the data buffer
-	// * @param length
-	// * the length of the data buffer in the packet
-	// * @param port
-	// * the target host port
-	// * @param trafficClass
-	// * the traffic class to be used when the datagram is sent
-	// * @param inetAddress
-	// * address to connect to.
-	// *
-	// * @exception IOException
-	// * upon an read error or timeout
-	// */
-	// protected static native int sendDatagramImpl2(FileDescriptor fd,
-	// byte[] data, int offset, int length, int port,
-	// boolean bindToDevice, int trafficClass, InetAddress inetAddress)
-	// throws IOException;
-	//
-	// /**
-	// * Send the <code>data</code> to the address and port to which the was
-	// * connnected and <code>port</code>.
-	// *
-	// * @param fd
-	// * the socket FileDescriptor
-	// * @param data
-	// * the data buffer of the packet
-	// * @param offset
-	// * the offset in the data buffer
-	// * @param length
-	// * the length of the data buffer in the packet
-	// * @param bindToDevice
-	// * not used, current kept in case needed as was the case for
-	// * sendDatagramImpl
-	// * @exception IOException
-	// * upon an read error or timeout
-	// */
-	// protected static native int sendConnectedDatagramImpl(FileDescriptor fd,
-	// byte[] data, int offset, int length, boolean bindToDevice)
-	// throws IOException;
-
-	protected int peek(InetAddress sender) throws IOException {
-		if (isNativeConnected) {
-			// in this case we know the port and address from which the data
-			// must have be been received as the socket is connected. However,
-			// we still need to do the receive in order to know that there was
-			// data received. We use a short buffer as we don't actually need
-			// the packet, only the knowledge that it is there
-			byte[] storageArray = new byte[10];
-			DatagramPacket pack = new DatagramPacket(storageArray,
-					storageArray.length);
-			netImpl.recvConnectedDatagram(fd, pack, pack.getData(), pack
-					.getOffset(), pack.getLength(), receiveTimeout, true); // peek
-			// to set the sender ,we now use a native function
-			// sender.ipaddress = connectedAddress.getAddress();
-			netImpl.setInetAddress(sender, connectedAddress.getAddress());
-			return connectedPort;
-		}
-		return netImpl.peekDatagram(fd, sender, receiveTimeout);
-	}
-
-	/**
-	 * Answer the data that may be read at this socket. Any data larger than the
-	 * packet buffer length will be discarded. The read will block until either
-	 * data is is read or, if the timeout is defined, the operation times out.
-	 * 
-	 * @exception IOException
-	 *                if an error or timeout occurs during a read
-	 */
-	public void receive(DatagramPacket pack) throws java.io.IOException {
-		try {
-			if (isNativeConnected) {
-				// do not peek
-				netImpl.recvConnectedDatagram(fd, pack, pack.getData(),
-						pack.getOffset(), pack.getLength(), receiveTimeout,
-						false);
-				updatePacketRecvAddress(pack);
-			} else {
-				// receiveDatagramImpl2
-				netImpl.receiveDatagram(fd, pack, pack.getData(), pack
-						.getOffset(), pack.getLength(), receiveTimeout, false);
-			}
-		} catch (InterruptedIOException e) {
-			throw new SocketTimeoutException(e.getMessage());
-		}
-	}
-
-	/**
-	 * Send the data on this socket.
-	 * 
-	 * @exception IOException
-	 *                if an error occurs during the write
-	 */
-	public void send(DatagramPacket packet) throws IOException {
-
-		if (isNativeConnected) {
-			netImpl.sendConnectedDatagram(fd, packet.getData(), packet
-					.getOffset(), packet.getLength(), bindToDevice);
-		} else {
-			// sendDatagramImpl2
-			netImpl.sendDatagram(fd, packet.getData(), packet.getOffset(),
-					packet.getLength(), packet.getPort(), bindToDevice,
-					trafficClass, packet.getAddress());
-		}
-	}
-
-	/**
-	 * Set the nominated socket option. As the timeouts are not set as options
-	 * in the IP stack, the value is stored in an instance field.
-	 * 
-	 * @exception SocketException
-	 *                thrown if the option value is unsupported or invalid
-	 */
-	public void setOption(int optID, Object val) throws SocketException {
-		// for datagram sockets on some platforms we have to set both the
-		// REUSEADDR AND REUSEPORT so for REUSEADDR set this option option
-		// which tells the VM to set the two values as appropriate for the
-		// platform
-		if (optID == SocketOptions.SO_REUSEADDR) {
-			optID = REUSEADDR_AND_REUSEPORT;
-		}
-
-		if (optID == SocketOptions.SO_TIMEOUT) {
-			receiveTimeout = ((Integer) val).intValue();
-		} else {
-			int flags = netImpl.getSocketFlags();
-			try {
-				netImpl.setSocketOption(fd, optID | (flags << 16), val);
-			} catch (SocketException e) {
-				// we don't throw an exception for IP_TOS even if the platform
-				// won't let us set the requested value
-				if (optID != SocketOptions.IP_TOS) {
-					throw e;
-				}
-			}
-			if (optID == SocketOptions.IP_MULTICAST_IF
-					&& (flags & MULTICAST_IF) != 0) {
-				InetAddress inet = (InetAddress) val;
-				if (bytesToInt(inet.getAddress(), 0) == 0
-						|| inet.isLoopbackAddress()) {
-					ipaddress = ((InetAddress) val).getAddress();
-				} else {
-					InetAddress local = null;
-					try {
-						local = InetAddress.getLocalHost();
-					} catch (UnknownHostException e) {
-						throw new SocketException("getLocalHost(): "
-								+ e.toString());
-					}
-					if (inet.equals(local)) {
-						ipaddress = ((InetAddress) val).getAddress();
-					} else {
-						throw new SocketException(val + " != getLocalHost(): "
-								+ local);
-					}
-				}
-			}
-			// save this value as it is acutally used differently for IPv4 and
-			// IPv6 so we cannot get the value using the getOption. The option
-			// is actually only set for IPv4 and a masked version of the value
-			// will be set as only a subset of the values are allowed on the
-			// socket. Therefore we need to retain it to return the value that
-			// was set. We also need the value to be passed into a number of
-			// natives so that it can be used properly with IPv6
-			if (optID == SocketOptions.IP_TOS) {
-				trafficClass = ((Integer) val).intValue();
-			}
-		}
-	}
-
-	public void setTimeToLive(int ttl) throws java.io.IOException {
-		setOption(IP_MULTICAST_TTL, new Byte((byte) (ttl & 0xFF)));
-		if ((netImpl.getSocketFlags() & MULTICAST_TTL) != 0) {
-			this.ttl = ttl;
-		}
-	}
-
-	public void setTTL(byte ttl) throws java.io.IOException {
-		setOption(IP_MULTICAST_TTL, new Byte(ttl));
-		if ((netImpl.getSocketFlags() & MULTICAST_TTL) != 0) {
-			this.ttl = ttl;
-		}
-	}
-
-	/**
-	 * Connect the socket to the specified remote address and port.
-	 * 
-	 * @param inetAddr
-	 *            the remote address
-	 * @param port
-	 *            the remote port
-	 * 
-	 * @exception SocketException
-	 *                possibly thrown, if the datagram socket cannot be
-	 *                connected to the specified remote address and port
-	 */
-	public void connect(InetAddress inetAddr, int port) throws SocketException {
-
-		// connectDatagram impl2
-		netImpl.connectDatagram(fd, port, trafficClass, inetAddr);
-
-		// if we get here then we are connected at the native level
-		try {
-			connectedAddress = InetAddress.getByAddress(inetAddr.getAddress());
-		} catch (UnknownHostException e) {
-			// this is never expected to happen as we should not have gotten
-			// here if the address is not resolvable
-			throw new SocketException(Msg.getString(
-					"K0317", inetAddr.getHostName())); //$NON-NLS-1$
-		}
-		connectedPort = port;
-		isNativeConnected = true;
-	}
-
-	/**
-	 * Disconnect the socket from the remote address and port.
-	 */
-	public void disconnect() {
-		try {
-			netImpl.disconnectDatagram(fd);
-		} catch (Exception e) {
-			// there is currently no way to return an error so just eat any
-			// exception
-		}
-		connectedPort = -1;
-		connectedAddress = null;
-		isNativeConnected = false;
-	}
-
-	/**
-	 * Receive data into the supplied datagram packet by peeking. The data is
-	 * not removed and will be received by another peekData() or receive() call.
-	 * 
-	 * This call will block until either data is received or, if a timeout is
-	 * set, the timeout expires.
-	 * 
-	 * @param pack
-	 *            the DatagramPacket used to store the data
-	 * 
-	 * @return the port the packet was received from
-	 * 
-	 * @exception IOException
-	 *                if an error occurs
-	 */
-	public int peekData(DatagramPacket pack) throws IOException {
-		try {
-			if (isNativeConnected) {
-				netImpl.recvConnectedDatagram(fd, pack, pack.getData(),
-						pack.getOffset(), pack.getLength(), receiveTimeout,
-						true); // peek
-				updatePacketRecvAddress(pack);
-			} else {
-				// receiveDatagram 2
-				netImpl.receiveDatagram(fd, pack, pack.getData(), pack
-						.getOffset(), pack.getLength(), receiveTimeout, true); // peek
-			}
-		} catch (InterruptedIOException e) {
-			throw new SocketTimeoutException(e.getMessage());
-		}
-		return pack.getPort();
-	}
-
-	/**
-	 * Set the received address and port in the packet. We do this when the
-	 * Datagram socket is connected at the native level and the
-	 * recvConnnectedDatagramImpl does not update the packet with address from
-	 * which the packet was received
-	 * 
-	 * @param packet
-	 *            the packet to be updated
-	 */
-	private void updatePacketRecvAddress(DatagramPacket packet) {
-		packet.setAddress(connectedAddress);
-		packet.setPort(connectedPort);
-	}
-
-	static void intToBytes(int value, byte bytes[], int start) {
-		// Shift the int so the current byte is right-most
-		// Use a byte mask of 255 to single out the last byte.
-		bytes[start] = (byte) ((value >> 24) & 255);
-		bytes[start + 1] = (byte) ((value >> 16) & 255);
-		bytes[start + 2] = (byte) ((value >> 8) & 255);
-		bytes[start + 3] = (byte) (value & 255);
-	}
-
-	static int bytesToInt(byte bytes[], int start) {
-		// First mask the byte with 255, as when a negative
-		// signed byte converts to an integer, it has bits
-		// on in the first 3 bytes, we are only concerned
-		// about the right-most 8 bits.
-		// Then shift the rightmost byte to align with its
-		// position in the integer.
-		int value = ((bytes[start + 3] & 255))
-				| ((bytes[start + 2] & 255) << 8)
-				| ((bytes[start + 1] & 255) << 16)
-				| ((bytes[start] & 255) << 24);
-		return value;
-	}
+     * Set the received address and port in the packet. We do this when the
+     * Datagram socket is connected at the native level and the
+     * recvConnnectedDatagramImpl does not update the packet with address from
+     * which the packet was received
+     * 
+     * @param packet
+     *            the packet to be updated
+     */
+    private void updatePacketRecvAddress(DatagramPacket packet) {
+        packet.setAddress(connectedAddress);
+        packet.setPort(connectedPort);
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainMulticastSocketImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainMulticastSocketImpl.java?view=diff&rev=440907&r1=440906&r2=440907
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainMulticastSocketImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainMulticastSocketImpl.java Wed Sep  6 17:01:16 2006
@@ -15,12 +15,10 @@
 
 package org.apache.harmony.luni.net;
 
-import java.io.FileDescriptor;
 import java.net.SocketException;
 
 import org.apache.harmony.luni.platform.Platform;
 
-
 /**
  * This class was added so we can create sockets with options that are needed
  * for server sockets. It just overrides create so that we call new natives
@@ -30,25 +28,9 @@
  * used, for earlier versions the original PlainSocketImpl is used.
  */
 class PlainMulticastSocketImpl extends PlainDatagramSocketImpl {
-    
-	// /**
-	// * Answer the result of attempting to create a multicast socket in the IP
-	// * stack. Any special options required for server sockets will be set by
-	// * this method.
-	// *
-	// * @param aFD
-	// * the socket FileDescriptor
-	// * @exception SocketException
-	// * if an error occurs while creating the socket
-	// */
-	// static native void createMulticastSocketImpl(FileDescriptor aFD,
-	// boolean preferIPv4Stack) throws SocketException;
 
-    /**
-	 * Allocate the socket descriptor in the IP stack.
-	 */
-	public void create() throws SocketException {
-		Platform.getNetworkSystem()
-				.createMulticastSocket(fd, NetUtil.preferIPv4Stack());
-	}
+    @Override
+    public void create() throws SocketException {
+        Platform.getNetworkSystem().createMulticastSocket(fd, NetUtil.preferIPv4Stack());
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainServerSocketImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainServerSocketImpl.java?view=diff&rev=440907&r1=440906&r2=440907
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainServerSocketImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainServerSocketImpl.java Wed Sep  6 17:01:16 2006
@@ -21,7 +21,6 @@
 import org.apache.harmony.luni.net.NetUtil;
 import org.apache.harmony.luni.net.PlainSocketImpl;
 
-
 /**
  * This class was added so we can create sockets with options that are needed
  * for server sockets. It just overrides create so that we call new natives
@@ -31,49 +30,23 @@
  * used, for earlier versions the original PlainSocketImpl is used.
  */
 class PlainServerSocketImpl extends PlainSocketImpl {
-    
-    public PlainServerSocketImpl(){
+
+    public PlainServerSocketImpl() {
         super();
     }
-    
-    public PlainServerSocketImpl(FileDescriptor fd){
+
+    public PlainServerSocketImpl(FileDescriptor fd) {
         super();
         this.fd = fd;
     }
 
-	/**
-	 * Answer the result of attempting to create a server stream socket in the
-	 * IP stack. Any special options required for server sockets will be set by
-	 * this method.
-	 * 
-	 * @param aFD
-	 *            the socket FileDescriptor
-	 * @exception SocketException
-	 *                if an error occurs while creating the socket
-	 */
-	// static native void createServerStreamSocketImpl(FileDescriptor aFD,
-	// boolean preferIPv4Stack) throws SocketException;
-	/**
-	 * Creates a new unconnected socket. If streaming is true, create a stream
-	 * socket, else a datagram socket. The deprecated datagram usage is not
-	 * supported and will throw an exception.
-	 * 
-	 * @param isStreaming
-	 *            true, if the socket is type streaming
-	 * @exception SocketException
-	 *                if an error occurs while creating the socket
-	 */
-	protected void create(boolean isStreaming) throws SocketException {
-		streaming = isStreaming;
-		// if (isStreaming) {
-		// createServerStreamSocketImpl(fd, Socket.preferIPv4Stack());
-		// } else {
-		// createDatagramSocketImpl(fd, Socket.preferIPv4Stack());
-		// }
-		if (isStreaming) {
-			netImpl.createServerStreamSocket(fd, NetUtil.preferIPv4Stack());
-		} else {
-			netImpl.createDatagramSocket(fd, NetUtil.preferIPv4Stack());
-		}
-	}
+    @Override
+    protected void create(boolean isStreaming) throws SocketException {
+        streaming = isStreaming;
+        if (isStreaming) {
+            netImpl.createServerStreamSocket(fd, NetUtil.preferIPv4Stack());
+        } else {
+            netImpl.createDatagramSocket(fd, NetUtil.preferIPv4Stack());
+        }
+    }
 }



Mime
View raw message