src/java.base/windows/classes/java/net/DualStackPlainDatagramSocketImpl.java
author michaelm
Thu, 13 Jun 2019 09:10:51 +0100
changeset 55375 96c7427456f9
parent 52427 3c6aa484536c
child 59200 a686b67a59d9
permissions -rw-r--r--
8216417: cleanup of IPv6 scope-id handling Reviewed-by: alanb, chegar, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49892
8bed781a8d9c 8202154: Remove unused code in java.base/windows/native/libnet
igerasim
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.IOException;
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 49892
diff changeset
    28
import jdk.internal.access.SharedSecrets;
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 49892
diff changeset
    29
import jdk.internal.access.JavaIOFileDescriptorAccess;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This class defines the plain DatagramSocketImpl that is used on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Windows platforms greater than or equal to Windows Vista. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * platforms have a dual layer TCP/IP stack and can handle both IPv4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * and IPV6 through a single file descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Note: Multicasting on a dual layer TCP/IP stack is always done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * TwoStacksPlainDatagramSocketImpl. This is to overcome the lack
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * of behavior defined for multicasting over a dual layer socket by the RFC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Chris Hegarty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class DualStackPlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static JavaIOFileDescriptorAccess fdAccess = SharedSecrets.getJavaIOFileDescriptorAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
23023
c1aebf9d16a9 8035653: InetAddress.getLocalHost crash
michaelm
parents: 23010
diff changeset
    48
    static {
c1aebf9d16a9 8035653: InetAddress.getLocalHost crash
michaelm
parents: 23010
diff changeset
    49
        initIDs();
c1aebf9d16a9 8035653: InetAddress.getLocalHost crash
michaelm
parents: 23010
diff changeset
    50
    }
c1aebf9d16a9 8035653: InetAddress.getLocalHost crash
michaelm
parents: 23010
diff changeset
    51
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    52
    // true if this socket is exclusively bound
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    53
    private final boolean exclusiveBind;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    54
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    55
    /*
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    56
     * Set to true if SO_REUSEADDR is set after the socket is bound to
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    57
     * indicate SO_REUSEADDR is being emulated
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    58
     */
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    59
    private boolean reuseAddressEmulated;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    60
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    61
    // emulates SO_REUSEADDR when exclusiveBind is true and socket is bound
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    62
    private boolean isReuseAddress;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    63
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    64
    DualStackPlainDatagramSocketImpl(boolean exclBind) {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    65
        exclusiveBind = exclBind;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    66
    }
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    67
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected void datagramSocketCreate() throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (fd == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            throw new SocketException("Socket closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
49892
8bed781a8d9c 8202154: Remove unused code in java.base/windows/native/libnet
igerasim
parents: 47216
diff changeset
    72
        int newfd = socketCreate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        fdAccess.set(fd, newfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected synchronized void bind0(int lport, InetAddress laddr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (laddr == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throw new NullPointerException("argument address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    84
        socketBind(nativefd, laddr, lport, exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (lport == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            localPort = socketLocalPort(nativefd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            localPort = lport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected synchronized int peek(InetAddress address) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (address == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            throw new NullPointerException("Null address in peek()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        // Use peekData()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        DatagramPacket peekPacket = new DatagramPacket(new byte[1], 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        int peekPort = peekData(peekPacket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        address = peekPacket.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return peekPort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    protected synchronized int peekData(DatagramPacket p) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            throw new NullPointerException("packet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (p.getData() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            throw new NullPointerException("packet buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return socketReceiveOrPeekData(nativefd, p, timeout, connected, true /*peek*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected synchronized void receive0(DatagramPacket p) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new NullPointerException("packet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (p.getData() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw new NullPointerException("packet buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        socketReceiveOrPeekData(nativefd, p, timeout, connected, false /*receive*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
55375
96c7427456f9 8216417: cleanup of IPv6 scope-id handling
michaelm
parents: 52427
diff changeset
   127
    protected void send0(DatagramPacket p) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            throw new NullPointerException("null packet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (p.getAddress() == null ||p.getData() ==null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            throw new NullPointerException("null address || null buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        socketSend(nativefd, p.getData(), p.getOffset(), p.getLength(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                   p.getAddress(), p.getPort(), connected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected void connect0(InetAddress address, int port) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (address == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            throw new NullPointerException("address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        socketConnect(nativefd, address, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    protected void disconnect0(int family /*unused*/) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (fd == null || !fd.valid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return;   // disconnect doesn't throw any exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        socketDisconnect(fdAccess.get(fd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    protected void datagramSocketClose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (fd == null || !fd.valid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            return;   // close doesn't throw any exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        socketClose(fdAccess.get(fd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        fdAccess.set(fd, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   164
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    protected void socketSetOption(int opt, Object val) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        int optionValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 32834
diff changeset
   170
        // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 32834
diff changeset
   171
        if (opt == SO_REUSEPORT) {
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 32834
diff changeset
   172
            throw new UnsupportedOperationException("unsupported option");
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 32834
diff changeset
   173
        }
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 32834
diff changeset
   174
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        switch(opt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            case IP_TOS :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            case SO_RCVBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            case SO_SNDBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                optionValue = ((Integer)val).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            case SO_REUSEADDR :
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   182
                if (exclusiveBind && localPort != 0)  {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   183
                    // socket already bound, emulate SO_REUSEADDR
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   184
                    reuseAddressEmulated = true;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   185
                    isReuseAddress = (Boolean)val;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   186
                    return;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   187
                }
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   188
                //Intentional fallthrough
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            case SO_BROADCAST :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                optionValue = ((Boolean)val).booleanValue() ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            default: /* shouldn't get here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                throw new SocketException("Option not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        socketSetIntOption(nativefd, opt, optionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    protected Object socketGetOption(int opt) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         // SO_BINDADDR is not a socket option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (opt == SO_BINDADDR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return socketLocalAddress(nativefd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   206
        if (opt == SO_REUSEADDR && reuseAddressEmulated)
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   207
            return isReuseAddress;
36115
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 32834
diff changeset
   208
        // SO_REUSEPORT is not supported on Windows.
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 32834
diff changeset
   209
        if (opt == SO_REUSEPORT)
0676e37a0b9c 6432031: Add support for SO_REUSEPORT
alanb
parents: 32834
diff changeset
   210
            throw new UnsupportedOperationException("unsupported option");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        int value = socketGetIntOption(nativefd, opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        Object returnValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        switch (opt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            case SO_REUSEADDR :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            case SO_BROADCAST :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                returnValue =  (value == 0) ? Boolean.FALSE : Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            case IP_TOS :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            case SO_RCVBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            case SO_SNDBUF :
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 36115
diff changeset
   223
                returnValue = Integer.valueOf(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            default: /* shouldn't get here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                throw new SocketException("Option not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /* Multicast specific methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Multicasting on a dual layer TCP/IP stack is always done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * TwoStacksPlainDatagramSocketImpl. This is to overcome the lack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * of behavior defined for multicasting over a dual layer socket by the RFC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    protected void join(InetAddress inetaddr, NetworkInterface netIf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    protected void leave(InetAddress inetaddr, NetworkInterface netIf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    protected void setTimeToLive(int ttl) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    protected int getTimeToLive() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   255
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    protected void setTTL(byte ttl) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   260
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    protected byte getTTL() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /* END Multicast specific methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    private int checkAndReturnNativeFD() throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (fd == null || !fd.valid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            throw new SocketException("Socket closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return fdAccess.get(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /* Native methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
49892
8bed781a8d9c 8202154: Remove unused code in java.base/windows/native/libnet
igerasim
parents: 47216
diff changeset
   277
    private static native int socketCreate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   279
    private static native void socketBind(int fd, InetAddress localAddress,
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   280
            int localport, boolean exclBind) throws SocketException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private static native void socketConnect(int fd, InetAddress address, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private static native void socketDisconnect(int fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    private static native void socketClose(int fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    private static native int socketLocalPort(int fd) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    private static native Object socketLocalAddress(int fd) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    private static native int socketReceiveOrPeekData(int fd, DatagramPacket packet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        int timeout, boolean connected, boolean peek) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    private static native void socketSend(int fd, byte[] data, int offset, int length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        InetAddress address, int port, boolean connected) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    private static native void socketSetIntOption(int fd, int cmd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        int optionValue) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    private static native int socketGetIntOption(int fd, int cmd) throws SocketException;
32503
1478c9130534 8072466: Deadlock when initializing MulticastSocket and DatagramSocket
igerasim
parents: 25859
diff changeset
   303
1478c9130534 8072466: Deadlock when initializing MulticastSocket and DatagramSocket
igerasim
parents: 25859
diff changeset
   304
    native int dataAvailable();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}