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