src/jdk.net/linux/classes/jdk/internal/net/rdma/RdmaSocketImpl.java
author bpb
Wed, 06 Feb 2019 12:48:01 -0800
branchrsocket-branch
changeset 57156 81e4a12fd1a4
parent 57115 512e7cc6ccce
child 57160 c502c299d41e
permissions -rw-r--r--
rsocket-branch: change recent copyright year to 2019 and new files to 2019 only
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     1
/*
57156
81e4a12fd1a4 rsocket-branch: change recent copyright year to 2019 and new files to 2019 only
bpb
parents: 57115
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
57115
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     4
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    10
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    16
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    20
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    23
 * questions.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    24
 */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    25
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    26
package jdk.internal.net.rdma;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    27
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    28
import java.io.FileDescriptor;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    29
import java.io.IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    30
import java.io.InputStream;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    31
import java.io.OutputStream;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    32
import java.net.Inet4Address;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    33
import java.net.Inet6Address;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    34
import java.net.InetAddress;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    35
import java.net.InetSocketAddress;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    36
import java.net.ProtocolFamily;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    37
import java.net.ServerSocket;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    38
import java.net.Socket;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    39
import java.net.SocketAddress;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    40
import java.net.SocketException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    41
import java.net.SocketImpl;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    42
import java.net.SocketOption;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    43
import java.net.SocketOptions;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    44
import java.net.StandardSocketOptions;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    45
import java.net.UnknownHostException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    46
import java.util.Objects;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    47
import java.util.Set;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    48
import sun.nio.ch.Net;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    49
import static java.net.StandardProtocolFamily.INET;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    50
import static java.net.StandardProtocolFamily.INET6;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    51
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    52
public abstract class RdmaSocketImpl extends SocketImpl
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    53
{
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    54
    private ProtocolFamily family;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    55
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    56
    Socket socket = null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    57
    ServerSocket serverSocket = null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    58
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    59
    int timeout;   // timeout in millisec
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    60
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    61
    int trafficClass;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    62
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    63
    InputStream socketInputStream;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    64
    OutputStream socketOutputStream;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    65
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    66
    private boolean shut_rd = false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    67
    private boolean shut_wr = false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    68
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    69
    /* number of threads using the FileDescriptor */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    70
    protected int fdUseCount = 0;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    71
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    72
    /* lock when increment/decrementing fdUseCount */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    73
    protected final Object fdLock = new Object();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    74
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    75
    /* indicates a close is pending on the file descriptor */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    76
    protected boolean closePending = false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    77
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    78
    /* indicates connection reset state */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    79
    private int CONNECTION_NOT_RESET = 0;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    80
    private int CONNECTION_RESET_PENDING = 1;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    81
    private int CONNECTION_RESET = 2;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    82
    private int resetState;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    83
    private final Object resetLock = new Object();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    84
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    85
    protected boolean stream;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    86
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    87
    private static UnsupportedOperationException unsupported;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    88
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    89
    static final sun.net.ext.RdmaSocketOptions rdmaOptions =
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    90
            sun.net.ext.RdmaSocketOptions.getInstance();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    91
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    92
    static {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    93
        java.security.AccessController.doPrivileged(
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    94
            new java.security.PrivilegedAction<>() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    95
                public Void run() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    96
                    System.loadLibrary("net");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    97
                    System.loadLibrary("extnet");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    98
                    return null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    99
                }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   100
            });
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   101
        UnsupportedOperationException uoe = null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   102
        try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   103
            initProto();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   104
        } catch (UnsupportedOperationException e) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   105
            uoe = e;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   106
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   107
        unsupported = uoe;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   108
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   109
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   110
    private static final Void checkSupported() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   111
        if (unsupported != null) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   112
            Exception e = unsupported;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   113
            throw new UnsupportedOperationException(e.getMessage(), e);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   114
        } else {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   115
            return null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   116
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   117
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   118
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   119
    public RdmaSocketImpl(ProtocolFamily family) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   120
        this(checkSupported(), family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   121
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   122
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   123
    private RdmaSocketImpl(Void unused, ProtocolFamily family) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   124
        Objects.requireNonNull(family, "null family");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   125
        if (!(family == INET || family == INET6)) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   126
            throw new UnsupportedOperationException("Protocol family not supported");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   127
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   128
        if (family == INET6) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   129
            if (!Net.isIPv6Available()) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   130
                throw new UnsupportedOperationException(
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   131
                        "IPv6 not available");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   132
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   133
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   134
        this.family = family;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   135
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   136
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   137
    private static volatile boolean checkedRdma;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   138
    private static volatile boolean isRdmaAvailable;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   139
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   140
    boolean isRdmaAvailable() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   141
        if (!checkedRdma) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   142
            isRdmaAvailable = isRdmaAvailable0();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   143
            checkedRdma = true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   144
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   145
        return isRdmaAvailable;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   146
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   147
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   148
    void setSocket(Socket soc) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   149
        this.socket = soc;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   150
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   151
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   152
    Socket getSocket() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   153
        return socket;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   154
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   155
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   156
    void setServerSocket(ServerSocket soc) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   157
        this.serverSocket = soc;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   158
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   159
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   160
    ServerSocket getServerSocket() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   161
        return serverSocket;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   162
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   163
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   164
    @Override
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   165
    protected abstract Set<SocketOption<?>> supportedOptions();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   166
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   167
    protected synchronized void create(boolean stream) throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   168
        this.stream = stream;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   169
        if (stream) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   170
            fd = new FileDescriptor();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   171
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   172
            boolean preferIPv6 = Net.isIPv6Available() && (family != INET);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   173
            rdmaSocketCreate(preferIPv6, true);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   174
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   175
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   176
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   177
    protected void connect(String host, int port)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   178
            throws UnknownHostException, IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   179
        boolean connected = false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   180
        try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   181
            InetAddress address = InetAddress.getByName(host);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   182
            this.port = port;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   183
            this.address = address;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   184
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   185
            connectToAddress(address, port, timeout);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   186
            connected = true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   187
        } finally {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   188
            if (!connected) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   189
                try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   190
                    close();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   191
                } catch (IOException ioe) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   192
                }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   193
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   194
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   195
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   196
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   197
    protected void connect(InetAddress address, int port) throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   198
        if (family == INET && !(address instanceof Inet4Address))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   199
                throw new IllegalArgumentException("address type mismatch");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   200
        if (family == INET6 && !(address instanceof Inet6Address))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   201
                throw new IllegalArgumentException("address type mismatch");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   202
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   203
        this.port = port;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   204
        this.address = address;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   205
        try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   206
            connectToAddress(address, port, timeout);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   207
            return;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   208
        } catch (IOException e) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   209
            close();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   210
            throw e;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   211
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   212
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   213
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   214
    protected void connect(SocketAddress address, int timeout)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   215
            throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   216
        boolean connected = false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   217
        try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   218
            if (address == null || !(address instanceof InetSocketAddress))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   219
                throw new IllegalArgumentException("unsupported address type");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   220
            InetSocketAddress addr = (InetSocketAddress) address;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   221
            InetAddress ia = addr.getAddress();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   222
            if (family == INET && !(ia instanceof Inet4Address))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   223
                throw new IllegalArgumentException("address type mismatch");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   224
            if (family == INET6 && !(ia instanceof Inet6Address))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   225
                throw new IllegalArgumentException("address type mismatch");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   226
            if (addr.isUnresolved())
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   227
                throw new UnknownHostException(addr.getHostName());
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   228
            this.port = addr.getPort();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   229
            this.address = addr.getAddress();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   230
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   231
            connectToAddress(this.address, port, timeout);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   232
            connected = true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   233
        } finally {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   234
            if (!connected) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   235
                try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   236
                    close();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   237
                } catch (IOException ioe) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   238
                }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   239
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   240
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   241
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   242
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   243
    private void connectToAddress(InetAddress address, int port, int timeout)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   244
            throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   245
        if (address.isAnyLocalAddress()) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   246
            doConnect(InetAddress.getLocalHost(), port, timeout);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   247
        } else {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   248
            doConnect(address, port, timeout);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   249
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   250
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   251
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   252
    @Override
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   253
    protected abstract <T> void setOption(SocketOption<T> name, T value)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   254
            throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   255
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   256
    @SuppressWarnings("unchecked")
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   257
    @Override
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   258
    protected abstract <T> T getOption(SocketOption<T> name)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   259
            throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   260
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   261
    public void setOption(int opt, Object val) throws SocketException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   262
        if (isClosedOrPending()) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   263
            throw new SocketException("Socket Closed");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   264
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   265
        boolean on = true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   266
        switch (opt) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   267
        case SO_TIMEOUT:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   268
            if (val == null || (!(val instanceof Integer)))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   269
                throw new SocketException("Bad parameter for SO_TIMEOUT");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   270
            int tmp = ((Integer) val).intValue();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   271
            if (tmp < 0)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   272
                throw new IllegalArgumentException("timeout < 0");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   273
            timeout = tmp;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   274
            break;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   275
        case SO_BINDADDR:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   276
            throw new SocketException("Cannot re-bind socket");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   277
        case TCP_NODELAY:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   278
            if (val == null || !(val instanceof Boolean))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   279
                throw new SocketException("bad parameter for TCP_NODELAY");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   280
            on = ((Boolean)val).booleanValue();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   281
            break;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   282
        case SO_SNDBUF:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   283
        case SO_RCVBUF:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   284
            int value = ((Integer)val).intValue();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   285
            int maxValue = 1024 * 1024 * 1024 - 1;   //maximum value for the buffer
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   286
            if (val == null || !(val instanceof Integer) ||
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   287
                !(value > 0)) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   288
                throw new SocketException("bad parameter for SO_SNDBUF " +
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   289
                                          "or SO_RCVBUF");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   290
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   291
            if (value >= maxValue)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   292
                value = maxValue;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   293
            break;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   294
        case SO_REUSEADDR:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   295
            if (val == null || !(val instanceof Boolean))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   296
                throw new SocketException("bad parameter for SO_REUSEADDR");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   297
            on = ((Boolean)val).booleanValue();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   298
            if (serverSocket != null && serverSocket.isBound())
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   299
                    throw new UnsupportedOperationException(
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   300
                            "RDMA server socket cannot set " +
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   301
                            "SO_REUSEADDR after bind.");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   302
            if (socket != null && socket.isConnected())
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   303
                    throw new UnsupportedOperationException(
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   304
                            "RDMA socket cannot set " +
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   305
                            "SO_REUSEADDR after connect.");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   306
            break;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   307
        default:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   308
            throw new SocketException("unrecognized TCP option: " + opt);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   309
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   310
        socketSetOption(opt, on, val);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   311
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   312
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   313
    public Object getOption(int opt) throws SocketException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   314
        if (isClosedOrPending()) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   315
            throw new SocketException("Socket Closed");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   316
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   317
        if (opt == SO_TIMEOUT) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   318
            return timeout;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   319
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   320
        int ret = 0;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   321
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   322
        switch (opt) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   323
        case TCP_NODELAY:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   324
            ret = rdmaSocketGetOption(opt, null);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   325
            return Boolean.valueOf(ret != -1);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   326
        case SO_REUSEADDR:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   327
            ret = rdmaSocketGetOption(opt, null);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   328
            return Boolean.valueOf(ret != -1);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   329
        case SO_BINDADDR:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   330
            RdmaInetAddressContainer in = new RdmaInetAddressContainer();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   331
            ret = rdmaSocketGetOption(opt, in);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   332
            return in.addr;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   333
        case SO_SNDBUF:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   334
        case SO_RCVBUF:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   335
            ret = rdmaSocketGetOption(opt, null);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   336
            return ret;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   337
        default:
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   338
            return null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   339
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   340
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   341
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   342
    protected void socketSetOption(int opt, boolean b, Object val)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   343
            throws SocketException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   344
        if (opt == SocketOptions.SO_REUSEPORT &&
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   345
            !supportedOptions().contains(StandardSocketOptions.SO_REUSEPORT)) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   346
            throw new UnsupportedOperationException("unsupported option");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   347
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   348
        try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   349
            rdmaSocketSetOption(opt, b, val);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   350
        } catch (SocketException se) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   351
            if (socket == null || !socket.isConnected())
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   352
                throw se;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   353
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   354
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   355
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   356
    synchronized void doConnect(InetAddress address, int port, int timeout)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   357
            throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   358
        try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   359
            acquireFD();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   360
            boolean preferIPv6 = Net.isIPv6Available() && (family != INET);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   361
            try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   362
                rdmaSocketConnect(preferIPv6, address, port, timeout);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   363
                synchronized (fdLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   364
                    if (closePending) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   365
                        throw new SocketException ("Socket closed");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   366
                    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   367
                }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   368
            } finally {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   369
                releaseFD();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   370
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   371
        } catch (IOException e) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   372
            close();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   373
            throw e;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   374
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   375
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   376
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   377
    private final InetAddress anyLocalAddress() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   378
        if (family == INET)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   379
            return InetAddress.getByName("0.0.0.0");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   380
        else if (family == INET6)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   381
            return InetAddress.getByName("::");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   382
        else
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   383
            throw new IllegalArgumentException("Unsupported address type " + family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   384
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   385
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   386
    protected synchronized void bind(InetAddress address, int lport)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   387
            throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   388
        if (address == null)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   389
            throw new IllegalArgumentException("address is null");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   390
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   391
        if (address.isAnyLocalAddress())
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   392
            address = anyLocalAddress();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   393
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   394
        if (family == INET && !(address instanceof Inet4Address))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   395
            throw new IllegalArgumentException("address type mismatch");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   396
        if (family == INET6 && !(address instanceof Inet6Address))
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   397
            throw new IllegalArgumentException("address type mismatch");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   398
        boolean preferIPv6 = Net.isIPv6Available() && (family != INET);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   399
        rdmaSocketBind(preferIPv6, address, lport);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   400
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   401
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   402
    protected synchronized void listen(int count) throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   403
        rdmaSocketListen(count);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   404
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   405
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   406
    protected void accept(SocketImpl s) throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   407
        acquireFD();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   408
        try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   409
            rdmaSocketAccept(s);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   410
        } finally {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   411
            releaseFD();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   412
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   413
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   414
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   415
    protected synchronized InputStream getInputStream() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   416
        synchronized (fdLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   417
            if (isClosedOrPending())
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   418
                throw new IOException("Socket Closed");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   419
            if (shut_rd)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   420
                throw new IOException("Socket input is shutdown");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   421
            if (socketInputStream == null)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   422
                socketInputStream = new RdmaSocketInputStream(this);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   423
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   424
        return socketInputStream;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   425
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   426
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   427
    protected synchronized OutputStream getOutputStream() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   428
        synchronized (fdLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   429
            if (isClosedOrPending())
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   430
                throw new IOException("Socket Closed");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   431
            if (shut_wr)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   432
                throw new IOException("Socket output is shutdown");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   433
            if (socketOutputStream == null)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   434
                socketOutputStream = new RdmaSocketOutputStream(this);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   435
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   436
        return socketOutputStream;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   437
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   438
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   439
    protected FileDescriptor getFileDescriptor() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   440
        return fd;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   441
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   442
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   443
    protected void setFileDescriptor(FileDescriptor fd) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   444
        this.fd = fd;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   445
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   446
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   447
    protected void setAddress(InetAddress address) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   448
        this.address = address;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   449
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   450
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   451
    void setPort(int port) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   452
        this.port = port;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   453
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   454
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   455
    void setLocalPort(int localport) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   456
        this.localport = localport;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   457
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   458
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   459
    protected synchronized int available() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   460
        throw new UnsupportedOperationException(
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   461
                "unsupported socket operation");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   462
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   463
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   464
    protected void close() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   465
        synchronized(fdLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   466
            if (fd != null) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   467
                if (fdUseCount == 0) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   468
                    if (closePending) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   469
                        return;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   470
                    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   471
                    closePending = true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   472
                    rdmaSocketClose();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   473
                    fd = null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   474
                    return;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   475
                } else {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   476
                    if (!closePending) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   477
                        closePending = true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   478
                        fdUseCount--;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   479
                        rdmaSocketClose();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   480
                    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   481
                }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   482
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   483
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   484
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   485
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   486
    void reset() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   487
        if (fd != null) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   488
            rdmaSocketClose();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   489
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   490
        fd = null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   491
        postReset();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   492
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   493
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   494
    void postReset() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   495
        address = null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   496
        port = 0;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   497
        localport = 0;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   498
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   499
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   500
    protected void shutdownInput() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   501
        if (fd != null) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   502
            rdmaSocketShutdown(SHUT_RD);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   503
            if (socketInputStream != null) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   504
                ((RdmaSocketInputStream)socketInputStream).setEOF(true);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   505
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   506
            shut_rd = true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   507
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   508
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   509
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   510
    protected void shutdownOutput() throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   511
        if (fd != null) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   512
            rdmaSocketShutdown(SHUT_WR);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   513
            shut_wr = true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   514
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   515
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   516
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   517
    protected boolean supportsUrgentData () {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   518
        return true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   519
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   520
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   521
    protected void sendUrgentData (int data) throws IOException {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   522
        if (fd == null) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   523
            throw new IOException("Socket Closed");
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   524
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   525
        rdmaSocketSendUrgentData(data);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   526
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   527
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   528
    FileDescriptor acquireFD() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   529
        synchronized (fdLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   530
            fdUseCount++;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   531
            return fd;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   532
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   533
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   534
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   535
    void releaseFD() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   536
        synchronized (fdLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   537
            fdUseCount--;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   538
            if (fdUseCount == -1) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   539
                if (fd != null) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   540
                    try {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   541
                        rdmaSocketClose();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   542
                    } catch (IOException e) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   543
                    } finally {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   544
                        fd = null;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   545
                    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   546
                }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   547
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   548
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   549
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   550
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   551
    public boolean isConnectionReset() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   552
        synchronized (resetLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   553
            return (resetState == CONNECTION_RESET);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   554
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   555
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   556
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   557
    public boolean isConnectionResetPending() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   558
        synchronized (resetLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   559
            return (resetState == CONNECTION_RESET_PENDING);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   560
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   561
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   562
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   563
    public void setConnectionReset() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   564
        synchronized (resetLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   565
            resetState = CONNECTION_RESET;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   566
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   567
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   568
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   569
    public void setConnectionResetPending() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   570
        synchronized (resetLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   571
            if (resetState == CONNECTION_NOT_RESET) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   572
                resetState = CONNECTION_RESET_PENDING;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   573
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   574
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   575
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   576
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   577
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   578
    public boolean isClosedOrPending() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   579
        synchronized (fdLock) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   580
            if (closePending || (fd == null)) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   581
                return true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   582
            } else {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   583
                return false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   584
            }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   585
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   586
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   587
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   588
    public int getTimeout() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   589
        return timeout;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   590
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   591
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   592
    protected InetAddress getInetAddress() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   593
        return address;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   594
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   595
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   596
    protected int getPort() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   597
        return port;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   598
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   599
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   600
    protected int getLocalPort() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   601
        return localport;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   602
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   603
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   604
    public static final int SHUT_RD = 0;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   605
    public static final int SHUT_WR = 1;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   606
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   607
    static native void initProto() throws UnsupportedOperationException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   608
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   609
    private static native boolean isRdmaAvailable0();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   610
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   611
    native void rdmaSocketCreate(boolean preferIPv6, boolean isServer)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   612
            throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   613
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   614
    native void rdmaSocketConnect(boolean preferIPv6, InetAddress address,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   615
            int port, int timeout) throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   616
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   617
    native void rdmaSocketBind(boolean preferIPv6, InetAddress address,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   618
            int port) throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   619
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   620
    native void rdmaSocketListen(int count) throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   621
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   622
    native void rdmaSocketAccept(SocketImpl s) throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   623
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   624
    native void rdmaSocketClose() throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   625
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   626
    native void rdmaSocketShutdown(int howto) throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   627
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   628
    native void rdmaSocketSetOption(int cmd, boolean on, Object value)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   629
            throws SocketException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   630
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   631
    native int rdmaSocketGetOption(int opt, Object iaContainerObj)
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   632
            throws SocketException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   633
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   634
    native void rdmaSocketSendUrgentData(int data) throws IOException;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
   635
}