src/jdk.net/linux/classes/jdk/internal/net/rdma/RdmaSocketOptionRegistry.java.template
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
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     5
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     8
 * published by the Free Software Foundation.  Oracle designates this
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
     9
 * particular file as subject to the "Classpath" exception as provided
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    10
 * by Oracle in the LICENSE file that accompanied this code.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    11
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    12
 * 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
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    15
 * 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
    16
 * accompanied this code).
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    17
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License version
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    19
 * 2 along with this work; if not, write to the Free Software Foundation,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    20
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    21
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    22
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    23
 * or visit www.oracle.com if you need additional information or have any
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    24
 * questions.
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    25
 *
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    26
 */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    27
@@END_COPYRIGHT@@
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    28
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    29
#include <stdio.h>
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    30
#include <sys/types.h>
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    31
#include <sys/socket.h>
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    32
#include <netinet/in.h>
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    33
#include <netinet/tcp.h>
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    34
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    35
/* To be able to name the Java constants the same as the C constants without
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    36
   having the preprocessor rewrite those identifiers, add PREFIX_ to all
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    37
   identifiers matching a C constant. The PREFIX_ is filtered out in the
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    38
   makefile. */
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    39
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    40
@@START_HERE@@
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    41
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    42
package jdk.internal.net.rdma;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    43
import java.net.SocketOption;
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.ProtocolFamily;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    46
import java.util.Map;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    47
import java.util.HashMap;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    48
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    49
class RdmaSocketOptionRegistry {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    50
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    51
    private RdmaSocketOptionRegistry() { }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    52
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    53
    private static class RegistryKey {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    54
        private final SocketOption<?> name;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    55
        private final ProtocolFamily family;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    56
        RegistryKey(SocketOption<?> name, ProtocolFamily family) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    57
            this.name = name;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    58
            this.family = family;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    59
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    60
        public int hashCode() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    61
            return name.hashCode() + family.hashCode();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    62
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    63
        public boolean equals(Object ob) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    64
            if (ob == null) return false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    65
            if (!(ob instanceof RegistryKey)) return false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    66
            RegistryKey other = (RegistryKey)ob;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    67
            if (this.name != other.name) return false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    68
            if (this.family != other.family) return false;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    69
            return true;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    70
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    71
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    72
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    73
    private static class LazyInitialization {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    74
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    75
        static final Map<RegistryKey,RdmaOptionKey> options = options();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    76
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    77
        private static Map<RegistryKey,RdmaOptionKey> options() {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    78
            Map<RegistryKey,RdmaOptionKey> map =
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    79
                new HashMap<RegistryKey,RdmaOptionKey>();
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    80
            map.put(new RegistryKey(StandardSocketOptions.PREFIX_SO_SNDBUF,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    81
                RdmaNet.UNSPEC), new RdmaOptionKey(SOL_SOCKET, SO_SNDBUF));
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    82
            map.put(new RegistryKey(StandardSocketOptions.PREFIX_SO_RCVBUF,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    83
                RdmaNet.UNSPEC), new RdmaOptionKey(SOL_SOCKET, SO_RCVBUF));
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    84
            map.put(new RegistryKey(StandardSocketOptions.PREFIX_SO_REUSEADDR,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    85
                RdmaNet.UNSPEC), new RdmaOptionKey(SOL_SOCKET, SO_REUSEADDR));
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    86
            // IPPROTO_TCP is 6
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    87
            map.put(new RegistryKey(StandardSocketOptions.PREFIX_TCP_NODELAY,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    88
                RdmaNet.UNSPEC), new RdmaOptionKey(6, TCP_NODELAY));
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    89
            return map;
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    90
        }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    91
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    92
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    93
    public static RdmaOptionKey findOption(SocketOption<?> name,
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    94
                                           ProtocolFamily family) {
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    95
        RegistryKey key = new RegistryKey(name, family);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    96
        return LazyInitialization.options.get(key);
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    97
    }
512e7cc6ccce Initial load of JEP 337 implementation
alanb
parents:
diff changeset
    98
}