src/java.base/share/classes/java/nio/channels/DatagramChannel.java
author bpb
Thu, 14 Nov 2019 09:06:43 -0800
changeset 59089 de56632f796d
parent 58803 1bd307ea5497
child 59227 46084917fde7
permissions -rw-r--r--
8146298: (dc spec) connect and disconnect methods should specify that they may block Reviewed-by: alanb, chegar, dfuchs, darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58518
705c3f88a409 8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents: 58501
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: 3419
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: 3419
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: 3419
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3419
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3419
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;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    29
import java.net.ProtocolFamily;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.DatagramSocket;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    31
import java.net.SocketOption;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.SocketAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.ByteBuffer;
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 datagram-oriented sockets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    40
 * <p> A datagram channel is created by invoking one of the {@link #open open} methods
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    41
 * of this class. It is not possible to create a channel for an arbitrary,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    42
 * pre-existing datagram socket. A newly-created datagram channel is open but not
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    43
 * connected. A datagram channel need not be connected in order for the {@link #send
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    44
 * send} and {@link #receive receive} methods to be used.  A datagram channel may be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * connected, by invoking its {@link #connect connect} method, in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * avoid the overhead of the security checks are otherwise performed as part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * every send and receive operation.  A datagram channel must be connected in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * order to use the {@link #read(java.nio.ByteBuffer) read} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * #write(java.nio.ByteBuffer) write} methods, since those methods do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * accept or return socket addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p> Once connected, a datagram channel remains connected until it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * disconnected or closed.  Whether or not a datagram channel is connected may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * be determined by invoking its {@link #isConnected isConnected} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    56
 * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
    57
 * setOption} method. A datagram channel to an Internet Protocol socket supports
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
    58
 * the following options:
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    59
 * <blockquote>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    60
 * <table class="striped">
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    61
 * <caption style="display:none">Socket options</caption>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    62
 * <thead>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    63
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    64
 *     <th scope="col">Option Name</th>
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    65
 *     <th scope="col">Description</th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    66
 *   </tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    67
 * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
    68
 * <tbody>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    69
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    70
 *     <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
    71
 *     <td> The size of the socket send buffer </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    72
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    73
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    74
 *     <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
    75
 *     <td> The size of the socket receive buffer </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    76
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    77
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    78
 *     <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
    79
 *     <td> Re-use address </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    80
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    81
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    82
 *     <th scope="row"> {@link java.net.StandardSocketOptions#SO_BROADCAST SO_BROADCAST} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    83
 *     <td> Allow transmission of broadcast datagrams </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    84
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    85
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    86
 *     <th scope="row"> {@link java.net.StandardSocketOptions#IP_TOS IP_TOS} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    87
 *     <td> The Type of Service (ToS) octet in the Internet Protocol (IP) header </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    88
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    89
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    90
 *     <th scope="row"> {@link java.net.StandardSocketOptions#IP_MULTICAST_IF IP_MULTICAST_IF} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    91
 *     <td> The network interface for Internet Protocol (IP) multicast datagrams </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    92
 *   </tr>
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#IP_MULTICAST_TTL
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
    95
 *       IP_MULTICAST_TTL} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    96
 *     <td> The <em>time-to-live</em> for Internet Protocol (IP) multicast
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    97
 *       datagrams </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    98
 *   </tr>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
    99
 *   <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   100
 *     <th scope="row"> {@link java.net.StandardSocketOptions#IP_MULTICAST_LOOP
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45124
diff changeset
   101
 *       IP_MULTICAST_LOOP} </th>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   102
 *     <td> Loopback for Internet Protocol (IP) multicast datagrams </td>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   103
 *   </tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 32143
diff changeset
   104
 * </tbody>
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   105
 * </table>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   106
 * </blockquote>
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   107
 * Additional (implementation specific) options may also be supported.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   108
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <p> Datagram channels are safe for use by multiple concurrent threads.  They
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * support concurrent reading and writing, though at most one thread may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * reading and at most one thread may be writing at any given time.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * @author JSR-51 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
public abstract class DatagramChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    extends AbstractSelectableChannel
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   120
    implements ByteChannel, ScatteringByteChannel, GatheringByteChannel, MulticastChannel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * 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
   125
     *
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18212
diff changeset
   126
     * @param  provider
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18212
diff changeset
   127
     *         The provider that created this channel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected DatagramChannel(SelectorProvider provider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        super(provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Opens a datagram channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <p> The new channel is created by invoking the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * java.nio.channels.spi.SelectorProvider#openDatagramChannel()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * openDatagramChannel} method of the system-wide default {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * java.nio.channels.spi.SelectorProvider} object.  The channel will not be
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   140
     * connected.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   141
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   142
     * <p> The {@link ProtocolFamily ProtocolFamily} of the channel's socket
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   143
     * is platform (and possibly configuration) dependent and therefore unspecified.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   144
     * The {@link #open(ProtocolFamily) open} allows the protocol family to be
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   145
     * selected when opening a datagram channel, and should be used to open
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   146
     * datagram channels that are intended for Internet Protocol multicasting.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @return  A new datagram channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public static DatagramChannel open() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return SelectorProvider.provider().openDatagramChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   158
     * Opens a datagram channel.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   159
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   160
     * <p> The {@code family} parameter is used to specify the {@link
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18574
diff changeset
   161
     * ProtocolFamily}. If the datagram channel is to be used for IP multicasting
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   162
     * then this should correspond to the address type of the multicast groups
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   163
     * that this channel will join.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   164
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   165
     * <p> The new channel is created by invoking the {@link
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   166
     * java.nio.channels.spi.SelectorProvider#openDatagramChannel(ProtocolFamily)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   167
     * openDatagramChannel} method of the system-wide default {@link
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   168
     * java.nio.channels.spi.SelectorProvider} object.  The channel will not be
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   169
     * connected.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   170
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   171
     * @param   family
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   172
     *          The protocol family
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   173
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   174
     * @return  A new datagram channel
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   175
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   176
     * @throws  UnsupportedOperationException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   177
     *          If the specified protocol family is not supported. For example,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   178
     *          suppose the parameter is specified as {@link
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   179
     *          java.net.StandardProtocolFamily#INET6 StandardProtocolFamily.INET6}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   180
     *          but IPv6 is not enabled on the platform.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   181
     * @throws  IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   182
     *          If an I/O error occurs
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
     * @since   1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   185
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   186
    public static DatagramChannel open(ProtocolFamily family) throws IOException {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   187
        return SelectorProvider.provider().openDatagramChannel(family);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   188
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   189
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   190
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Returns an operation set identifying this channel's supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <p> Datagram channels support reading and writing, so this method
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   195
     * returns {@code (}{@link SelectionKey#OP_READ} {@code |}&nbsp;{@link
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   196
     * SelectionKey#OP_WRITE}{@code )}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return  The valid-operation set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public final int validOps() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return (SelectionKey.OP_READ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                | SelectionKey.OP_WRITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    // -- Socket-specific operations --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   209
     * @throws  AlreadyBoundException               {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   210
     * @throws  UnsupportedAddressTypeException     {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   211
     * @throws  ClosedChannelException              {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   212
     * @throws  IOException                         {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   213
     * @throws  SecurityException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   214
     *          If a security manager has been installed and its {@link
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   215
     *          SecurityManager#checkListen checkListen} method denies the
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   216
     *          operation
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   217
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   218
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   219
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   220
    public abstract DatagramChannel bind(SocketAddress local)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   221
        throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   222
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   223
    /**
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   224
     * @throws  UnsupportedOperationException           {@inheritDoc}
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   225
     * @throws  IllegalArgumentException                {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   226
     * @throws  ClosedChannelException                  {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   227
     * @throws  IOException                             {@inheritDoc}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   228
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   229
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   230
     */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   231
    public abstract <T> DatagramChannel setOption(SocketOption<T> name, T value)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   232
        throws IOException;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   233
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   234
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Retrieves a datagram socket associated with this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <p> The returned object will not declare any public methods that are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * declared in the {@link java.net.DatagramSocket} class.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @return  A datagram socket associated with this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public abstract DatagramSocket socket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   245
     * Tells whether or not this channel's socket is connected.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   247
     * @return  {@code true} if, and only if, this channel's socket
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   248
     *          is {@link #isOpen open} and connected
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public abstract boolean isConnected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Connects this channel's socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <p> The channel's socket is configured so that it only receives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * datagrams from, and sends datagrams to, the given remote <i>peer</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * address.  Once connected, datagrams may not be received from or sent to
59089
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   258
     * any other address.  Datagrams in the channel's {@linkplain
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   259
     * java.net.StandardSocketOptions#SO_RCVBUF socket receive buffer}, which
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   260
     * have not been {@linkplain #receive(ByteBuffer) received} before invoking
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   261
     * this method, may be discarded.  The channel's socket remains connected
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   262
     * until it is explicitly disconnected or until it is closed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <p> This method performs exactly the same security checks as the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * java.net.DatagramSocket#connect connect} method of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * java.net.DatagramSocket} class.  That is, if a security manager has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * installed then this method verifies that its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * java.lang.SecurityManager#checkAccept checkAccept} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * java.lang.SecurityManager#checkConnect checkConnect} methods permit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * datagrams to be received from and sent to, respectively, the given
58501
6fc4a729763e 8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents: 49284
diff changeset
   271
     * remote address. Once connected, no further security checks are performed
6fc4a729763e 8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents: 49284
diff changeset
   272
     * for datagrams received from, or sent to, the given remote address. Care
6fc4a729763e 8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents: 49284
diff changeset
   273
     * should be taken to ensure that a connected datagram channel is not shared
6fc4a729763e 8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents: 49284
diff changeset
   274
     * with untrusted code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
59089
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   276
     * <p> This method may be invoked at any time.  If another thread has
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   277
     * already initiated a read or write operation upon this channel, then an
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   278
     * invocation of this method will block until any such operation is
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   279
     * complete.  If this channel's socket is not bound then this method will
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   280
     * first cause the socket to be bound to an address that is assigned
2427
f35f516befc3 6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents: 2057
diff changeset
   281
     * automatically, as if invoking the {@link #bind bind} method with a
59089
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   282
     * parameter of {@code null}.  </p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param  remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *         The remote address to which this channel is to be connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @return  This datagram channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
49284
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   289
     * @throws  AlreadyConnectedException
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   290
     *          If this channel is already connected
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   291
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @throws  AsynchronousCloseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *          If another thread closes this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *          while the connect operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @throws  ClosedByInterruptException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *          If another thread interrupts the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *          while the connect operation is in progress, thereby
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *          closing the channel and setting the current thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *          interrupt status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
49284
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   305
     * @throws  UnresolvedAddressException
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   306
     *          If the given remote address is not fully resolved
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   307
     *
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   308
     * @throws  UnsupportedAddressTypeException
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   309
     *          If the type of the given remote address is not supported
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   310
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @throws  SecurityException
58803
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   312
     *          If a security manager has been installed and it does not
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   313
     *          permit access to the given remote address, or if unbound,
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   314
     *          the security manager {@link SecurityManager#checkListen checkListen}
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   315
     *          method denies the operation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *          If some other I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public abstract DatagramChannel connect(SocketAddress remote)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Disconnects this channel's socket.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <p> The channel's socket is configured so that it can receive datagrams
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * from, and sends datagrams to, any remote address so long as the security
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * manager, if installed, permits it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
59089
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   330
     * <p> This method may be invoked at any time.  If another thread has
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   331
     * already initiated a read or write operation upon this channel, then an
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   332
     * invocation of this method will block until any such operation is
de56632f796d 8146298: (dc spec) connect and disconnect methods should specify that they may block
bpb
parents: 58803
diff changeset
   333
     * complete.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * <p> If this channel's socket is not connected, or if the channel is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * closed, then invoking this method has no effect.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
58518
705c3f88a409 8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents: 58501
diff changeset
   338
     * @apiNote If this method throws an IOException, the channel's socket
705c3f88a409 8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents: 58501
diff changeset
   339
     * may be left in an unspecified state. It is strongly recommended that
705c3f88a409 8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents: 58501
diff changeset
   340
     * the channel be closed when disconnect fails.
705c3f88a409 8231260: (dc) DatagramChannel::disconnect changes the port of the local address to 0 (lnx)
dfuchs
parents: 58501
diff changeset
   341
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @return  This datagram channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *          If some other I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public abstract DatagramChannel disconnect() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   350
     * 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
   351
     *
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   352
     * @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
   353
     *          connected
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   354
     *
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   355
     * @throws  ClosedChannelException
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   356
     *          If the channel is closed
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   357
     * @throws  IOException
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   358
     *          If an I/O error occurs
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   359
     *
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   360
     * @since 1.7
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   361
     */
2057
3acf8e5e2ca0 6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents: 1247
diff changeset
   362
    public abstract SocketAddress getRemoteAddress() throws IOException;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   363
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 2
diff changeset
   364
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Receives a datagram via this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p> If a datagram is immediately available, or if this channel is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * blocking mode and one eventually becomes available, then the datagram is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * copied into the given byte buffer and its source address is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * If this channel is in non-blocking mode and a datagram is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * immediately available then this method immediately returns
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   372
     * {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * <p> The datagram is transferred into the given byte buffer starting at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * its current position, as if by a regular {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * ReadableByteChannel#read(java.nio.ByteBuffer) read} operation.  If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * are fewer bytes remaining in the buffer than are required to hold the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * datagram then the remainder of the datagram is silently discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * <p> This method performs exactly the same security checks as the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * java.net.DatagramSocket#receive receive} method of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * java.net.DatagramSocket} class.  That is, if the socket is not connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * to a specific remote address and a security manager has been installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * then for each datagram received this method verifies that the source's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * address and port number are permitted by the security manager's {@link
58501
6fc4a729763e 8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents: 49284
diff changeset
   386
     * java.lang.SecurityManager#checkAccept checkAccept} method. Datagrams
6fc4a729763e 8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents: 49284
diff changeset
   387
     * that are not permitted by the security manager are silently discarded.
6fc4a729763e 8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents: 49284
diff changeset
   388
     * The overhead of this security check can be avoided by first connecting
6fc4a729763e 8230946: Clarify security manager behaviour of a connected DatagramSocket and DatagramChannel
pconcannon
parents: 49284
diff changeset
   389
     * the socket via the {@link #connect connect} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * <p> This method may be invoked at any time.  If another thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * already initiated a read operation upon this channel, however, then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * invocation of this method will block until the first operation is
2427
f35f516befc3 6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents: 2057
diff changeset
   394
     * complete. If this channel's socket is not bound then this method will
f35f516befc3 6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents: 2057
diff changeset
   395
     * first cause the socket to be bound to an address that is assigned
f35f516befc3 6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents: 2057
diff changeset
   396
     * automatically, as if invoking the {@link #bind bind} method with a
f35f516befc3 6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents: 2057
diff changeset
   397
     * parameter of {@code null}. </p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @param  dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *         The buffer into which the datagram is to be transferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @return  The datagram's source address,
32143
394ab6a6658d 8133459: replace <tt> tags (obsolete in html5) in java.nio docs
avstepan
parents: 25859
diff changeset
   403
     *          or {@code null} if this channel is in non-blocking mode
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *          and no datagram was immediately available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @throws  AsynchronousCloseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *          If another thread closes this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *          while the read operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @throws  ClosedByInterruptException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *          If another thread interrupts the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *          while the read operation is in progress, thereby
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *          closing the channel and setting the current thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *          interrupt status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
58803
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   419
     * @throws  SecurityException
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   420
     *          If unbound, and a security manager has been installed and
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   421
     *          its {@link SecurityManager#checkListen checkListen} method
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   422
     *          denies the operation
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   423
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *          If some other I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    public abstract SocketAddress receive(ByteBuffer dst) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Sends a datagram via this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * <p> If this channel is in non-blocking mode and there is sufficient room
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * in the underlying output buffer, or if this channel is in blocking mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * and sufficient room becomes available, then the remaining bytes in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * given buffer are transmitted as a single datagram to the given target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * <p> The datagram is transferred from the byte buffer as if by a regular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * {@link WritableByteChannel#write(java.nio.ByteBuffer) write} operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * <p> This method performs exactly the same security checks as the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * java.net.DatagramSocket#send send} method of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * java.net.DatagramSocket} class.  That is, if the socket is not connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * to a specific remote address and a security manager has been installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * then for each datagram sent this method verifies that the target address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * and port number are permitted by the security manager's {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * java.lang.SecurityManager#checkConnect checkConnect} method.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * overhead of this security check can be avoided by first connecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * socket via the {@link #connect connect} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * <p> This method may be invoked at any time.  If another thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * already initiated a write operation upon this channel, however, then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * invocation of this method will block until the first operation is
2427
f35f516befc3 6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents: 2057
diff changeset
   454
     * complete. If this channel's socket is not bound then this method will
f35f516befc3 6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents: 2057
diff changeset
   455
     * first cause the socket to be bound to an address that is assigned
3419
3ae6dc68c20d 6866554: Misc. javadoc warnings
martin
parents: 2427
diff changeset
   456
     * automatically, as if by invoking the {@link #bind bind} method with a
2427
f35f516befc3 6621689: (dc spec) DatagramChannel.receive when channel is not bound is not specified
alanb
parents: 2057
diff changeset
   457
     * parameter of {@code null}. </p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param  src
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *         The buffer containing the datagram to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param  target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *         The address to which the datagram is to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @return   The number of bytes sent, which will be either the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *           of bytes that were remaining in the source buffer when this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *           method was invoked or, if this channel is non-blocking, may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *           zero if there was insufficient room for the datagram in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *           underlying output buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
49284
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   471
     * @throws  AlreadyConnectedException
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   472
     *          If this channel is connected to a different address
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   473
     *          from that specified by {@code target}
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   474
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @throws  AsynchronousCloseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *          If another thread closes this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *          while the read operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @throws  ClosedByInterruptException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *          If another thread interrupts the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *          while the read operation is in progress, thereby
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *          closing the channel and setting the current thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *          interrupt status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
49284
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   488
     * @throws  UnresolvedAddressException
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   489
     *          If the given remote address is not fully resolved
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   490
     *
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   491
     * @throws  UnsupportedAddressTypeException
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   492
     *          If the type of the given remote address is not supported
a51ca91c2cde 8198753: (dc) DatagramChannel throws unspecified exceptions
bpb
parents: 47216
diff changeset
   493
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @throws  SecurityException
58803
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   495
     *          If a security manager has been installed and it does not permit
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   496
     *          datagrams to be sent to the given address, or if unbound, and
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   497
     *          the security manager's {@link SecurityManager#checkListen checkListen}
1bd307ea5497 8231570: (dc) Clarify implicit bind behavior of DatagramChannel
pconcannon
parents: 58518
diff changeset
   498
     *          method denies the operation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *          If some other I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    public abstract int send(ByteBuffer src, SocketAddress target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    // -- ByteChannel operations --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Reads a datagram from this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * <p> This method may only be invoked if this channel's socket is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * connected, and it only accepts datagrams from the socket's peer.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * there are more bytes in the datagram than remain in the given buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * then the remainder of the datagram is silently discarded.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * this method behaves exactly as specified in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * ReadableByteChannel} interface.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *          If this channel's socket is not connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public abstract int read(ByteBuffer dst) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * Reads a datagram from this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <p> This method may only be invoked if this channel's socket is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * connected, and it only accepts datagrams from the socket's peer.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * there are more bytes in the datagram than remain in the given buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * then the remainder of the datagram is silently discarded.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * this method behaves exactly as specified in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * ScatteringByteChannel} interface.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *          If this channel's socket is not connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public abstract long read(ByteBuffer[] dsts, int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * Reads a datagram from this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * <p> This method may only be invoked if this channel's socket is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * connected, and it only accepts datagrams from the socket's peer.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * there are more bytes in the datagram than remain in the given buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * then the remainder of the datagram is silently discarded.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * this method behaves exactly as specified in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * ScatteringByteChannel} interface.  </p>
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's socket is not 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
     * Writes a datagram to this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * <p> This method may only be invoked if this channel's socket is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * connected, in which case it sends datagrams directly to the socket's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * peer.  Otherwise it behaves exactly as specified in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * WritableByteChannel} interface.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *          If this channel's socket is not connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public abstract int write(ByteBuffer src) 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
     * Writes a datagram to this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <p> This method may only be invoked if this channel's socket is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * connected, in which case it sends datagrams directly to the socket's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * peer.  Otherwise it behaves exactly as specified in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * GatheringByteChannel} interface.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @return   The number of bytes sent, which will be either the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *           of bytes that were remaining in the source buffer when this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *           method was invoked or, if this channel is non-blocking, may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *           zero if there was insufficient room for the datagram in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *           underlying output buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *          If this channel's socket is not connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    public abstract long write(ByteBuffer[] srcs, int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Writes a datagram to this channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <p> This method may only be invoked if this channel's socket is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * connected, in which case it sends datagrams directly to the socket's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * peer.  Otherwise it behaves exactly as specified in the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * GatheringByteChannel} interface.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @return   The number of bytes sent, which will be either the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *           of bytes that were remaining in the source buffer when this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *           method was invoked or, if this channel is non-blocking, may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     *           zero if there was insufficient room for the datagram in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *           underlying output buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @throws  NotYetConnectedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *          If this channel's socket is not connected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    public final long write(ByteBuffer[] srcs) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        return write(srcs, 0, srcs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
18212
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   611
    /**
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   612
     * {@inheritDoc}
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   613
     * <p>
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   614
     * If there is a security manager set, its {@code checkConnect} method is
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   615
     * 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
   616
     * 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
   617
     * a {@code SocketAddress} representing the
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   618
     * {@link java.net.InetAddress#getLoopbackAddress loopback} address and the
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   619
     * local port of the channel's socket is returned.
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   620
     *
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   621
     * @return  The {@code SocketAddress} that the socket is bound to, or the
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   622
     *          {@code SocketAddress} representing the loopback address if
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   623
     *          denied by the security manager, or {@code null} if the
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   624
     *          channel's socket is not bound
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   625
     *
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   626
     * @throws  ClosedChannelException     {@inheritDoc}
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   627
     * @throws  IOException                {@inheritDoc}
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   628
     */
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   629
    @Override
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   630
    public abstract SocketAddress getLocalAddress() throws IOException;
22f8c33b0690 8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents: 14342
diff changeset
   631
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
}