jdk/src/windows/classes/java/net/DualStackPlainDatagramSocketImpl.java
author chegar
Fri, 16 Sep 2011 12:09:04 -0700
changeset 10596 39b3a979e600
parent 5506 202f599c92aa
child 14856 92a1bcf46888
permissions -rw-r--r--
7090158: Networking Libraries don't build with javac -Werror Summary: Minor changes to networking java files to remove warnings Reviewed-by: chegar, weijun, hawtin Contributed-by: kurchi.subhra.hazra@oracle.com, sasha_bu@hotmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
     2
 * Copyright (c) 2007,2011 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected void datagramSocketCreate() throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        if (fd == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            throw new SocketException("Socket closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        int newfd = socketCreate(false /* v6Only */);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        fdAccess.set(fd, newfd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected synchronized void bind0(int lport, InetAddress laddr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (laddr == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            throw new NullPointerException("argument address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        socketBind(nativefd, laddr, lport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (lport == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            localPort = socketLocalPort(nativefd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            localPort = lport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected synchronized int peek(InetAddress address) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (address == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            throw new NullPointerException("Null address in peek()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        // Use peekData()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        DatagramPacket peekPacket = new DatagramPacket(new byte[1], 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        int peekPort = peekData(peekPacket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        address = peekPacket.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return peekPort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected synchronized int peekData(DatagramPacket p) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            throw new NullPointerException("packet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (p.getData() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            throw new NullPointerException("packet buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return socketReceiveOrPeekData(nativefd, p, timeout, connected, true /*peek*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected synchronized void receive0(DatagramPacket p) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new NullPointerException("packet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (p.getData() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            throw new NullPointerException("packet buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        socketReceiveOrPeekData(nativefd, p, timeout, connected, false /*receive*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected void send(DatagramPacket p) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            throw new NullPointerException("null packet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (p.getAddress() == null ||p.getData() ==null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            throw new NullPointerException("null address || null buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        socketSend(nativefd, p.getData(), p.getOffset(), p.getLength(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                   p.getAddress(), p.getPort(), connected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    protected void connect0(InetAddress address, int port) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (address == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            throw new NullPointerException("address");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        socketConnect(nativefd, address, port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected void disconnect0(int family /*unused*/) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (fd == null || !fd.valid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            return;   // disconnect doesn't throw any exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        socketDisconnect(fdAccess.get(fd));
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 datagramSocketClose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (fd == null || !fd.valid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return;   // close doesn't throw any exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        socketClose(fdAccess.get(fd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        fdAccess.set(fd, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected void socketSetOption(int opt, Object val) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        int optionValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        switch(opt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            case IP_TOS :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            case SO_RCVBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            case SO_SNDBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                optionValue = ((Integer)val).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            case SO_REUSEADDR :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            case SO_BROADCAST :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                optionValue = ((Boolean)val).booleanValue() ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            default: /* shouldn't get here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                throw new SocketException("Option not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        socketSetIntOption(nativefd, opt, optionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    protected Object socketGetOption(int opt) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        int nativefd = checkAndReturnNativeFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         // SO_BINDADDR is not a socket option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (opt == SO_BINDADDR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            return socketLocalAddress(nativefd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        int value = socketGetIntOption(nativefd, opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        Object returnValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        switch (opt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            case SO_REUSEADDR :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            case SO_BROADCAST :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                returnValue =  (value == 0) ? Boolean.FALSE : Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            case IP_TOS :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            case SO_RCVBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            case SO_SNDBUF :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                returnValue = new Integer(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            default: /* shouldn't get here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                throw new SocketException("Option not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /* Multicast specific methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Multicasting on a dual layer TCP/IP stack is always done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * TwoStacksPlainDatagramSocketImpl. This is to overcome the lack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * of behavior defined for multicasting over a dual layer socket by the RFC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    protected void join(InetAddress inetaddr, NetworkInterface netIf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    protected void leave(InetAddress inetaddr, NetworkInterface netIf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    protected void setTimeToLive(int ttl) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    protected int getTimeToLive() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   217
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    protected void setTTL(byte ttl) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 5506
diff changeset
   222
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    protected byte getTTL() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        throw new IOException("Method not implemented!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /* END Multicast specific methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private int checkAndReturnNativeFD() throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (fd == null || !fd.valid())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            throw new SocketException("Socket closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return fdAccess.get(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /* Native methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    private static native int socketCreate(boolean v6Only);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    private static native void socketBind(int fd, InetAddress localAddress, int localport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    private static native void socketConnect(int fd, InetAddress address, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    private static native void socketDisconnect(int fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    private static native void socketClose(int fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    private static native int socketLocalPort(int fd) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    private static native Object socketLocalAddress(int fd) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    private static native int socketReceiveOrPeekData(int fd, DatagramPacket packet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        int timeout, boolean connected, boolean peek) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private static native void socketSend(int fd, byte[] data, int offset, int length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        InetAddress address, int port, boolean connected) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private static native void socketSetIntOption(int fd, int cmd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        int optionValue) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private static native int socketGetIntOption(int fd, int cmd) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
}