< prev index next >

src/java.base/share/classes/java/nio/channels/AsynchronousSocketChannel.java

Print this page




  45  * pre-existing {@link java.net.Socket socket}.
  46  *
  47  * <p> A newly-created channel is connected by invoking its {@link #connect connect}
  48  * method; once connected, a channel remains connected until it is closed.  Whether
  49  * or not a socket channel is connected may be determined by invoking its {@link
  50  * #getRemoteAddress getRemoteAddress} method. An attempt to invoke an I/O
  51  * operation upon an unconnected channel will cause a {@link NotYetConnectedException}
  52  * to be thrown.
  53  *
  54  * <p> Channels of this type are safe for use by multiple concurrent threads.
  55  * They support concurrent reading and writing, though at most one read operation
  56  * and one write operation can be outstanding at any time.
  57  * If a thread initiates a read operation before a previous read operation has
  58  * completed then a {@link ReadPendingException} will be thrown. Similarly, an
  59  * attempt to initiate a write operation before a previous write has completed
  60  * will throw a {@link WritePendingException}.
  61  *
  62  * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
  63  * setOption} method. Asynchronous socket channels support the following options:
  64  * <blockquote>
  65  * <table border summary="Socket options">


  66  *   <tr>
  67  *     <th>Option Name</th>
  68  *     <th>Description</th>
  69  *   </tr>


  70  *   <tr>
  71  *     <td> {@link java.net.StandardSocketOptions#SO_SNDBUF SO_SNDBUF} </td>
  72  *     <td> The size of the socket send buffer </td>
  73  *   </tr>
  74  *   <tr>
  75  *     <td> {@link java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF} </td>
  76  *     <td> The size of the socket receive buffer </td>
  77  *   </tr>
  78  *   <tr>
  79  *     <td> {@link java.net.StandardSocketOptions#SO_KEEPALIVE SO_KEEPALIVE} </td>
  80  *     <td> Keep connection alive </td>
  81  *   </tr>
  82  *   <tr>
  83  *     <td> {@link java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} </td>
  84  *     <td> Re-use address </td>
  85  *   </tr>
  86  *   <tr>
  87  *     <td> {@link java.net.StandardSocketOptions#TCP_NODELAY TCP_NODELAY} </td>
  88  *     <td> Disable the Nagle algorithm </td>
  89  *   </tr>

  90  * </table>
  91  * </blockquote>
  92  * Additional (implementation specific) options may also be supported.
  93  *
  94  * <h2>Timeouts</h2>
  95  *
  96  * <p> The {@link #read(ByteBuffer,long,TimeUnit,Object,CompletionHandler) read}
  97  * and {@link #write(ByteBuffer,long,TimeUnit,Object,CompletionHandler) write}
  98  * methods defined by this class allow a timeout to be specified when initiating
  99  * a read or write operation. If the timeout elapses before an operation completes
 100  * then the operation completes with the exception {@link
 101  * InterruptedByTimeoutException}. A timeout may leave the channel, or the
 102  * underlying connection, in an inconsistent state. Where the implementation
 103  * cannot guarantee that bytes have not been read from the channel then it puts
 104  * the channel into an implementation specific <em>error state</em>. A subsequent
 105  * attempt to initiate a {@code read} operation causes an unspecified runtime
 106  * exception to be thrown. Similarly if a {@code write} operation times out and
 107  * the implementation cannot guarantee bytes have not been written to the
 108  * channel then further attempts to {@code write} to the channel cause an
 109  * unspecified runtime exception to be thrown. When a timeout elapses then the




  45  * pre-existing {@link java.net.Socket socket}.
  46  *
  47  * <p> A newly-created channel is connected by invoking its {@link #connect connect}
  48  * method; once connected, a channel remains connected until it is closed.  Whether
  49  * or not a socket channel is connected may be determined by invoking its {@link
  50  * #getRemoteAddress getRemoteAddress} method. An attempt to invoke an I/O
  51  * operation upon an unconnected channel will cause a {@link NotYetConnectedException}
  52  * to be thrown.
  53  *
  54  * <p> Channels of this type are safe for use by multiple concurrent threads.
  55  * They support concurrent reading and writing, though at most one read operation
  56  * and one write operation can be outstanding at any time.
  57  * If a thread initiates a read operation before a previous read operation has
  58  * completed then a {@link ReadPendingException} will be thrown. Similarly, an
  59  * attempt to initiate a write operation before a previous write has completed
  60  * will throw a {@link WritePendingException}.
  61  *
  62  * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
  63  * setOption} method. Asynchronous socket channels support the following options:
  64  * <blockquote>
  65  * <table class="altrows">
  66  * <caption style="display:none">Socket options</caption>
  67  * <thead>
  68  *   <tr>
  69  *     <th>Option Name</th>
  70  *     <th>Description</th>
  71  *   </tr>
  72  * </thead>
  73  * <tbody>
  74  *   <tr>
  75  *     <td> {@link java.net.StandardSocketOptions#SO_SNDBUF SO_SNDBUF} </td>
  76  *     <td> The size of the socket send buffer </td>
  77  *   </tr>
  78  *   <tr>
  79  *     <td> {@link java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF} </td>
  80  *     <td> The size of the socket receive buffer </td>
  81  *   </tr>
  82  *   <tr>
  83  *     <td> {@link java.net.StandardSocketOptions#SO_KEEPALIVE SO_KEEPALIVE} </td>
  84  *     <td> Keep connection alive </td>
  85  *   </tr>
  86  *   <tr>
  87  *     <td> {@link java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} </td>
  88  *     <td> Re-use address </td>
  89  *   </tr>
  90  *   <tr>
  91  *     <td> {@link java.net.StandardSocketOptions#TCP_NODELAY TCP_NODELAY} </td>
  92  *     <td> Disable the Nagle algorithm </td>
  93  *   </tr>
  94  * </tbody>
  95  * </table>
  96  * </blockquote>
  97  * Additional (implementation specific) options may also be supported.
  98  *
  99  * <h2>Timeouts</h2>
 100  *
 101  * <p> The {@link #read(ByteBuffer,long,TimeUnit,Object,CompletionHandler) read}
 102  * and {@link #write(ByteBuffer,long,TimeUnit,Object,CompletionHandler) write}
 103  * methods defined by this class allow a timeout to be specified when initiating
 104  * a read or write operation. If the timeout elapses before an operation completes
 105  * then the operation completes with the exception {@link
 106  * InterruptedByTimeoutException}. A timeout may leave the channel, or the
 107  * underlying connection, in an inconsistent state. Where the implementation
 108  * cannot guarantee that bytes have not been read from the channel then it puts
 109  * the channel into an implementation specific <em>error state</em>. A subsequent
 110  * attempt to initiate a {@code read} operation causes an unspecified runtime
 111  * exception to be thrown. Similarly if a {@code write} operation times out and
 112  * the implementation cannot guarantee bytes have not been written to the
 113  * channel then further attempts to {@code write} to the channel cause an
 114  * unspecified runtime exception to be thrown. When a timeout elapses then the


< prev index next >