15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.net;
27
28 import java.io.InputStream;
29 import java.io.OutputStream;
30 import java.io.IOException;
31 import java.nio.channels.SocketChannel;
32 import java.security.AccessController;
33 import java.security.PrivilegedExceptionAction;
34 import java.security.PrivilegedAction;
35
36 /**
37 * This class implements client sockets (also called just
38 * "sockets"). A socket is an endpoint for communication
39 * between two machines.
40 * <p>
41 * The actual work of the socket is performed by an instance of the
42 * {@code SocketImpl} class. An application, by changing
43 * the socket factory that creates the socket implementation,
44 * can configure itself to create sockets appropriate to the local
45 * firewall.
46 *
47 * @author unascribed
48 * @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
49 * @see java.net.SocketImpl
50 * @see java.nio.channels.SocketChannel
51 * @since JDK1.0
52 */
53 public
54 class Socket implements java.io.Closeable {
1703 * @param connectionTime
1704 * An {@code int} expressing the relative importance of a short
1705 * connection time
1706 *
1707 * @param latency
1708 * An {@code int} expressing the relative importance of low
1709 * latency
1710 *
1711 * @param bandwidth
1712 * An {@code int} expressing the relative importance of high
1713 * bandwidth
1714 *
1715 * @since 1.5
1716 */
1717 public void setPerformancePreferences(int connectionTime,
1718 int latency,
1719 int bandwidth)
1720 {
1721 /* Not implemented yet */
1722 }
1723 }
|
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.net;
27
28 import java.io.InputStream;
29 import java.io.OutputStream;
30 import java.io.IOException;
31 import java.nio.channels.SocketChannel;
32 import java.security.AccessController;
33 import java.security.PrivilegedExceptionAction;
34 import java.security.PrivilegedAction;
35 import java.util.Set;
36 import java.util.Collections;
37
38 /**
39 * This class implements client sockets (also called just
40 * "sockets"). A socket is an endpoint for communication
41 * between two machines.
42 * <p>
43 * The actual work of the socket is performed by an instance of the
44 * {@code SocketImpl} class. An application, by changing
45 * the socket factory that creates the socket implementation,
46 * can configure itself to create sockets appropriate to the local
47 * firewall.
48 *
49 * @author unascribed
50 * @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
51 * @see java.net.SocketImpl
52 * @see java.nio.channels.SocketChannel
53 * @since JDK1.0
54 */
55 public
56 class Socket implements java.io.Closeable {
1705 * @param connectionTime
1706 * An {@code int} expressing the relative importance of a short
1707 * connection time
1708 *
1709 * @param latency
1710 * An {@code int} expressing the relative importance of low
1711 * latency
1712 *
1713 * @param bandwidth
1714 * An {@code int} expressing the relative importance of high
1715 * bandwidth
1716 *
1717 * @since 1.5
1718 */
1719 public void setPerformancePreferences(int connectionTime,
1720 int latency,
1721 int bandwidth)
1722 {
1723 /* Not implemented yet */
1724 }
1725
1726
1727 /**
1728 * Sets the value of a socket option.
1729 *
1730 * @param name The socket option
1731 * @param value The value of the socket option. A value of {@code null}
1732 * may be valid for some options.
1733 * @return this Socket
1734 *
1735 * @throws UnsupportedOperationException if the socket does not support
1736 * the option.
1737 *
1738 * @throws IllegalArgumentException if the value is not valid for
1739 * the option.
1740 *
1741 * @throws IOException if an I/O error occurs, or if the socket is closed.
1742 *
1743 * @throws NullPointerException if name is {@code null}
1744 *
1745 * @throws SecurityException if a security manager is set and if the socket
1746 * option requires a security permission and if the caller does
1747 * not have the required permission.
1748 * {@link java.net.StandardSocketOptions StandardSocketOptions}
1749 * do not require any security permission.
1750 *
1751 * @since 1.9
1752 */
1753 public <T> Socket setOption(SocketOption<T> name, T value)
1754 throws IOException
1755 {
1756 getImpl().setOption(name, value);
1757 return this;
1758 }
1759
1760 /**
1761 * Returns the value of a socket option.
1762 *
1763 * @param name The socket option
1764 *
1765 * @return The value of the socket option.
1766 *
1767 * @throws UnsupportedOperationException if the socket does not support
1768 * the option.
1769 *
1770 * @throws IOException if an I/O error occurs, or if the socket is closed.
1771 *
1772 * @throws NullPointerException if name is {@code null}
1773 *
1774 * @throws SecurityException if a security manager is set and if the socket
1775 * option requires a security permission and if the caller does
1776 * not have the required permission.
1777 * {@link java.net.StandardSocketOptions StandardSocketOptions}
1778 * do not require any security permission.
1779 *
1780 * @since 1.9
1781 */
1782 @SuppressWarnings("unchecked")
1783 public <T> T getOption(SocketOption<T> name) throws IOException
1784 {
1785 return getImpl().getOption(name);
1786 }
1787
1788 private static Set<SocketOption<?>> options;
1789 private static boolean optionsSet = false;
1790
1791 /**
1792 * Returns a set of the socket options supported by this socket.
1793 *
1794 * This method will continue to return the set of options even after
1795 * the socket has been closed.
1796 *
1797 * @return A set of the socket options supported by this socket. This set
1798 * may be empty if the socket's SocketImpl cannot be created.
1799 *
1800 * @since 1.9
1801 */
1802 public Set<SocketOption<?>> supportedOptions()
1803 {
1804 synchronized (Socket.class) {
1805 if (optionsSet) {
1806 return options;
1807 }
1808 try {
1809 SocketImpl impl = getImpl();
1810 options = Collections.unmodifiableSet(impl.supportedOptions());
1811 } catch (IOException e) {
1812 options = Collections.emptySet();
1813 }
1814 optionsSet = true;
1815 return options;
1816 }
1817 }
1818 }
|