< prev index next >

src/jdk.net/share/classes/jdk/net/Sockets.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 jdk.net;
  27 
  28 import java.net.*;

  29 import java.io.IOException;

  30 import java.util.Collections;
  31 import java.util.HashMap;
  32 import java.util.HashSet;
  33 import java.util.Map;
  34 import java.util.Set;


  35 import jdk.net.ExtendedSocketOptions.PlatformSocketOptions;
  36 
  37 /**
  38  * Defines static methods to set and get socket options defined by the
  39  * {@link java.net.SocketOption} interface. All of the standard options defined
  40  * by {@link java.net.Socket}, {@link java.net.ServerSocket}, and
  41  * {@link java.net.DatagramSocket} can be set this way, as well as additional
  42  * or platform specific options supported by each socket type.
  43  * <p>
  44  * The {@link #supportedOptions(Class)} method can be called to determine
  45  * the complete set of options available (per socket type) on the
  46  * current system.
  47  * <p>
  48  * When a security manager is installed, some non-standard socket options
  49  * may require a security permission before being set or get.
  50  * The details are specified in {@link ExtendedSocketOptions}. No permission
  51  * is required for {@link java.net.StandardSocketOptions}.
  52  *
  53  * @see java.nio.channels.NetworkChannel
  54  */


 357 
 358         static {
 359             Set<SocketOption<?>> s = new Socket().supportedOptions();
 360             available = s.contains(ExtendedSocketOptions.TCP_QUICKACK);
 361         }
 362     }
 363 
 364     /**
 365      * Tells whether TCP_KEEPALIVE options are supported.
 366      */
 367     static class KeepAliveOptions {
 368 
 369         static final boolean AVAILABLE;
 370 
 371         static {
 372             Set<SocketOption<?>> s = new Socket().supportedOptions();
 373             AVAILABLE = s.containsAll(Set.of(ExtendedSocketOptions.TCP_KEEPCOUNT,
 374                                             ExtendedSocketOptions.TCP_KEEPIDLE,
 375                                             ExtendedSocketOptions.TCP_KEEPINTERVAL));
 376         }












































































 377     }
 378 }


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 jdk.net;
  27 
  28 import java.net.*;
  29 import java.nio.channels.*;
  30 import java.io.IOException;
  31 import java.lang.reflect.Field;
  32 import java.util.Collections;
  33 import java.util.HashMap;
  34 import java.util.HashSet;
  35 import java.util.Map;
  36 import java.util.Set;
  37 import rdma.ch.RdmaPollSelectorProvider;
  38 import rdma.ch.RdmaSocketImpl;
  39 import jdk.net.ExtendedSocketOptions.PlatformSocketOptions;
  40 
  41 /**
  42  * Defines static methods to set and get socket options defined by the
  43  * {@link java.net.SocketOption} interface. All of the standard options defined
  44  * by {@link java.net.Socket}, {@link java.net.ServerSocket}, and
  45  * {@link java.net.DatagramSocket} can be set this way, as well as additional
  46  * or platform specific options supported by each socket type.
  47  * <p>
  48  * The {@link #supportedOptions(Class)} method can be called to determine
  49  * the complete set of options available (per socket type) on the
  50  * current system.
  51  * <p>
  52  * When a security manager is installed, some non-standard socket options
  53  * may require a security permission before being set or get.
  54  * The details are specified in {@link ExtendedSocketOptions}. No permission
  55  * is required for {@link java.net.StandardSocketOptions}.
  56  *
  57  * @see java.nio.channels.NetworkChannel
  58  */


 361 
 362         static {
 363             Set<SocketOption<?>> s = new Socket().supportedOptions();
 364             available = s.contains(ExtendedSocketOptions.TCP_QUICKACK);
 365         }
 366     }
 367 
 368     /**
 369      * Tells whether TCP_KEEPALIVE options are supported.
 370      */
 371     static class KeepAliveOptions {
 372 
 373         static final boolean AVAILABLE;
 374 
 375         static {
 376             Set<SocketOption<?>> s = new Socket().supportedOptions();
 377             AVAILABLE = s.containsAll(Set.of(ExtendedSocketOptions.TCP_KEEPCOUNT,
 378                                             ExtendedSocketOptions.TCP_KEEPIDLE,
 379                                             ExtendedSocketOptions.TCP_KEEPINTERVAL));
 380         }
 381     }
 382 
 383     /**
 384      * Creates an unconnected RDMA socket
 385      */
 386     public static Socket openRdmaSocket() throws IOException {
 387         RdmaSocketImpl impl = new RdmaSocketImpl();
 388         Socket s = new Socket(impl) {};
 389         return s;
 390     }
 391 
 392     /**
 393      * Creates an unbound RDMA server socket
 394      */
 395     public static ServerSocket openRdmaServerSocket() throws IOException {
 396         SocketImpl impl = new RdmaSocketImpl();
 397         ServerSocket ss = new ServerSocket(impl) {
 398             public Socket accept() throws IOException {
 399                 if (isClosed())
 400                 throw new SocketException("Socket is closed");
 401                 if (!isBound())
 402                     throw new SocketException("Socket is not bound yet");
 403 
 404                 Socket s = openRdmaSocket();
 405                 implAccept(s);
 406                 return s;
 407             }    
 408         };
 409         return ss;
 410     }
 411 
 412     /**
 413      * Opens a RDMA socket channel.
 414      *
 415      * @return  A new RDMA socket channel
 416      *
 417      * @throws  IOException
 418      *          If an I/O error occurs
 419      */
 420     public static SocketChannel openRdmaSocketChannel() throws IOException {
 421         return RdmaPollSelectorProvider.provider().openSocketChannel();
 422     }
 423 
 424     /**
 425      * Opens a RDMA server-socket channel.
 426      *
 427      * <p> The new channel is created by invoking the {@link
 428      * java.nio.channels.spi.SelectorProvider#openServerSocketChannel
 429      * openServerSocketChannel} method of the system-wide default {@link
 430      * java.nio.channels.spi.SelectorProvider} object.
 431      *
 432      * <p> The new channel's socket is initially unbound; it must be bound to a
 433      * specific address via one of its socket's {@link
 434      * java.net.ServerSocket#bind(SocketAddress) bind} methods before
 435      * connections can be accepted.  </p>
 436      *
 437      * @return  A new RDMA server socket channel
 438      *
 439      * @throws  IOException
 440      *          If an I/O error occurs
 441      */
 442     public static ServerSocketChannel openRdmaServerSocketChannel()
 443         throws IOException {
 444         return RdmaPollSelectorProvider.provider().openServerSocketChannel();
 445     }
 446 
 447     /**
 448      * Opens a RDMA selector.
 449      *
 450      * @return  A new RDMA selector
 451      *
 452      * @throws  IOException
 453      *          If an I/O error occurs
 454      */
 455     public static Selector openRdmaSelector() throws IOException {
 456         return RdmaPollSelectorProvider.provider().openSelector();
 457     }
 458 }
< prev index next >