Index: src/test/java/tests/api/java/net/ServerSocketTest.java =================================================================== --- src/test/java/tests/api/java/net/ServerSocketTest.java (revision 392901) +++ src/test/java/tests/api/java/net/ServerSocketTest.java (working copy) @@ -1,4 +1,4 @@ -/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable +/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -881,6 +881,14 @@ handleException(e, SO_RCVBUF); } } + + /* + * @tests java.net.ServerSocket#setPerformancePreference() + */ + public void test_setPerformancePreference_Int_Int_Int() throws Exception { + ServerSocket theSocket = new ServerSocket(); + theSocket.setPerformancePreferences(1,1,1); + } /** * Sets up the fixture, for example, open a network connection. This method Index: src/test/java/tests/api/java/net/SocketImplTest.java =================================================================== --- src/test/java/tests/api/java/net/SocketImplTest.java (revision 392901) +++ src/test/java/tests/api/java/net/SocketImplTest.java (working copy) @@ -1,4 +1,4 @@ -/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable +/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,13 @@ package tests.api.java.net; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.Socket; +import java.net.SocketAddress; +import java.net.SocketException; +import java.net.SocketImpl; import tests.support.Support_Configuration; @@ -62,7 +67,72 @@ System.setProperties(null); } } + + /* + * @tests java.net.SocketImpl#setPerformancePreference() + */ + public void test_setPerformancePreference_Int_Int_Int() throws Exception { + MockSocketImpl theSocket = new MockSocketImpl(); + theSocket.setPerformancePreference(1,1,1); + } + + + // the mock class for test, leave all method empty + class MockSocketImpl extends SocketImpl{ + + protected void accept(SocketImpl newSocket) throws IOException { + } + protected int available() throws IOException { + return 0; + } + + protected void bind(InetAddress address, int port) throws IOException { + } + + protected void close() throws IOException { + } + + protected void connect(String host, int port) throws IOException { + } + + protected void connect(InetAddress address, int port) throws IOException { + } + + protected void create(boolean isStreaming) throws IOException { + } + + protected InputStream getInputStream() throws IOException { + return null; + } + + public Object getOption(int optID) throws SocketException { + return null; + } + + protected OutputStream getOutputStream() throws IOException { + return null; + } + + protected void listen(int backlog) throws IOException { + } + + public void setOption(int optID, Object val) throws SocketException { + } + + protected void connect(SocketAddress remoteAddr, int timeout) throws IOException { + } + + protected void sendUrgentData(int value) throws IOException { + } + + public void setPerformancePreference(int connectionTime, + int latency, + int bandwidth){ + super.setPerformancePreferences(connectionTime, latency, bandwidth); + } + } + protected void setUp() { } Index: src/test/java/tests/api/java/net/SocketTest.java =================================================================== --- src/test/java/tests/api/java/net/SocketTest.java (revision 392901) +++ src/test/java/tests/api/java/net/SocketTest.java (working copy) @@ -1,4 +1,4 @@ -/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable +/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -2498,6 +2498,14 @@ } } + /* + * @tests java.net.Socket#setPerformancePreference() + */ + public void test_setPerformancePreference_Int_Int_Int() throws Exception { + Socket theSocket = new Socket(); + theSocket.setPerformancePreferences(1,1,1); + } + /** * */ Index: src/main/java/java/net/ServerSocket.java =================================================================== --- src/main/java/java/net/ServerSocket.java (revision 392901) +++ src/main/java/java/net/ServerSocket.java (working copy) @@ -1,4 +1,4 @@ -/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable +/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,13 @@ private boolean isBound = false; private boolean isClosed = false; + + private int connectionTime = 0; + private int latency = 0; + + private int bandwidth = 0; + /** * Construct a ServerSocket, which is not bound to any port. The default * number of pending connections may be backlogged. @@ -500,4 +506,25 @@ checkClosedAndCreate(true); return ((Integer) impl.getOption(SocketOptions.SO_RCVBUF)).intValue(); } + + /** + * sets performance preference for connectionTime,latency and bandwidth + * + * @param connectionTime + * the importance of connect time + * @param latency + * the importance of latency + * @param bandwidth + * the importance of bandwidth + */ + public void setPerformancePreferences(int connectionTime, int latency, + int bandwidth) { + if(!this.isBound){ + this.connectionTime = connectionTime; + this.latency = latency; + this.bandwidth = bandwidth; + } + return; + } + } Index: src/main/java/java/net/SocketImpl.java =================================================================== --- src/main/java/java/net/SocketImpl.java (revision 392901) +++ src/main/java/java/net/SocketImpl.java (working copy) @@ -1,4 +1,4 @@ -/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable +/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -500,8 +500,22 @@ * when an error occurs sending urgent data */ protected abstract void sendUrgentData(int value) throws IOException; - -// static native boolean supportsUrgentDataImpl(FileDescriptor fd); + + /** + * sets performance preference for connectionTime,latency and bandwidth + * defaultly does nothing at all. + * @param connectionTime + * the importance of connect time + * @param latency + * the importance of latency + * @param bandwidth + * the importance of bandwidth + */ + protected void setPerformancePreferences(int connectionTime, int latency, + int bandwidth) { + // do nothing at all + } +// static native boolean supportsUrgentDataImpl(FileDescriptor fd); // // static native boolean sendUrgentDataImpl(FileDescriptor fd, byte value); } Index: src/main/java/java/net/Socket.java =================================================================== --- src/main/java/java/net/Socket.java (revision 392901) +++ src/main/java/java/net/Socket.java (working copy) @@ -1,4 +1,4 @@ -/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable +/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,13 @@ private boolean isOutputShutdown = false; private Object connectLock = new Object(); + + private int connectionTime = 0; + private int latency = 0; + + private int bandwidth = 0; + static final int MULTICAST_IF = 1; static final int MULTICAST_TTL = 2; @@ -1045,5 +1051,25 @@ return true; return false; } + + /** + * sets performance preference for connectionTime,latency and bandwidth + * + * @param connectionTime + * the importance of connect time + * @param latency + * the importance of latency + * @param bandwidth + * the importance of bandwidth + */ + public void setPerformancePreferences(int connectionTime, int latency, + int bandwidth) { + if(!this.isBound){ + this.connectionTime = connectionTime; + this.latency = latency; + this.bandwidth = bandwidth; + } + return; + } }