3909N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. 893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 893N/A * This code is free software; you can redistribute it and/or modify it 893N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 893N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 893N/A * This code is distributed in the hope that it will be useful, but WITHOUT 893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 893N/A * version 2 for more details (a copy is included in the LICENSE file that 893N/A * accompanied this code). 893N/A * You should have received a copy of the GNU General Public License version 893N/A * 2 along with this work; if not, write to the Free Software Foundation, 954N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 893N/A * Windows implementation of AsynchronousSocketChannel using overlapped I/O. 893N/A * typedef struct _WSABUF { 893N/A // socket handle. Use begin()/end() around each usage of this handle. 893N/A // I/O completion port that the socket is associated with 893N/A // completion key to identify channel when I/O completes 893N/A // Pending I/O operations are tied to an OVERLAPPED structure that can only 893N/A // be released when the I/O completion event is posted to the completion 893N/A // port. Where I/O operations complete immediately then it is possible 893N/A // there may be more than two OVERLAPPED structures in use. 893N/A // per-channel arrays of WSABUF structures 893N/A // associate socket with default completion port 893N/A // allocate WSABUF arrays 893N/A * Invoked by Iocp when an I/O operation competes. 893N/A // invoked by WindowsAsynchronousServerSocketChannelImpl 893N/A // invoked by WindowsAsynchronousServerSocketChannelImpl when new connection 893N/A // close socket (may cause outstanding async I/O operations to fail). 893N/A // waits until all I/O operations have completed 893N/A // release arrays of WSABUF structures 893N/A // finally disassociate from the completion port (key can be 0 if 893N/A // channel created when group is shutdown) 893N/A * Implements the task to initiate a connection and the handler to 893N/A * consume the result when the connection is established (or fails). 893N/A * Invoke after a connection is successfully established. 893N/A * Task to initiate a connection. 893N/A // synchronize on result to allow this thread handle the case 893N/A // where the connection is established immediately. 893N/A // initiate the connection 893N/A // connection is pending 893N/A // connection established immediately 893N/A * Invoked by handler thread when connection established. 893N/A // channel is closed or unable to finish connect 893N/A * Invoked by handler thread when failed to establish connection. 893N/A // check and update state 893N/A // ConnectEx requires the socket to be bound to a local address 893N/A * Implements the task to initiate a read and the handler to consume the 893N/A * result when the read completes. 893N/A * Invoked prior to read to prepare the WSABUF array. Where necessary, 893N/A * it substitutes non-direct buffers with direct buffers. 893N/A // substitute with direct buffer 893N/A * Invoked after a read has completed to update the buffer positions 893N/A * and release any substituted buffers. 893N/A // position changed by another 893N/A }
else {
// Buffers not completely filled 893N/A // position changed by another 893N/A // Put results from shadow into the slow buffers 893N/A // position changed by another 893N/A // substitute non-direct buffers 893N/A // get an OVERLAPPED structure (from the cache or allocate) 1191N/A // reset read flag before releasing waiters 1191N/A // release resources if I/O not pending 893N/A // invoke completion handler 893N/A * Executed when the I/O has completed 893N/A // return direct buffer to cache if substituted 893N/A // release waiters if not already released by timeout 893N/A // return direct buffer to cache if substituted 893N/A // release waiters if not already released by timeout 893N/A * Invoked if timeout expires before it is cancelled 893N/A // kill further reading before releasing waiters 893N/A // invoke handler without any locks 893N/A * Implements the task to initiate a write and the handler to consume the 893N/A * result when the write completes. 893N/A * Invoked prior to write to prepare the WSABUF array. Where necessary, 893N/A * it substitutes non-direct buffers with direct buffers. 893N/A // substitute with direct buffer 893N/A * Invoked after a write has completed to update the buffer positions 893N/A * and release any substituted buffers. 893N/A // Notify the buffers how many bytes were taken 893N/A // position changed by someone else 893N/A }
else {
// Buffers not completely filled 893N/A // position changed by someone else 1580N/A //@SuppressWarnings("unchecked") 893N/A // substitute non-direct buffers 893N/A // get an OVERLAPPED structure (from the cache or allocate) 1191N/A // special case for shutdown output 1191N/A // write completed immediately 1191N/A // write failed. Enable writing before releasing waiters. 1191N/A // release resources if I/O not pending 893N/A // invoke completion handler 893N/A * Executed when the I/O has completed 893N/A // return direct buffer to cache if substituted 893N/A // release waiters if not already released by timeout 893N/A // return direct buffer to cache if substituted 893N/A // release waiters if not already released by timeout 893N/A * Invoked if timeout expires before it is cancelled 893N/A // kill further writing before releasing waiters 893N/A // invoke handler without any locks 893N/A // initiate I/O (can only be done from thread in thread pool) 893N/A // -- Native methods --