src/java.base/share/classes/java/nio/channels/ServerSocketChannel.java
author michaelm
Thu, 14 Nov 2019 12:38:31 +0000
branchunixdomainchannels
changeset 59078 4e648a2d8480
parent 59076 998df1368cca
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
/*
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
     2
 * Copyright (c) 2000, 2017, 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.ProtocolFamily;
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    30
import java.net.StandardProtocolFamily;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.ServerSocket;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    32
import java.net.SocketOption;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.SocketAddress;
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
    34
import java.nio.channels.spi.AbstractSelectableChannel;
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
    35
import java.nio.channels.spi.SelectorProvider;
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
 * A selectable channel for stream-oriented listening sockets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
    40
 * <p> A server-socket channel is created by invoking one of the open methods of this class.
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    41
 * 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
    42
 * pre-existing {@link ServerSocket}. A newly-created server-socket channel is
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    43
 * open but not yet bound.  An attempt to invoke the {@link #accept() accept}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    44
 * method of an unbound server-socket channel will cause a {@link NotYetBoundException}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    45
 * to be thrown. A server-socket channel can be bound by invoking one of the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    46
 * {@link #bind(java.net.SocketAddress,int) bind} methods defined by this class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    48
 * <p>Two kinds of server-socket channel are supported: <i>IP</i> (Internet Protocol)
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
    49
 * and <i>Unix Domain</i> depending on which open method is used to create them and which subtype of
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    50
 * {@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
    51
 * <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
    52
 * 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
    53
 * <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
    54
 * 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
    55
 * They use {@link UnixDomainSocketAddress}es and also
59074
7917f95f74c4 unixdomainchannels: minor apidoc update
michaelm
parents: 58981
diff changeset
    56
 * do not support the {@link #socket()} method. Note, it is also possible to
7917f95f74c4 unixdomainchannels: minor apidoc update
michaelm
parents: 58981
diff changeset
    57
 * create channels that support either IPv4 or IPv6 only through the
7917f95f74c4 unixdomainchannels: minor apidoc update
michaelm
parents: 58981
diff changeset
    58
 * {@link #open(ProtocolFamily)} method.
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    59
 *
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    60
 * <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
    61
 * setOption} method. <i>IP</i> server-socket channels support the following options:
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    62
 * <blockquote>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    63
 * <table class="striped">
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    64
 * <caption style="display:none">Socket options</caption>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    65
 * <thead>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    66
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    67
 *     <th scope="col">Option Name</th>
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    68
 *     <th scope="col">Description</th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    69
 *   </tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    70
 * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    71
 * <tbody>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    72
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    73
 *     <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
    74
 *     <td> The size of the socket receive buffer </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    75
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    76
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    77
 *     <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
    78
 *     <td> Re-use address </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    79
 *   </tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    80
 * </tbody>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    81
 * </table>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    82
 * </blockquote>
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
    83
 *
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    84
 * Additional (implementation specific) options may also be supported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <p> Server-socket channels are safe for use by multiple concurrent threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
    89
 * <p><i>Unix Domain</i> server-socket 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
    90
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @author JSR-51 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
public abstract class ServerSocketChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    extends AbstractSelectableChannel
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    98
    implements NetworkChannel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Initializes a new instance of this class.
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18212
diff changeset
   103
     *
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18212
diff changeset
   104
     * @param  provider
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18212
diff changeset
   105
     *         The provider that created this channel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    protected ServerSocketChannel(SelectorProvider provider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        super(provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   112
     * Opens an <i>IP</i> server-socket channel.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * <p> The new channel is created by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * java.nio.channels.spi.SelectorProvider#openServerSocketChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * openServerSocketChannel} method of the system-wide default {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * java.nio.channels.spi.SelectorProvider} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <p> The new channel's socket is initially unbound; it must be bound to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * specific address via one of its socket's {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * java.net.ServerSocket#bind(SocketAddress) bind} methods before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * connections can be accepted.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return  A new socket channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static ServerSocketChannel open() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return SelectorProvider.provider().openServerSocketChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   134
     * Returns a {@link ServerSocketChannel} of the given protocol family.
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   135
     * Where family is equal to {@link StandardProtocolFamily#INET} or {@link
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   136
     * StandardProtocolFamily#INET6} the returned channel must be bound to an
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   137
     * {@link InetSocketAddress}. If family is {@link StandardProtocolFamily#UNIX}
59074
7917f95f74c4 unixdomainchannels: minor apidoc update
michaelm
parents: 58981
diff changeset
   138
     * the returned channel must be bound to a {@link UnixDomainSocketAddress}.
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   139
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   140
     * @param family the protocol family
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   141
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   142
     * @return a ServerSocketChannel
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   143
     *
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   144
     * @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
   145
     * @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
   146
     * @since 14
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   147
     */
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   148
    public static ServerSocketChannel open(ProtocolFamily family) throws IOException {
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   149
        return SelectorProvider.provider().openServerSocketChannel(family);
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   150
    }
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   151
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   152
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Returns an operation set identifying this channel's supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p> Server-socket channels only support the accepting of new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * connections, so this method returns {@link SelectionKey#OP_ACCEPT}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @return  The valid-operation set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public final int validOps() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return SelectionKey.OP_ACCEPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    // -- ServerSocket-specific operations --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   170
     * Binds the channel's socket to a local address and configures the socket
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   171
     * to listen for connections.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   172
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   173
     * <p> An invocation of this method is equivalent to the following:
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   174
     * <blockquote><pre>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   175
     * bind(local, 0);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   176
     * </pre></blockquote>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   177
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   178
     * @param   local
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   179
     *          The local address to bind the socket, or {@code null} to bind
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   180
     *          to an automatically assigned socket address
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   181
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   182
     * @return  This channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   183
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   184
     * @throws  AlreadyBoundException               {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   185
     * @throws  UnsupportedAddressTypeException     {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   186
     * @throws  ClosedChannelException              {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   187
     * @throws  IOException                         {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   188
     * @throws  SecurityException
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   189
     *          If a security manager has been installed and its
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   190
     *          {@link SecurityManager#checkListen checkListen} method denies
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   191
     *          the operation for <i>IP</i> channels. Or with <i>Unix Domain</i>
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   192
     *          channels, if the security manager denies "read" or "write"
58847
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   193
     *          {@link java.io.FilePermission} for the local path.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   194
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   195
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   196
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   197
    public final ServerSocketChannel bind(SocketAddress local)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   198
        throws IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   199
    {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   200
        return bind(local, 0);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   201
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   202
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   203
    /**
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   204
     * Binds the channel's socket to a local address and configures the socket to
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   205
     * listen for connections.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   206
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   207
     * <p> This method is used to establish an association between the socket and
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   208
     * a local address. Once an association is established then the socket remains
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   209
     * bound until the channel is closed.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   210
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   211
     * <p> The {@code backlog} parameter is the maximum number of pending
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   212
     * connections on the socket. Its exact semantics are implementation specific.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   213
     * In particular, an implementation may impose a maximum length or may choose
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   214
     * to ignore the parameter altogther. If the {@code backlog} parameter has
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   215
     * the value {@code 0}, or a negative value, then an implementation specific
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   216
     * default is used.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   217
     *
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   218
     * <p> Note, for <i>Unix Domain</i> channels, a file is created in the file-system
58847
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   219
     * with the same path name as this channel's bound {@link UnixDomainSocketAddress}.
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   220
     * This file persists after the channel is closed, and must be removed before
59078
4e648a2d8480 unixdomainchannels: new test plus apidoc update
michaelm
parents: 59076
diff changeset
   221
     * another channel can bind to the same name. <i>Unix Domain</i>
4e648a2d8480 unixdomainchannels: new test plus apidoc update
michaelm
parents: 59076
diff changeset
   222
     * {@code ServerSocketChannels} do not support automatically assigned addresses.
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   223
     *
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   224
     * @param   local
59076
998df1368cca unixdomainchannels: unix domain automatic bind
michaelm
parents: 59074
diff changeset
   225
     *          The address to bind the socket, or {@code null} to bind an <i>IP</i> channel to
998df1368cca unixdomainchannels: unix domain automatic bind
michaelm
parents: 59074
diff changeset
   226
     *          an automatically assigned socket address
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   227
     * @param   backlog
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   228
     *          The maximum number of pending connections
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   229
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   230
     * @return  This channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   231
     *
59076
998df1368cca unixdomainchannels: unix domain automatic bind
michaelm
parents: 59074
diff changeset
   232
     * @throws  BindException
998df1368cca unixdomainchannels: unix domain automatic bind
michaelm
parents: 59074
diff changeset
   233
     *          If this is a <i>Unix domain</i> channel and {@code local} is {@code null}
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   234
     * @throws  AlreadyBoundException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   235
     *          If the socket is already bound
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   236
     * @throws  UnsupportedAddressTypeException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   237
     *          If the type of the given address is not supported
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   238
     * @throws  ClosedChannelException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   239
     *          If this channel is closed
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   240
     * @throws  IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   241
     *          If some other I/O error occurs
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   242
     * @throws  SecurityException
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   243
     *          If a security manager has been installed and its
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   244
     *          {@link SecurityManager#checkListen checkListen} method denies
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   245
     *          the operation for <i>IP</i> channels; or in the case of <i>Unix Domain</i>
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   246
     *          channels, if the security manager denies "read" or "write"
58847
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   247
     *          {@link java.io.FilePermission} for the local path.
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   248
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   249
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   250
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   251
    public abstract ServerSocketChannel bind(SocketAddress local, int backlog)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   252
        throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   253
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   254
    /**
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   255
     * @throws  UnsupportedOperationException           {@inheritDoc}
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   256
     * @throws  IllegalArgumentException                {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   257
     * @throws  ClosedChannelException                  {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   258
     * @throws  IOException                             {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   259
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   260
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   261
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   262
    public abstract <T> ServerSocketChannel setOption(SocketOption<T> name, T value)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   263
        throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   264
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   265
    /**
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   266
     * Retrieves a server 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
   267
     * channel. The operation is not supported for <i>Unix Domain</i> channels.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <p> The returned object will not declare any public methods that are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * declared in the {@link java.net.ServerSocket} class.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return  A server socket associated with this channel
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   273
     *
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   274
     * @throws UnsupportedOperationException if this is a Unix Domain channel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public abstract ServerSocket socket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Accepts a connection made to this channel's socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * <p> If this channel is in non-blocking mode then this method will
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   282
     * immediately return {@code null} if there are no pending connections.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Otherwise it will block indefinitely until a new connection is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * or an I/O error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * <p> The socket channel returned by this method, if any, will be in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * blocking mode regardless of the blocking mode of this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
58847
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   289
     * <p> For <i>IP</i> channels, this method performs exactly the same security checks
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   290
     * as the {@link java.net.ServerSocket#accept accept} method of the {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * java.net.ServerSocket} class.  That is, if a security manager has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * installed then for each new connection this method verifies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * address and port number of the connection's remote endpoint are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * permitted by the security manager's {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * java.lang.SecurityManager#checkAccept checkAccept} method.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   297
     * <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
   298
     * 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
   299
     * 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
   300
     * remote 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
   301
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @return  The socket channel for the new connection,
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   303
     *          or {@code null} if this channel is in non-blocking mode
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *          and no connection is available to be accepted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @throws  AsynchronousCloseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *          If another thread closes this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *          while the accept operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @throws  ClosedByInterruptException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *          If another thread interrupts the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *          while the accept operation is in progress, thereby
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *          closing the channel and setting the current thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *          interrupt status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @throws  NotYetBoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *          If this channel's socket has not yet been bound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *          If a security manager has been installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *          and it does not permit access to the remote endpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *          of the new connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *          If some other I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public abstract SocketChannel accept() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   332
    /**
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   333
     * {@inheritDoc}
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   334
     * Where the channel is bound to a <i>Unix Domain</i> address, the return
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   335
     * value from this method is of type  {@link UnixDomainSocketAddress}.
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   336
     * <p>
58801
119ac9128c1b Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents: 47216
diff changeset
   337
     * 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
   338
     * {@code checkConnect} method is
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   339
     * called with the local address and {@code -1} as its arguments to see
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   340
     * if the operation is allowed. If the operation is not allowed,
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   341
     * a {@code SocketAddress} representing the
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   342
     * {@link java.net.InetAddress#getLoopbackAddress loopback} address and the
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   343
     * 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
   344
     * <p>
58981
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   345
     * If there is a security manager set and this is a <i>Unix Domain</i> channel,
58847
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   346
     * then {@link SecurityManager#checkPermission(Permission)} is called using
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   347
     * a {@link java.io.FilePermission} constructed with the path from the
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   348
     * local address and "read" as the action. If this check fails
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   349
     * then an unnamed {@link UnixDomainSocketAddress} (with empty pathname)
692de65ab293 partial cleanup
michaelm
parents: 58801
diff changeset
   350
     * is returned.
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   351
     *
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   352
     * @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
   353
     *          {@code SocketAddress} representing the loopback address or empty
5c79956cc7d7 Minor updates to spec, and fix test issues
michaelm
parents: 58847
diff changeset
   354
     *          pathname if denied by the security manager, or {@code null} if the
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   355
     *          channel's socket is not bound
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   356
     *
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   357
     * @throws  ClosedChannelException     {@inheritDoc}
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   358
     * @throws  IOException                {@inheritDoc}
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   359
     */
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   360
    @Override
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   361
    public abstract SocketAddress getLocalAddress() throws IOException;
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   362
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
}