1 /* 2 * Copyright (c) 2007, 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 package rdma.ch; 26 27 import java.io.IOException; 28 import java.io.InputStream; 29 import java.io.OutputStream; 30 import java.net.SocketException; 31 import java.net.InetAddress; 32 import java.net.SocketImpl; 33 import sun.net.ext.RdmaSocketOptions; 34 import rdma.ch.RdmaSocketImpl.PlatformRdmaSocketImpl; 35 36 class LinuxRdmaSocketImpl extends PlatformRdmaSocketImpl 37 { 38 static { 39 java.security.AccessController.doPrivileged( 40 new java.security.PrivilegedAction<>() { 41 public Void run() { 42 System.loadLibrary("net"); 43 System.loadLibrary("extnet"); 44 return null; 45 } 46 }); 47 initProto(); 48 } 49 50 public LinuxRdmaSocketImpl() { } 51 52 static final RdmaSocketOptions rdmaOptions = 53 RdmaSocketOptions.getInstance(); 54 55 private static volatile boolean checkedRdma; 56 private static volatile boolean isRdmaAvailable; 57 58 boolean isRdmaAvailable() { 59 if (!checkedRdma) { 60 isRdmaAvailable = isRdmaAvailable0(); 61 checkedRdma = true; 62 } 63 return isRdmaAvailable; 64 } 65 66 protected synchronized RdmaSocketInputStream getRdmaInputStream( 67 RdmaSocketImpl impl) throws IOException { 68 return new RdmaSocketInputStream(impl); 69 } 70 71 protected synchronized RdmaSocketOutputStream getRdmaOutputStream( 72 RdmaSocketImpl impl) throws IOException { 73 return new RdmaSocketOutputStream(impl); 74 } 75 76 protected void rdmaSocketShutdownInput(int howto, RdmaSocketImpl impl, 77 InputStream socketInputStream) throws IOException { 78 rdmaSocketShutdown(howto, impl); 79 if (socketInputStream != null) { 80 ((RdmaSocketInputStream)socketInputStream).setEOF(true); 81 } 82 } 83 84 static native void initProto(); 85 86 private static native boolean isRdmaAvailable0(); 87 88 native void rdmaSocketCreate(boolean isServer, RdmaSocketImpl impl) throws IOException; 89 90 native void rdmaSocketConnect(RdmaSocketImpl impl, InetAddress address, int port, int timeout) 91 throws IOException; 92 93 native void rdmaSocketBind(RdmaSocketImpl impl, InetAddress address, int port) 94 throws IOException; 95 96 native void rdmaSocketListen(RdmaSocketImpl impl, int count) throws IOException; 97 98 native void rdmaSocketAccept(SocketImpl impl, RdmaSocketImpl s) throws IOException; 99 100 native int rdmaSocketAvailable(RdmaSocketImpl impl) throws IOException; 101 102 native void rdmaSocketClose(boolean useDeferredClose, RdmaSocketImpl impl) throws IOException; 103 104 native void rdmaSocketShutdown(int howto, RdmaSocketImpl impl) throws IOException; 105 106 native void rdmaSocketSetOption(RdmaSocketImpl impl, int cmd, boolean on, Object value) 107 throws SocketException; 108 109 native int rdmaSocketGetOption(RdmaSocketImpl impl, int opt, Object iaContainerObj) throws SocketException; 110 111 native void rdmaSocketSendUrgentData(RdmaSocketImpl impl, int data) throws IOException; 112 }