src/java.base/share/classes/java/nio/channels/SocketChannel.java
author michaelm
Thu, 14 Nov 2019 12:38:31 +0000
branchunixdomainchannels
changeset 59078 4e648a2d8480
parent 58981 5c79956cc7d7
permissions -rw-r--r--
unixdomainchannels: new test plus apidoc update
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2019, 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: 2057
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: 2057
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: 2057
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2057
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.nio.channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    29
import java.net.InetSocketAddress;
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    30
import java.net.ProtocolFamily;
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    31
import java.net.StandardProtocolFamily;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.Socket;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    33
import java.net.SocketOption;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.SocketAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.nio.ByteBuffer;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
    36
import java.nio.channels.spi.AbstractSelectableChannel;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
    37
import java.nio.channels.spi.SelectorProvider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * A selectable channel for stream-oriented connecting sockets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    42
 * <p> A socket channel is created by invoking one of the open methods of this class.
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    43
 * It is not possible to create a channel for an arbitrary,
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    44
 * pre-existing socket. A newly-created socket channel is open but not yet
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * connected.  An attempt to invoke an I/O operation upon an unconnected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * channel will cause a {@link NotYetConnectedException} to be thrown.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * socket channel can be connected by invoking its {@link #connect connect}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * method; once connected, a socket channel remains connected until it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * closed.  Whether or not a socket channel is connected may be determined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * invoking its {@link #isConnected isConnected} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p> Socket channels support <i>non-blocking connection:</i>&nbsp;A socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * channel may be created and the process of establishing the link to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * remote socket may be initiated via the {@link #connect connect} method for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * later completion by the {@link #finishConnect finishConnect} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Whether or not a connection operation is in progress may be determined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * invoking the {@link #isConnectionPending isConnectionPending} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p> Socket channels support <i>asynchronous shutdown,</i> which is similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * to the asynchronous close operation specified in the {@link Channel} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * If the input side of a socket is shut down by one thread while another
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * thread is blocked in a read operation on the socket's channel, then the read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * operation in the blocked thread will complete without reading any bytes and
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
    64
 * will return {@code -1}.  If the output side of a socket is shut down by one
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * thread while another thread is blocked in a write operation on the socket's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * channel, then the blocked thread will receive an {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * AsynchronousCloseException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    69
 * <p>Two kinds of socket channel are supported: <i>IP</i> (Internet Protocol) and
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
    70
 * <i>Unix Domain</i> depending on which open method is used to create them and which
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    71
 * subtype of {@link SocketAddress} that they support for local and remote addresses.
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    72
 * <i>IP</i> channels are created using {@link #open()}. They use {@link
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    73
 * InetSocketAddress} addresses and support both IPv4 and IPv6 TCP/IP.
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
    74
 * <i>Unix Domain</i> channels are created using {@link #open(ProtocolFamily)}
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    75
 * with the family parameter set to {@link StandardProtocolFamily#UNIX}.
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    76
 * They use {@link UnixDomainSocketAddress}es and also
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
    77
 * do not support the {@link #socket()} method. Note, it is also possible to
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
    78
 * create channels that support either IPv4 or IPv6 only through the
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
    79
 * {@link #open(ProtocolFamily)} method.
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    80
 *
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    81
 * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    82
 * setOption} method. <i>IP</i> socket channels support the following options:
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    83
 * <blockquote>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    84
 * <table class="striped">
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    85
 * <caption style="display:none">Socket options</caption>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    86
 * <thead>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    87
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    88
 *     <th scope="col">Option Name</th>
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    89
 *     <th scope="col">Description</th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    90
 *   </tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    91
 * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    92
 * <tbody>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    93
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    94
 *     <th scope="row"> {@link java.net.StandardSocketOptions#SO_SNDBUF SO_SNDBUF} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    95
 *     <td> The size of the socket send buffer </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    96
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    97
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    98
 *     <th scope="row"> {@link java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    99
 *     <td> The size of the socket receive buffer </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   100
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   101
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   102
 *     <th scope="row"> {@link java.net.StandardSocketOptions#SO_KEEPALIVE SO_KEEPALIVE} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   103
 *     <td> Keep connection alive </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   104
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   105
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   106
 *     <th scope="row"> {@link java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   107
 *     <td> Re-use address </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   108
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   109
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   110
 *     <th scope="row"> {@link java.net.StandardSocketOptions#SO_LINGER SO_LINGER} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   111
 *     <td> Linger on close if data is present (when configured in blocking mode
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   112
 *          only) </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   113
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   114
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   115
 *     <th scope="row"> {@link java.net.StandardSocketOptions#TCP_NODELAY TCP_NODELAY} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   116
 *     <td> Disable the Nagle algorithm </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   117
 *   </tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
   118
 * </tbody>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   119
 * </table>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   120
 * </blockquote>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   121
 * Additional (implementation specific) options may also be supported.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   122
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <p> Socket channels are safe for use by multiple concurrent threads.  They
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * support concurrent reading and writing, though at most one thread may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * reading and at most one thread may be writing at any given time.  The {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * #connect connect} and {@link #finishConnect finishConnect} methods are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * mutually synchronized against each other, and an attempt to initiate a read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * or write operation while an invocation of one of these methods is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * progress will block until that invocation is complete.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   131
 * <p><i>Unix Domain</i> channels support a subset of the options listed above.
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   132
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * @author JSR-51 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
public abstract class SocketChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    extends AbstractSelectableChannel
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   140
    implements ByteChannel, ScatteringByteChannel, GatheringByteChannel, NetworkChannel
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
    /**
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   144
     * Initializes a new <i>IP</i> instance of this class.
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18274
diff changeset
   145
     *
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18274
diff changeset
   146
     * @param  provider
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18274
diff changeset
   147
     *         The provider that created this channel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    protected SocketChannel(SelectorProvider provider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        super(provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   154
     * Opens an <i>IP</i> socket channel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p> The new channel is created by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * java.nio.channels.spi.SelectorProvider#openSocketChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * openSocketChannel} method of the system-wide default {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * java.nio.channels.spi.SelectorProvider} object.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @return  A new socket channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public static SocketChannel open() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return SelectorProvider.provider().openSocketChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   171
     * Returns a {@link SocketChannel} of the given {@link ProtocolFamily}.
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   172
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   173
     * @param family the protocol family
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   174
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   175
     * @return a SocketChannel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   177
     * @throws IOException if an I/O error occurs
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   178
     * @throws UnsupportedAddressTypeException if the protocol family is not supported
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   179
     * @since 14
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   180
     */
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   181
    public static SocketChannel open(ProtocolFamily family) throws IOException {
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   182
        return SelectorProvider.provider().openSocketChannel(family);
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   183
    }
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   184
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   185
    /**
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   186
     * Opens a socket channel and connects it to a remote address.
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   187
     * Depending on the type of {@link SocketAddress} supplied, the returned object
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   188
     * is an <i>IP</i> or <i>Unix Domain</i> channel.
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   189
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   190
     * <p> For {@link InetSocketAddress}es this convenience method works as if by invoking the {@link #open()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * method, invoking the {@link #connect(SocketAddress) connect} method upon
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   192
     * the resulting socket channel, passing it {@code remote}, which must be an
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   193
     * {@link InetSocketAddress} and then returning that channel.  </p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   195
     * <p> For {@link UnixDomainSocketAddress}es it works as if by invoking the {@link
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   196
     * #open(ProtocolFamily)} method with {@link StandardProtocolFamily#UNIX} as parameter,
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   197
     * invoking the {@link #connect(SocketAddress) connect} method upon
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   198
     * the resulting socket channel, passing it {@code remote}, which must be a
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   199
     * {@link UnixDomainSocketAddress} and then returning that channel.  </p>
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   200
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param  remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *         The remote address to which the new channel is to be connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18274
diff changeset
   204
     * @return  A new, and connected, socket channel
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18274
diff changeset
   205
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @throws  AsynchronousCloseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *          If another thread closes this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *          while the connect operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @throws  ClosedByInterruptException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *          If another thread interrupts the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *          while the connect operation is in progress, thereby
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *          closing the channel and setting the current thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *          interrupt status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @throws  UnresolvedAddressException
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   217
     *          If the given remote is an InetSocketAddress that is not fully resolved
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @throws  UnsupportedAddressTypeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *          If the type of the given remote address is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *          If a security manager has been installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *          and it does not permit access to the given remote endpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *          If some other I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public static SocketChannel open(SocketAddress remote)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    {
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   232
        SocketChannel sc;
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   233
        if (remote instanceof InetSocketAddress)
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   234
            sc = open();
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   235
        else if (remote instanceof UnixDomainSocketAddress)
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   236
            sc = open(StandardProtocolFamily.UNIX);
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   237
        else
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   238
            throw new UnsupportedAddressTypeException();
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   239
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            sc.connect(remote);
8539
eeb9fc5a68c1 7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents: 5506
diff changeset
   242
        } catch (Throwable x) {
eeb9fc5a68c1 7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents: 5506
diff changeset
   243
            try {
eeb9fc5a68c1 7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents: 5506
diff changeset
   244
                sc.close();
eeb9fc5a68c1 7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents: 5506
diff changeset
   245
            } catch (Throwable suppressed) {
eeb9fc5a68c1 7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents: 5506
diff changeset
   246
                x.addSuppressed(suppressed);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
8539
eeb9fc5a68c1 7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents: 5506
diff changeset
   248
            throw x;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        assert sc.isConnected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return sc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Returns an operation set identifying this channel's supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <p> Socket channels support connecting, reading, and writing, so this
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   259
     * method returns {@code (}{@link SelectionKey#OP_CONNECT}
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   260
     * {@code |}&nbsp;{@link SelectionKey#OP_READ} {@code |}&nbsp;{@link
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   261
     * SelectionKey#OP_WRITE}{@code )}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @return  The valid-operation set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public final int validOps() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return (SelectionKey.OP_READ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                | SelectionKey.OP_WRITE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                | SelectionKey.OP_CONNECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    // -- Socket-specific operations --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   275
     * {@inheritDoc}
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   276
     *
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   277
     * <p> Note, for <i>Unix Domain</i> channels, a file is created in the file-system
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   278
     * with the same name as this channel's bound address. This file persists after
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   279
     * the channel is closed, and must be removed before another channel can bind
59078
4e648a2d8480 unixdomainchannels: new test plus apidoc update
michaelm
parents: 58981
diff changeset
   280
     * to the same name. However, automatically assigned addresses have an empty
4e648a2d8480 unixdomainchannels: new test plus apidoc update
michaelm
parents: 58981
diff changeset
   281
     * pathname, and no corresponding file in the file-system.
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   282
     *
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   283
     * @throws  ConnectionPendingException
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   284
     *          If a non-blocking connect operation is already in progress on
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   285
     *          this channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   286
     * @throws  AlreadyBoundException               {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   287
     * @throws  UnsupportedAddressTypeException     {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   288
     * @throws  ClosedChannelException              {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   289
     * @throws  IOException                         {@inheritDoc}
22339
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 18574
diff changeset
   290
     * @throws  SecurityException
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 18574
diff changeset
   291
     *          If a security manager has been installed and its
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 18574
diff changeset
   292
     *          {@link SecurityManager#checkListen checkListen} method denies
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   293
     *          the operation for <i>IP</i> channels; or for <i>Unix Domain</i>
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   294
     *          channels, if the security manager denies "read" or "write"
58847
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   295
     *          {@link java.io.FilePermission} for the local path.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   296
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   297
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   298
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   299
    @Override
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   300
    public abstract SocketChannel bind(SocketAddress local)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   301
        throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   302
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   303
    /**
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   304
     * @throws  UnsupportedOperationException           {@inheritDoc}
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   305
     * @throws  IllegalArgumentException                {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   306
     * @throws  ClosedChannelException                  {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   307
     * @throws  IOException                             {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   308
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   309
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   310
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   311
    @Override
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   312
    public abstract <T> SocketChannel setOption(SocketOption<T> name, T value)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   313
        throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   314
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   315
    /**
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   316
     * Shutdown the connection for reading without closing the channel.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   317
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   318
     * <p> Once shutdown for reading then further reads on the channel will
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   319
     * return {@code -1}, the end-of-stream indication. If the input side of the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   320
     * connection is already shutdown then invoking this method has no effect.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   321
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   322
     * @return  The channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   323
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   324
     * @throws  NotYetConnectedException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   325
     *          If this channel is not yet connected
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   326
     * @throws  ClosedChannelException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   327
     *          If this channel is closed
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   328
     * @throws  IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   329
     *          If some other I/O error occurs
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   330
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   331
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   332
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   333
    public abstract SocketChannel shutdownInput() throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   334
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   335
    /**
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   336
     * Shutdown the connection for writing without closing the channel.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   337
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   338
     * <p> Once shutdown for writing then further attempts to write to the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   339
     * channel will throw {@link ClosedChannelException}. If the output side of
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   340
     * the connection is already shutdown then invoking this method has no
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   341
     * effect.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   342
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   343
     * @return  The channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   344
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   345
     * @throws  NotYetConnectedException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   346
     *          If this channel is not yet connected
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   347
     * @throws  ClosedChannelException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   348
     *          If this channel is closed
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   349
     * @throws  IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   350
     *          If some other I/O error occurs
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   351
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   352
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   353
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   354
    public abstract SocketChannel shutdownOutput() throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   355
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   356
    /**
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   357
     * Retrieves a socket associated with this channel if it is an <i>IP</i>
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   358
     * channel. The operation is not supported for <i>Unix Domain</i> channels.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * <p> The returned object will not declare any public methods that are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * declared in the {@link java.net.Socket} class.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @return  A socket associated with this channel
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   364
     *
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   365
     * @throws UnsupportedOperationException is this is a <i>Unix Domain</i> channel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public abstract Socket socket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   370
     * Tells whether or not this channel's network socket is connected.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   372
     * @return  {@code true} if, and only if, this channel's network socket
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   373
     *          is {@link #isOpen open} and connected
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public abstract boolean isConnected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Tells whether or not a connection operation is in progress on this
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 9679
diff changeset
   379
     * channel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   381
     * @return  {@code true} if, and only if, a connection operation has been
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *          initiated on this channel but not yet completed by invoking the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *          {@link #finishConnect finishConnect} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public abstract boolean isConnectionPending();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Connects this channel's socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * <p> If this channel is in non-blocking mode then an invocation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * method initiates a non-blocking connection operation.  If the connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * is established immediately, as can happen with a local connection, then
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   393
     * this method returns {@code true}.  Otherwise this method returns
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   394
     * {@code false} and the connection operation must later be completed by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * invoking the {@link #finishConnect finishConnect} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * <p> If this channel is in blocking mode then an invocation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * method will block until the connection is established or an I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   401
     * <p> For <i>IP</i> channels, this method performs exactly the same security checks
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   402
     * as the {@link java.net.Socket} class.  That is, if a security manager has been
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * installed then this method verifies that its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * java.lang.SecurityManager#checkConnect checkConnect} method permits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * connecting to the address and port number of the given remote endpoint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   407
     * <p> For <i>Unix Domain</i> channels, this method performs a security
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   408
     * manager {@link SecurityManager#checkPermission(Permission)} using
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   409
     * a {@link java.io.FilePermission} constructed with the path from the
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   410
     * destination address and "read,write" as the actions.
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   411
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <p> This method may be invoked at any time.  If a read or write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * operation upon this channel is invoked while an invocation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * method is in progress then that operation will first block until this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * invocation is complete.  If a connection attempt is initiated but fails,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * that is, if an invocation of this method throws a checked exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * then the channel will be closed.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param  remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *         The remote address to which this channel is to be connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   422
     * @return  {@code true} if a connection was established,
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   423
     *          {@code false} if this channel is in non-blocking mode
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *          and the connection operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @throws  AlreadyConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *          If this channel is already connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @throws  ConnectionPendingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *          If a non-blocking connection operation is already in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *          on this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @throws  AsynchronousCloseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *          If another thread closes this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *          while the connect operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @throws  ClosedByInterruptException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *          If another thread interrupts the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *          while the connect operation is in progress, thereby
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *          closing the channel and setting the current thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *          interrupt status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @throws  UnresolvedAddressException
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   447
     *          If the given remote address is an InetSocketAddress which is not fully resolved
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @throws  UnsupportedAddressTypeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *          If the type of the given remote address is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *          If a security manager has been installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *          and it does not permit access to the given remote endpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *          If some other I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public abstract boolean connect(SocketAddress remote) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Finishes the process of connecting a socket channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * <p> A non-blocking connection operation is initiated by placing a socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * channel in non-blocking mode and then invoking its {@link #connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * connect} method.  Once the connection is established, or the attempt has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * failed, the socket channel will become connectable and this method may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * be invoked to complete the connection sequence.  If the connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * operation failed then invoking this method will cause an appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * {@link java.io.IOException} to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * <p> If this channel is already connected then this method will not block
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   473
     * and will immediately return {@code true}.  If this channel is in
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   474
     * non-blocking mode then this method will return {@code false} if the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * connection process is not yet complete.  If this channel is in blocking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * mode then this method will block until the connection either completes
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   477
     * or fails, and will always either return {@code true} or throw a checked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * exception describing the failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * <p> This method may be invoked at any time.  If a read or write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * operation upon this channel is invoked while an invocation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * method is in progress then that operation will first block until this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * invocation is complete.  If a connection attempt fails, that is, if an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * invocation of this method throws a checked exception, then the channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * will be closed.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   487
     * @return  {@code true} if, and only if, this channel's socket is now
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *          connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @throws  NoConnectionPendingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *          If this channel is not connected and a connection operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *          has not been initiated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @throws  AsynchronousCloseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *          If another thread closes this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *          while the connect operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @throws  ClosedByInterruptException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *          If another thread interrupts the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *          while the connect operation is in progress, thereby
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *          closing the channel and setting the current thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *          interrupt status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *          If some other I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public abstract boolean finishConnect() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   512
    /**
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   513
     * Returns the remote address to which this channel's socket is connected.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   514
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   515
     * <p> Where the channel is bound and connected to an Internet Protocol
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   516
     * socket address then the return value from this method is of type {@link
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   517
     * java.net.InetSocketAddress}.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   518
     *
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   519
     * <p> Where the channel is bound and connected to a <i>Unix Domain</i>
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   520
     * address, the returned address is a {@link UnixDomainSocketAddress}
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   521
     *
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   522
     * @return  The remote address; {@code null} if the channel's socket is not
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   523
     *          connected
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   524
     *
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   525
     * @throws  ClosedChannelException
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   526
     *          If the channel is closed
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   527
     * @throws  IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   528
     *          If an I/O error occurs
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   529
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   530
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   531
     */
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   532
    public abstract SocketAddress getRemoteAddress() throws IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    // -- ByteChannel operations --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *          If this channel is not yet connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    public abstract int read(ByteBuffer dst) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *          If this channel is not yet connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public abstract long read(ByteBuffer[] dsts, int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *          If this channel is not yet connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    public final long read(ByteBuffer[] dsts) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return read(dsts, 0, dsts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *          If this channel is not yet connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    public abstract int write(ByteBuffer src) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *          If this channel is not yet connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public abstract long write(ByteBuffer[] srcs, int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *          If this channel is not yet connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    public final long write(ByteBuffer[] srcs) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        return write(srcs, 0, srcs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   578
    /**
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   579
     * {@inheritDoc}
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   580
     * <p>
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   581
     * If there is a security manager set and this is an <i>IP</i> channel,
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   582
     * {@code checkConnect} method is
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   583
     * called with the local address and {@code -1} as its arguments to see
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   584
     * if the operation is allowed. If the operation is not allowed,
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   585
     * a {@code SocketAddress} representing the
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   586
     * {@link java.net.InetAddress#getLoopbackAddress loopback} address and the
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   587
     * local port of the channel's socket is returned.
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   588
     * <p>
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   589
     * If there is a security manager set and this is a <i>Unix Domain</i> channel,
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   590
     * {@code checkPermission} is called with a {@link FilePermission} whose {@code
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   591
     * path} is the path of the bound address and actions is {@code "read"}
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   592
     * and if the operation is allowed a {@link UnixDomainSocketAddress} 
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   593
     * corresponding to the bound address is returned. If not, then an address with
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   594
     * an empty path is returned.
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   595
     *
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   596
     * @return  The {@code SocketAddress} that the socket is bound to, or the
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   597
     *          {@code SocketAddress} representing the loopback address or an
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   598
     *          empty pathname, if denied by the security manager, or {@code null} if the
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   599
     *          channel's socket is not bound
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   600
     *
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   601
     * @throws  ClosedChannelException     {@inheritDoc}
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   602
     * @throws  IOException                {@inheritDoc}
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   603
     */
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   604
    @Override
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 9679
diff changeset
   605
    public abstract SocketAddress getLocalAddress() throws IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
}