0N/A/*
2362N/A * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/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
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
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
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A */
0N/A
0N/Apackage sun.nio.ch;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.io.FileDescriptor;
0N/Aimport java.nio.ByteBuffer;
0N/Aimport java.nio.channels.*;
0N/Aimport java.nio.channels.spi.*;
0N/A
0N/A/**
0N/A * Pipe.SourceChannel implementation based on socket connection.
0N/A */
0N/A
0N/Aclass SourceChannelImpl
0N/A extends Pipe.SourceChannel
0N/A implements SelChImpl
0N/A{
0N/A // The SocketChannel assoicated with this pipe
0N/A SocketChannel sc;
0N/A
0N/A public FileDescriptor getFD() {
0N/A return ((SocketChannelImpl) sc).getFD();
0N/A }
0N/A
0N/A public int getFDVal() {
0N/A return ((SocketChannelImpl) sc).getFDVal();
0N/A }
0N/A
0N/A SourceChannelImpl(SelectorProvider sp, SocketChannel sc) {
0N/A super(sp);
0N/A this.sc = sc;
0N/A }
0N/A
0N/A protected void implCloseSelectableChannel() throws IOException {
0N/A if (!isRegistered())
0N/A kill();
0N/A }
0N/A
0N/A public void kill() throws IOException {
0N/A sc.close();
0N/A }
0N/A
0N/A protected void implConfigureBlocking(boolean block) throws IOException {
0N/A sc.configureBlocking(block);
0N/A }
0N/A
0N/A public boolean translateReadyOps(int ops, int initialOps,
0N/A SelectionKeyImpl sk) {
0N/A int intOps = sk.nioInterestOps(); // Do this just once, it synchronizes
0N/A int oldOps = sk.nioReadyOps();
0N/A int newOps = initialOps;
0N/A
0N/A if ((ops & PollArrayWrapper.POLLNVAL) != 0)
0N/A throw new Error("POLLNVAL detected");
0N/A
0N/A if ((ops & (PollArrayWrapper.POLLERR
0N/A | PollArrayWrapper.POLLHUP)) != 0) {
0N/A newOps = intOps;
0N/A sk.nioReadyOps(newOps);
0N/A return (newOps & ~oldOps) != 0;
0N/A }
0N/A
0N/A if (((ops & PollArrayWrapper.POLLIN) != 0) &&
0N/A ((intOps & SelectionKey.OP_READ) != 0))
0N/A newOps |= SelectionKey.OP_READ;
0N/A
0N/A sk.nioReadyOps(newOps);
0N/A return (newOps & ~oldOps) != 0;
0N/A }
0N/A
0N/A public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk) {
0N/A return translateReadyOps(ops, sk.nioReadyOps(), sk);
0N/A }
0N/A
0N/A public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk) {
0N/A return translateReadyOps(ops, 0, sk);
0N/A }
0N/A
0N/A public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) {
0N/A if ((ops & SelectionKey.OP_READ) != 0)
0N/A ops = PollArrayWrapper.POLLIN;
0N/A sk.selector.putEventOps(sk, ops);
0N/A }
0N/A
0N/A public int read(ByteBuffer dst) throws IOException {
0N/A try {
0N/A return sc.read(dst);
0N/A } catch (AsynchronousCloseException x) {
0N/A close();
0N/A throw x;
0N/A }
0N/A }
0N/A
0N/A public long read(ByteBuffer[] dsts, int offset, int length)
0N/A throws IOException
0N/A {
0N/A if ((offset < 0) || (length < 0) || (offset > dsts.length - length))
0N/A throw new IndexOutOfBoundsException();
0N/A try {
0N/A return read(Util.subsequence(dsts, offset, length));
0N/A } catch (AsynchronousCloseException x) {
0N/A close();
0N/A throw x;
0N/A }
0N/A }
0N/A
0N/A public long read(ByteBuffer[] dsts) throws IOException {
0N/A try {
0N/A return sc.read(dsts);
0N/A } catch (AsynchronousCloseException x) {
0N/A close();
0N/A throw x;
0N/A }
0N/A }
0N/A
0N/A}