< prev index next >

src/java.base/share/classes/java/net/Socket.java

Print this page




1774      *
1775      * @throws IOException if an I/O error occurs, or if the socket is closed.
1776      *
1777      * @throws NullPointerException if name is {@code null}
1778      *
1779      * @throws SecurityException if a security manager is set and if the socket
1780      *         option requires a security permission and if the caller does
1781      *         not have the required permission.
1782      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
1783      *         do not require any security permission.
1784      *
1785      * @since 9
1786      */
1787     @SuppressWarnings("unchecked")
1788     public <T> T getOption(SocketOption<T> name) throws IOException {
1789         return getImpl().getOption(name);
1790     }
1791 
1792     private static Set<SocketOption<?>> options;
1793     private static boolean optionsSet = false;

1794 
1795     /**
1796      * Returns a set of the socket options supported by this socket.
1797      *
1798      * This method will continue to return the set of options even after
1799      * the socket has been closed.
1800      *
1801      * @return A set of the socket options supported by this socket. This set
1802      *         may be empty if the socket's SocketImpl cannot be created.
1803      *
1804      * @since 9
1805      */
1806     public Set<SocketOption<?>> supportedOptions() {
1807         synchronized (Socket.class) {
1808             if (optionsSet) {


1809                 return options;
1810             }
1811             try {
1812                 SocketImpl impl = getImpl();
1813                 options = Collections.unmodifiableSet(impl.supportedOptions());
1814             } catch (IOException e) {
1815                 options = Collections.emptySet();
1816             }





1817             optionsSet = true;

1818             return options;
1819         }
1820     }
1821 }


1774      *
1775      * @throws IOException if an I/O error occurs, or if the socket is closed.
1776      *
1777      * @throws NullPointerException if name is {@code null}
1778      *
1779      * @throws SecurityException if a security manager is set and if the socket
1780      *         option requires a security permission and if the caller does
1781      *         not have the required permission.
1782      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
1783      *         do not require any security permission.
1784      *
1785      * @since 9
1786      */
1787     @SuppressWarnings("unchecked")
1788     public <T> T getOption(SocketOption<T> name) throws IOException {
1789         return getImpl().getOption(name);
1790     }
1791 
1792     private static Set<SocketOption<?>> options;
1793     private static boolean optionsSet = false;
1794     private static boolean rdmaOptionsSet = false;
1795 
1796     /**
1797      * Returns a set of the socket options supported by this socket.
1798      *
1799      * This method will continue to return the set of options even after
1800      * the socket has been closed.
1801      *
1802      * @return A set of the socket options supported by this socket. This set
1803      *         may be empty if the socket's SocketImpl cannot be created.
1804      *
1805      * @since 9
1806      */
1807     public Set<SocketOption<?>> supportedOptions() {
1808         synchronized (Socket.class) {
1809             String currentImpl = impl.getClass().getName();
1810             boolean rdma = currentImpl.equals("rdma.ch.RdmaSocketImpl");
1811             if ((rdma && rdmaOptionsSet) || (!rdma && optionsSet)) {
1812                 return options;
1813             }
1814             try {
1815                 SocketImpl impl = getImpl();
1816                 options = Collections.unmodifiableSet(impl.supportedOptions());
1817             } catch (IOException e) {
1818                 options = Collections.emptySet();
1819             }
1820             if (rdma) {
1821                 rdmaOptionsSet = true;
1822                 optionsSet = false;
1823             } else {
1824                 rdmaOptionsSet = false;
1825                 optionsSet = true;
1826             }
1827             return options;
1828         }
1829     }
1830 }
< prev index next >