src/jdk.net/linux/native/libextnet/LinuxSocketOptions.c
author sveerabhadra
Thu, 31 May 2018 16:50:10 +0530
changeset 50356 27d982661042
parent 47733 fbfe06b70e16
child 50303 7164c3bb55df
child 56454 82c3ae69914f
permissions -rw-r--r--
8199723: Test java/awt/TextComponent/DeselectionDuringDoSelectionNonVisibleTest/DeselectionDuringDoSelectionNonVisibleTest.java fails Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47733
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
     1
/*
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
     4
 *
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    10
 *
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    15
 * accompanied this code).
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    16
 *
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    20
 *
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    23
 * questions.
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    24
 */
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    25
#include <sys/socket.h>
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    26
#include <string.h>
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    27
#include <errno.h>
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    28
#include <unistd.h>
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    29
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    30
#include <jni.h>
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    31
#include <netinet/tcp.h>
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    32
#include "jni_util.h"
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    33
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    34
/*
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    35
 * Class:     jdk_net_LinuxSocketOptions
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    36
 * Method:    setQuickAck
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    37
 * Signature: (II)V
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    38
 */
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    39
JNIEXPORT void JNICALL Java_jdk_net_LinuxSocketOptions_setQuickAck0
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    40
(JNIEnv *env, jobject unused, jint fd, jboolean on) {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    41
    int optval;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    42
    int rv;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    43
    optval = (on ? 1 : 0);
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    44
    rv = setsockopt(fd, SOL_SOCKET, TCP_QUICKACK, &optval, sizeof (optval));
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    45
    if (rv < 0) {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    46
        if (errno == ENOPROTOOPT) {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    47
            JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    48
                            "unsupported socket option");
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    49
        } else {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    50
            JNU_ThrowByNameWithLastError(env, "java/net/SocketException",
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    51
                                        "set option TCP_QUICKACK failed");
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    52
        }
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    53
    }
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    54
}
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    55
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    56
/*
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    57
 * Class:     jdk_net_LinuxSocketOptions
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    58
 * Method:    getQuickAck
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    59
 * Signature: (I)Z;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    60
 */
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    61
JNIEXPORT jboolean JNICALL Java_jdk_net_LinuxSocketOptions_getQuickAck0
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    62
(JNIEnv *env, jobject unused, jint fd) {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    63
    int on;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    64
    socklen_t sz = sizeof (on);
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    65
    int rv = getsockopt(fd, SOL_SOCKET, TCP_QUICKACK, &on, &sz);
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    66
    if (rv < 0) {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    67
        if (errno == ENOPROTOOPT) {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    68
            JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    69
                            "unsupported socket option");
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    70
        } else {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    71
            JNU_ThrowByNameWithLastError(env, "java/net/SocketException",
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    72
                                        "get option TCP_QUICKACK failed");
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    73
        }
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    74
    }
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    75
    return on != 0;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    76
}
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    77
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    78
/*
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    79
 * Class:     jdk_net_LinuxSocketOptions
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    80
 * Method:    quickAckSupported
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    81
 * Signature: ()Z
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    82
 */
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    83
JNIEXPORT jboolean JNICALL Java_jdk_net_LinuxSocketOptions_quickAckSupported0
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    84
(JNIEnv *env, jobject unused) {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    85
    int one = 1;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    86
    int rv, s;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    87
    s = socket(PF_INET, SOCK_STREAM, 0);
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    88
    if (s < 0) {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    89
        return JNI_FALSE;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    90
    }
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    91
    rv = setsockopt(s, SOL_SOCKET, TCP_QUICKACK, (void *) &one, sizeof (one));
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    92
    if (rv != 0 && errno == ENOPROTOOPT) {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    93
        rv = JNI_FALSE;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    94
    } else {
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    95
        rv = JNI_TRUE;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    96
    }
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    97
    close(s);
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    98
    return rv;
fbfe06b70e16 8145635: Add TCP_QUICKACK socket option
vtewari
parents:
diff changeset
    99
}