Path: blob/master/src/java.base/share/classes/sun/nio/ch/SelectorProviderImpl.java
41159 views
/*1* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.nio.ch;2627import java.io.IOException;28import java.net.ProtocolFamily;29import java.nio.channels.DatagramChannel;30import java.nio.channels.Pipe;31import java.nio.channels.ServerSocketChannel;32import java.nio.channels.SocketChannel;33import java.nio.channels.spi.AbstractSelector;34import java.nio.channels.spi.SelectorProvider;35import java.util.Objects;36import static java.net.StandardProtocolFamily.INET;37import static java.net.StandardProtocolFamily.INET6;38import static java.net.StandardProtocolFamily.UNIX;3940public abstract class SelectorProviderImpl41extends SelectorProvider42{43@Override44public DatagramChannel openDatagramChannel() throws IOException {45return new DatagramChannelImpl(this, /*interruptible*/true);46}4748/**49* SelectorProviderImpl specific method to create a DatagramChannel that50* is not interruptible.51*/52public DatagramChannel openUninterruptibleDatagramChannel() throws IOException {53return new DatagramChannelImpl(this, /*interruptible*/false);54}5556@Override57public DatagramChannel openDatagramChannel(ProtocolFamily family) throws IOException {58return new DatagramChannelImpl(this, family, /*interruptible*/true);59}6061@Override62public Pipe openPipe() throws IOException {63return new PipeImpl(this);64}6566@Override67public abstract AbstractSelector openSelector() throws IOException;6869@Override70public ServerSocketChannel openServerSocketChannel() throws IOException {71return new ServerSocketChannelImpl(this);72}7374@Override75public SocketChannel openSocketChannel() throws IOException {76return new SocketChannelImpl(this);77}7879@Override80public SocketChannel openSocketChannel(ProtocolFamily family) throws IOException {81Objects.requireNonNull(family, "'family' is null");82if (family == INET6 && !Net.isIPv6Available()) {83throw new UnsupportedOperationException("IPv6 not available");84} else if (family == INET || family == INET6) {85return new SocketChannelImpl(this, family);86} else if (family == UNIX && UnixDomainSockets.isSupported()) {87return new SocketChannelImpl(this, family);88} else {89throw new UnsupportedOperationException("Protocol family not supported");90}91}9293@Override94public ServerSocketChannel openServerSocketChannel(ProtocolFamily family) throws IOException {95Objects.requireNonNull(family, "'family' is null");96if (family == INET6 && !Net.isIPv6Available()) {97throw new UnsupportedOperationException("IPv6 not available");98} else if (family == INET || family == INET6) {99return new ServerSocketChannelImpl(this, family);100} else if (family == UNIX && UnixDomainSockets.isSupported()) {101return new ServerSocketChannelImpl(this, family);102} else {103throw new UnsupportedOperationException("Protocol family not supported");104}105}106}107108109