< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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  */


 332         if (flowsupported) {
 333             set.add(ExtendedSocketOptions.SO_FLOW_SLA);
 334         }
 335         set = Collections.unmodifiableSet(set);
 336         options.put(MulticastSocket.class, set);
 337 
 338         return Collections.unmodifiableMap(options);
 339     }
 340 
 341     /**
 342      * Tells whether TCP_QUICKACK is supported.
 343      */
 344     static class QuickAck {
 345 
 346         static final boolean available;
 347 
 348         static {
 349             Set<SocketOption<?>> s = new Socket().supportedOptions();
 350             available = s.contains(ExtendedSocketOptions.TCP_QUICKACK);
 351         }

































































 352     }
 353 }
   1 /*
   2  * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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.util.Collections;
  32 import java.util.HashMap;
  33 import java.util.HashSet;
  34 import java.util.Map;
  35 import java.util.Set;
  36 import rdma.ch.RdmaPollSelectorProvider;
  37 import rdma.ch.RdmaSocketImpl;
  38 import jdk.net.ExtendedSocketOptions.PlatformSocketOptions;
  39 
  40 /**
  41  * Defines static methods to set and get socket options defined by the
  42  * {@link java.net.SocketOption} interface. All of the standard options defined
  43  * by {@link java.net.Socket}, {@link java.net.ServerSocket}, and
  44  * {@link java.net.DatagramSocket} can be set this way, as well as additional
  45  * or platform specific options supported by each socket type.
  46  * <p>
  47  * The {@link #supportedOptions(Class)} method can be called to determine
  48  * the complete set of options available (per socket type) on the
  49  * current system.
  50  * <p>
  51  * When a security manager is installed, some non-standard socket options
  52  * may require a security permission before being set or get.
  53  * The details are specified in {@link ExtendedSocketOptions}. No permission
  54  * is required for {@link java.net.StandardSocketOptions}.
  55  *
  56  * @see java.nio.channels.NetworkChannel
  57  */


 335         if (flowsupported) {
 336             set.add(ExtendedSocketOptions.SO_FLOW_SLA);
 337         }
 338         set = Collections.unmodifiableSet(set);
 339         options.put(MulticastSocket.class, set);
 340 
 341         return Collections.unmodifiableMap(options);
 342     }
 343 
 344     /**
 345      * Tells whether TCP_QUICKACK is supported.
 346      */
 347     static class QuickAck {
 348 
 349         static final boolean available;
 350 
 351         static {
 352             Set<SocketOption<?>> s = new Socket().supportedOptions();
 353             available = s.contains(ExtendedSocketOptions.TCP_QUICKACK);
 354         }
 355     }
 356 
 357     /**
 358      * Creates an unconnected RDMA socket
 359      */
 360     public static Socket openRdmaSocket() throws IOException {
 361         RdmaSocketImplFactory factory = new RdmaSocketImplFactory();
 362         SocketImpl impl = factory.createSocketImpl();
 363         return new Socket(impl) { };
 364     }
 365 
 366     /**
 367      * Creates an unbound RDMA server socket
 368      */
 369     public static ServerSocket openRdmaServerSocket() throws IOException {
 370         RdmaSocketImplFactory factory = new RdmaSocketImplFactory();
 371         SocketImpl impl = factory.createSocketImpl();
 372         return new ServerSocket(impl) { };
 373     }
 374 
 375     /**
 376      * Opens a RDMA socket channel.
 377      *
 378      * @return  A new RDMA socket channel
 379      *
 380      * @throws  IOException
 381      *          If an I/O error occurs
 382      */
 383     public static SocketChannel openRdmaSocketChannel() throws IOException {
 384         return RdmaPollSelectorProvider.provider().openSocketChannel();
 385     }
 386 
 387     /**
 388      * Opens a RDMA server-socket channel.
 389      *
 390      * <p> The new channel is created by invoking the {@link
 391      * java.nio.channels.spi.SelectorProvider#openServerSocketChannel
 392      * openServerSocketChannel} method of the system-wide default {@link
 393      * java.nio.channels.spi.SelectorProvider} object.
 394      *
 395      * <p> The new channel's socket is initially unbound; it must be bound to a
 396      * specific address via one of its socket's {@link
 397      * java.net.ServerSocket#bind(SocketAddress) bind} methods before
 398      * connections can be accepted.  </p>
 399      *
 400      * @return  A new RDMA server socket channel
 401      *
 402      * @throws  IOException
 403      *          If an I/O error occurs
 404      */
 405     public static ServerSocketChannel openRdmaServerSocketChannel()
 406         throws IOException {
 407         return RdmaPollSelectorProvider.provider().openServerSocketChannel();
 408     }
 409 
 410     /**
 411      * Opens a RDMA selector.
 412      *
 413      * @return  A new RDMA selector
 414      *
 415      * @throws  IOException
 416      *          If an I/O error occurs
 417      */
 418     public static Selector openRdmaSelector() throws IOException {
 419         return RdmaPollSelectorProvider.provider().openSelector();
 420     }
 421 }
< prev index next >