jdk/src/windows/classes/java/net/DualStackPlainDatagramSocketImpl.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 18192 fa6bd0992104
child 23023 c1aebf9d16a9
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 18192
diff changeset
     2
 * Copyright (c) 2007, 2013, 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.misc.SharedSecrets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.misc.JavaIOFileDescriptorAccess;
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
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    48
    // true if this socket is exclusively bound
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    49
    private final boolean exclusiveBind;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    50
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    51
    /*
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    52
     * 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
    53
     * indicate SO_REUSEADDR is being emulated
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
    private boolean reuseAddressEmulated;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    56
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    57
    // emulates SO_REUSEADDR when exclusiveBind is true and socket is bound
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    58
    private boolean isReuseAddress;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    59
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    60
    DualStackPlainDatagramSocketImpl(boolean exclBind) {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    61
        exclusiveBind = exclBind;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    62
    }
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    63
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected void datagramSocketCreate() throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (fd == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            throw new SocketException("Socket closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        int newfd = socketCreate(false /* v6Only */);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        fdAccess.set(fd, newfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected synchronized void bind0(int lport, InetAddress laddr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (laddr == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new NullPointerException("argument address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
    80
        socketBind(nativefd, laddr, lport, exclusiveBind);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (lport == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            localPort = socketLocalPort(nativefd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            localPort = lport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected synchronized int peek(InetAddress address) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (address == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            throw new NullPointerException("Null address in peek()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // Use peekData()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        DatagramPacket peekPacket = new DatagramPacket(new byte[1], 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        int peekPort = peekData(peekPacket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        address = peekPacket.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return peekPort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected synchronized int peekData(DatagramPacket p) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            throw new NullPointerException("packet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (p.getData() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            throw new NullPointerException("packet buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return socketReceiveOrPeekData(nativefd, p, timeout, connected, true /*peek*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    protected synchronized void receive0(DatagramPacket p) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new NullPointerException("packet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (p.getData() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throw new NullPointerException("packet buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        socketReceiveOrPeekData(nativefd, p, timeout, connected, false /*receive*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    protected void send(DatagramPacket p) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            throw new NullPointerException("null packet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (p.getAddress() == null ||p.getData() ==null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throw new NullPointerException("null address || null buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        socketSend(nativefd, p.getData(), p.getOffset(), p.getLength(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                   p.getAddress(), p.getPort(), connected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    protected void connect0(InetAddress address, int port) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (address == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            throw new NullPointerException("address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        socketConnect(nativefd, address, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected void disconnect0(int family /*unused*/) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (fd == null || !fd.valid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return;   // disconnect doesn't throw any exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        socketDisconnect(fdAccess.get(fd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    protected void datagramSocketClose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (fd == null || !fd.valid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return;   // close doesn't throw any exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        socketClose(fdAccess.get(fd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        fdAccess.set(fd, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   160
    @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    protected void socketSetOption(int opt, Object val) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        int optionValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        switch(opt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            case IP_TOS :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            case SO_RCVBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            case SO_SNDBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                optionValue = ((Integer)val).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            case SO_REUSEADDR :
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   173
                if (exclusiveBind && localPort != 0)  {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   174
                    // socket already bound, emulate SO_REUSEADDR
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   175
                    reuseAddressEmulated = true;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   176
                    isReuseAddress = (Boolean)val;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   177
                    return;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   178
                }
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   179
                //Intentional fallthrough
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            case SO_BROADCAST :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                optionValue = ((Boolean)val).booleanValue() ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            default: /* shouldn't get here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                throw new SocketException("Option not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        socketSetIntOption(nativefd, opt, optionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    protected Object socketGetOption(int opt) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         // SO_BINDADDR is not a socket option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (opt == SO_BINDADDR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return socketLocalAddress(nativefd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   197
        if (opt == SO_REUSEADDR && reuseAddressEmulated)
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   198
            return isReuseAddress;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        int value = socketGetIntOption(nativefd, opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        Object returnValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        switch (opt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            case SO_REUSEADDR :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            case SO_BROADCAST :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                returnValue =  (value == 0) ? Boolean.FALSE : Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            case IP_TOS :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            case SO_RCVBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            case SO_SNDBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                returnValue = new Integer(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            default: /* shouldn't get here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                throw new SocketException("Option not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /* Multicast specific methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Multicasting on a dual layer TCP/IP stack is always done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * TwoStacksPlainDatagramSocketImpl. This is to overcome the lack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * of behavior defined for multicasting over a dual layer socket by the RFC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    protected void join(InetAddress inetaddr, NetworkInterface netIf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    protected void leave(InetAddress inetaddr, NetworkInterface netIf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    protected void setTimeToLive(int ttl) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    protected int getTimeToLive() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   243
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    protected void setTTL(byte ttl) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   248
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    protected byte getTTL() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /* END Multicast specific methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private int checkAndReturnNativeFD() throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (fd == null || !fd.valid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            throw new SocketException("Socket closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return fdAccess.get(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /* Native methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    private static native int socketCreate(boolean v6Only);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   267
    private static native void socketBind(int fd, InetAddress localAddress,
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14856
diff changeset
   268
            int localport, boolean exclBind) throws SocketException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private static native void socketConnect(int fd, InetAddress address, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private static native void socketDisconnect(int fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static native void socketClose(int fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static native int socketLocalPort(int fd) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    private static native Object socketLocalAddress(int fd) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private static native int socketReceiveOrPeekData(int fd, DatagramPacket packet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        int timeout, boolean connected, boolean peek) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private static native void socketSend(int fd, byte[] data, int offset, int length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        InetAddress address, int port, boolean connected) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    private static native void socketSetIntOption(int fd, int cmd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        int optionValue) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    private static native int socketGetIntOption(int fd, int cmd) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}