jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java
author mchung
Tue, 01 May 2012 19:45:34 -0700
changeset 12559 9456ceada8b1
parent 10708 f255532bf336
child 14014 da3648e13e67
permissions -rw-r--r--
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary Reviewed-by: alanb, mullan, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8817
diff changeset
     2
 * Copyright (c) 1995, 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: 2446
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: 2446
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: 2446
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2446
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2446
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.FileDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.net.ConnectionResetException;
2446
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
    34
import sun.net.NetHooks;
8817
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
    35
import sun.net.ResourceManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Default Socket Implementation. This implementation does
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * not implement any security checks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Note this class should <b>NOT</b> be public.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author  Steven B. Byrne
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
abstract class AbstractPlainSocketImpl extends SocketImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /* instance variable for SO_TIMEOUT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    int timeout;   // timeout in millisec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    // traffic class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private int trafficClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private boolean shut_rd = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private boolean shut_wr = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private SocketInputStream socketInputStream = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /* number of threads using the FileDescriptor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected int fdUseCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /* lock when increment/decrementing fdUseCount */
7027
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
    60
    protected final Object fdLock = new Object();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /* indicates a close is pending on the file descriptor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected boolean closePending = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /* indicates connection reset state */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private int CONNECTION_NOT_RESET = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private int CONNECTION_RESET_PENDING = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private int CONNECTION_RESET = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private int resetState;
7027
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
    70
    private final Object resetLock = new Object();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
8817
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
    72
   /* whether this Socket is a stream (TCP) socket or not (UDP)
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
    73
    */
10708
f255532bf336 7099488: TwoStacksPlainSocketImpl should invoke super.create(stream), typo in fix for 7098719
chegar
parents: 10704
diff changeset
    74
    protected boolean stream;
8817
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
    75
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Load net library into runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        java.security.AccessController.doPrivileged(
12559
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 10708
diff changeset
    81
            new java.security.PrivilegedAction<Void>() {
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 10708
diff changeset
    82
                public Void run() {
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 10708
diff changeset
    83
                    System.loadLibrary("net");
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 10708
diff changeset
    84
                    return null;
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 10708
diff changeset
    85
                }
9456ceada8b1 7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents: 10708
diff changeset
    86
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Creates a socket with a boolean that specifies whether this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * is a stream socket (true) or an unconnected UDP socket (false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected synchronized void create(boolean stream) throws IOException {
8817
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
    94
        this.stream = stream;
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
    95
        if (!stream) {
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
    96
            ResourceManager.beforeUdpCreate();
10704
db5816a6e8c7 7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents: 10421
diff changeset
    97
            // only create the fd after we know we will be able to create the socket
db5816a6e8c7 7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents: 10421
diff changeset
    98
            fd = new FileDescriptor();
8817
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
    99
            try {
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   100
                socketCreate(false);
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   101
            } catch (IOException ioe) {
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   102
                ResourceManager.afterUdpClose();
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   103
                fd = null;
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   104
                throw ioe;
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   105
            }
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   106
        } else {
10704
db5816a6e8c7 7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
chegar
parents: 10421
diff changeset
   107
            fd = new FileDescriptor();
8817
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   108
            socketCreate(true);
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   109
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (socket != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            socket.setCreated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (serverSocket != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            serverSocket.setCreated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Creates a socket and connects it to the specified port on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * the specified host.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param host the specified host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param port the specified port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    protected void connect(String host, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        throws UnknownHostException, IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    {
7027
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   125
        boolean connected = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            InetAddress address = InetAddress.getByName(host);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            this.address = address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
7027
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   131
            connectToAddress(address, port, timeout);
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   132
            connected = true;
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   133
        } finally {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   134
            if (!connected) {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   135
                try {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   136
                    close();
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   137
                } catch (IOException ioe) {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   138
                    /* Do nothing. If connect threw an exception then
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   139
                       it will be passed up the call stack */
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   140
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Creates a socket and connects it to the specified address on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * the specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param address the address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param port the specified port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    protected void connect(InetAddress address, int port) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        this.address = address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            connectToAddress(address, port, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            // everything failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Creates a socket and connects it to the specified address on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * the specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param address the address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param timeout the timeout value in milliseconds, or zero for no timeout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @throws IOException if connection fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @throws  IllegalArgumentException if address is null or is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *          SocketAddress subclass not supported by this socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
7027
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   175
    protected void connect(SocketAddress address, int timeout)
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   176
            throws IOException {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   177
        boolean connected = false;
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   178
        try {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   179
            if (address == null || !(address instanceof InetSocketAddress))
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   180
                throw new IllegalArgumentException("unsupported address type");
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   181
            InetSocketAddress addr = (InetSocketAddress) address;
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   182
            if (addr.isUnresolved())
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   183
                throw new UnknownHostException(addr.getHostName());
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   184
            this.port = addr.getPort();
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   185
            this.address = addr.getAddress();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            connectToAddress(this.address, port, timeout);
7027
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   188
            connected = true;
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   189
        } finally {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   190
            if (!connected) {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   191
                try {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   192
                    close();
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   193
                } catch (IOException ioe) {
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   194
                    /* Do nothing. If connect threw an exception then
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   195
                       it will be passed up the call stack */
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   196
                }
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   197
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private void connectToAddress(InetAddress address, int port, int timeout) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (address.isAnyLocalAddress()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            doConnect(InetAddress.getLocalHost(), port, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            doConnect(address, port, timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public void setOption(int opt, Object val) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (isClosedOrPending()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            throw new SocketException("Socket Closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        boolean on = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        switch (opt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            /* check type safety b4 going native.  These should never
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
             * fail, since only java.Socket* has access to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
             * PlainSocketImpl.setOption().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        case SO_LINGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            if (val == null || (!(val instanceof Integer) && !(val instanceof Boolean)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                throw new SocketException("Bad parameter for option");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (val instanceof Boolean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                /* true only if disabling - enabling should be Integer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                on = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        case SO_TIMEOUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            if (val == null || (!(val instanceof Integer)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                throw new SocketException("Bad parameter for SO_TIMEOUT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            int tmp = ((Integer) val).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (tmp < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                throw new IllegalArgumentException("timeout < 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            timeout = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        case IP_TOS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
             if (val == null || !(val instanceof Integer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                 throw new SocketException("bad argument for IP_TOS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
             trafficClass = ((Integer)val).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        case SO_BINDADDR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            throw new SocketException("Cannot re-bind socket");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        case TCP_NODELAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (val == null || !(val instanceof Boolean))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                throw new SocketException("bad parameter for TCP_NODELAY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            on = ((Boolean)val).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        case SO_SNDBUF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        case SO_RCVBUF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (val == null || !(val instanceof Integer) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                !(((Integer)val).intValue() > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                throw new SocketException("bad parameter for SO_SNDBUF " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                          "or SO_RCVBUF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        case SO_KEEPALIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (val == null || !(val instanceof Boolean))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                throw new SocketException("bad parameter for SO_KEEPALIVE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            on = ((Boolean)val).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        case SO_OOBINLINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if (val == null || !(val instanceof Boolean))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                throw new SocketException("bad parameter for SO_OOBINLINE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            on = ((Boolean)val).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        case SO_REUSEADDR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (val == null || !(val instanceof Boolean))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                throw new SocketException("bad parameter for SO_REUSEADDR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            on = ((Boolean)val).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            throw new SocketException("unrecognized TCP option: " + opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        socketSetOption(opt, on, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public Object getOption(int opt) throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (isClosedOrPending()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            throw new SocketException("Socket Closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (opt == SO_TIMEOUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            return new Integer(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        int ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
         * The native socketGetOption() knows about 3 options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
         * The 32 bit value it returns will be interpreted according
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
         * to what we're asking.  A return of -1 means it understands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         * the option but its turned off.  It will raise a SocketException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         * if "opt" isn't one it understands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        switch (opt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        case TCP_NODELAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            ret = socketGetOption(opt, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return Boolean.valueOf(ret != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        case SO_OOBINLINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            ret = socketGetOption(opt, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            return Boolean.valueOf(ret != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        case SO_LINGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            ret = socketGetOption(opt, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return (ret == -1) ? Boolean.FALSE: (Object)(new Integer(ret));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        case SO_REUSEADDR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            ret = socketGetOption(opt, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            return Boolean.valueOf(ret != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        case SO_BINDADDR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            InetAddressContainer in = new InetAddressContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            ret = socketGetOption(opt, in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return in.addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        case SO_SNDBUF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        case SO_RCVBUF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            ret = socketGetOption(opt, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return new Integer(ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        case IP_TOS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            ret = socketGetOption(opt, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            if (ret == -1) { // ipv6 tos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                return new Integer(trafficClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                return new Integer(ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        case SO_KEEPALIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            ret = socketGetOption(opt, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            return Boolean.valueOf(ret != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        // should never get here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * The workhorse of the connection operation.  Tries several times to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * establish a connection to the given <host, port>.  If unsuccessful,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * throws an IOException indicating what went wrong.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException {
2446
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   336
        synchronized (fdLock) {
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   337
            if (!closePending && (socket == null || !socket.isBound())) {
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   338
                NetHooks.beforeTcpConnect(fd, address, port);
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   339
            }
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   340
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        try {
7027
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   342
            acquireFD();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                socketConnect(address, port, timeout);
1335
79ed7fd4bb49 6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents: 715
diff changeset
   345
                /* socket may have been closed during poll/select */
79ed7fd4bb49 6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents: 715
diff changeset
   346
                synchronized (fdLock) {
79ed7fd4bb49 6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents: 715
diff changeset
   347
                    if (closePending) {
79ed7fd4bb49 6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents: 715
diff changeset
   348
                        throw new SocketException ("Socket closed");
79ed7fd4bb49 6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents: 715
diff changeset
   349
                    }
79ed7fd4bb49 6739920: java 6u4~ use larger C heap if there are many threads
michaelm
parents: 715
diff changeset
   350
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                // If we have a ref. to the Socket, then sets the flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                // created, bound & connected to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                // This is normally done in Socket.connect() but some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                // subclasses of Socket may call impl.connect() directly!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                if (socket != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    socket.setBound();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    socket.setConnected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                releaseFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Binds the socket to the specified address of the specified local port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param address the address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @param port the port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    protected synchronized void bind(InetAddress address, int lport)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    {
2446
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   376
       synchronized (fdLock) {
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   377
            if (!closePending && (socket == null || !socket.isBound())) {
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   378
                NetHooks.beforeTcpBind(fd, address, lport);
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   379
            }
07047237e4d4 4890703: Support SDP (sol)
alanb
parents: 1335
diff changeset
   380
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        socketBind(address, lport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (socket != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            socket.setBound();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (serverSocket != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            serverSocket.setBound();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Listens, for a specified amount of time, for connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @param count the amount of time to listen for connections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    protected synchronized void listen(int count) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        socketListen(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Accepts connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @param s the connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    protected void accept(SocketImpl s) throws IOException {
7027
d3404b1406d5 6994079: PlainSocketImpl should close the socket if it fails
chegar
parents: 5506
diff changeset
   401
        acquireFD();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            socketAccept(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            releaseFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Gets an InputStream for this socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    protected synchronized InputStream getInputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        if (isClosedOrPending()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            throw new IOException("Socket Closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (shut_rd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            throw new IOException("Socket input is shutdown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (socketInputStream == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            socketInputStream = new SocketInputStream(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return socketInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    void setInputStream(SocketInputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        socketInputStream = in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Gets an OutputStream for this socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    protected synchronized OutputStream getOutputStream() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        if (isClosedOrPending()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            throw new IOException("Socket Closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (shut_wr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            throw new IOException("Socket output is shutdown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return new SocketOutputStream(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    void setFileDescriptor(FileDescriptor fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        this.fd = fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    void setAddress(InetAddress address) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        this.address = address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    void setPort(int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    void setLocalPort(int localport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        this.localport = localport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Returns the number of bytes that can be read without blocking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    protected synchronized int available() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if (isClosedOrPending()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            throw new IOException("Stream closed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        /*
10421
2ee16a0f6df5 7014860: Socket.getInputStream().available() not clear for shutdown input
chegar
parents: 9035
diff changeset
   467
         * If connection has been reset or shut down for input, then return 0
2ee16a0f6df5 7014860: Socket.getInputStream().available() not clear for shutdown input
chegar
parents: 9035
diff changeset
   468
         * to indicate there are no buffered bytes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
         */
10421
2ee16a0f6df5 7014860: Socket.getInputStream().available() not clear for shutdown input
chegar
parents: 9035
diff changeset
   470
        if (isConnectionReset() || shut_rd) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
         * If no bytes available and we were previously notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
         * of a connection reset then we move to the reset state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
         * If are notified of a connection reset then check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         * again if there are bytes buffered on the socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            n = socketAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            if (n == 0 && isConnectionResetPending()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                setConnectionReset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        } catch (ConnectionResetException exc1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            setConnectionResetPending();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                n = socketAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                if (n == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    setConnectionReset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            } catch (ConnectionResetException exc2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * Closes the socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    protected void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        synchronized(fdLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            if (fd != null) {
8817
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   506
                if (!stream) {
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   507
                    ResourceManager.afterUdpClose();
5351579c46a9 6981922: DNS cache poisoning by untrusted applets
michaelm
parents: 7668
diff changeset
   508
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                if (fdUseCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    if (closePending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    closePending = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                     * We close the FileDescriptor in two-steps - first the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                     * "pre-close" which closes the socket but doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                     * release the underlying file descriptor. This operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                     * may be lengthy due to untransmitted data and a long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                     * linger interval. Once the pre-close is done we do the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                     * actual socket to release the fd.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                        socketPreClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                        socketClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    fd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                     * If a thread has acquired the fd and a close
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                     * isn't pending then use a deferred close.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                     * Also decrement fdUseCount to signal the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                     * thread that releases the fd to close it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                    if (!closePending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                        closePending = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                        fdUseCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                        socketPreClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    void reset() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (fd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            socketClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        fd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        super.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * Shutdown read-half of the socket connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    protected void shutdownInput() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
      if (fd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
          socketShutdown(SHUT_RD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
          if (socketInputStream != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
              socketInputStream.setEOF(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
          shut_rd = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * Shutdown write-half of the socket connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    protected void shutdownOutput() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
      if (fd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
          socketShutdown(SHUT_WR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
          shut_wr = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    protected boolean supportsUrgentData () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    protected void sendUrgentData (int data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (fd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            throw new IOException("Socket Closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        socketSendUrgentData (data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Cleans up if the user forgets to close it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    protected void finalize() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * "Acquires" and returns the FileDescriptor for this impl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * A corresponding releaseFD is required to "release" the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * FileDescriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    FileDescriptor acquireFD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        synchronized (fdLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            fdUseCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            return fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * "Release" the FileDescriptor for this impl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * If the use count goes to -1 then the socket is closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    void releaseFD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        synchronized (fdLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            fdUseCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            if (fdUseCount == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                if (fd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                        socketClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                        fd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public boolean isConnectionReset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        synchronized (resetLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            return (resetState == CONNECTION_RESET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    public boolean isConnectionResetPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        synchronized (resetLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            return (resetState == CONNECTION_RESET_PENDING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public void setConnectionReset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        synchronized (resetLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            resetState = CONNECTION_RESET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public void setConnectionResetPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        synchronized (resetLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            if (resetState == CONNECTION_NOT_RESET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                resetState = CONNECTION_RESET_PENDING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * Return true if already closed or close is pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public boolean isClosedOrPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
         * Lock on fdLock to ensure that we wait if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
         * close is in progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        synchronized (fdLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            if (closePending || (fd == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * Return the current value of SO_TIMEOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    public int getTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        return timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * "Pre-close" a socket by dup'ing the file descriptor - this enables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * the socket to be closed without releasing the file descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    private void socketPreClose() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        socketClose0(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Close the socket (and release the file descriptor).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    protected void socketClose() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        socketClose0(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    abstract void socketCreate(boolean isServer) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    abstract void socketConnect(InetAddress address, int port, int timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    abstract void socketBind(InetAddress address, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    abstract void socketListen(int count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    abstract void socketAccept(SocketImpl s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    abstract int socketAvailable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    abstract void socketClose0(boolean useDeferredClose)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    abstract void socketShutdown(int howto)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    abstract void socketSetOption(int cmd, boolean on, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    abstract int socketGetOption(int opt, Object iaContainerObj) throws SocketException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    abstract void socketSendUrgentData(int data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    public final static int SHUT_RD = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    public final static int SHUT_WR = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
class InetAddressContainer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    InetAddress addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
}