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.net.SocketException;
  29 import java.net.InetAddress;
  30 import java.net.SocketImpl;
  31 import sun.net.ext.RdmaSocketOptions;
  32 import rdma.ch.RdmaSocketImpl.PlatformRdmaSocketImpl;
  33 
  34 class LinuxRdmaSocketImpl extends PlatformRdmaSocketImpl
  35 {
  36     static {
  37         java.security.AccessController.doPrivileged(
  38             new java.security.PrivilegedAction<>() {
  39                 public Void run() {
  40                     System.loadLibrary("net");
  41                     System.loadLibrary("extnet");
  42                     return null;
  43                 }
  44             });
  45         initProto();
  46     }
  47 
  48     public LinuxRdmaSocketImpl() { }
  49 
  50     static final RdmaSocketOptions rdmaOptions =
  51             RdmaSocketOptions.getInstance();
  52 
  53     private static volatile boolean checkedRdma;
  54     private static volatile boolean isRdmaAvailable;
  55 
  56     boolean isRdmaAvailable() {
  57         if (!checkedRdma) {
  58             isRdmaAvailable = isRdmaAvailable0();
  59             checkedRdma = true;
  60         }
  61         return isRdmaAvailable;
  62     }
  63 
  64     static native void initProto();
  65 
  66     private static native boolean isRdmaAvailable0();
  67 
  68     native void rdmaSocketCreate(boolean isServer, RdmaSocketImpl impl) throws IOException;
  69 
  70     native void rdmaSocketConnect(RdmaSocketImpl impl, InetAddress address, int port, int timeout)
  71         throws IOException;
  72 
  73     native void rdmaSocketBind(RdmaSocketImpl impl, InetAddress address, int port)
  74         throws IOException;
  75 
  76     native void rdmaSocketListen(RdmaSocketImpl impl, int count) throws IOException;
  77 
  78     native void rdmaSocketAccept(SocketImpl impl, RdmaSocketImpl s) throws IOException;
  79 
  80     native int rdmaSocketAvailable(RdmaSocketImpl impl) throws IOException;
  81 
  82     native void rdmaSocketClose(boolean useDeferredClose, RdmaSocketImpl impl) throws IOException;
  83 
  84     native void rdmaSocketShutdown(int howto, RdmaSocketImpl impl) throws IOException;
  85 
  86     native void rdmaSocketSetOption(RdmaSocketImpl impl, int cmd, boolean on, Object value)
  87         throws SocketException;
  88 
  89     native int rdmaSocketGetOption(RdmaSocketImpl impl, int opt, Object iaContainerObj) throws SocketException;
  90 
  91     native void rdmaSocketSendUrgentData(RdmaSocketImpl impl, int data) throws IOException;
  92 }