com.sun.nio.sctp.SctpChannel Java Examples

The following examples show how to use com.sun.nio.sctp.SctpChannel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SctpChannelImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T> SctpChannel setOption(SctpSocketOption<T> name, T value)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();

        SctpNet.setSocketOption(fdVal, name, value, 0 /*oneToOne*/);
    }
    return this;
}
 
Example #2
Source File: Bind.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
SctpChannel connectChannel(SctpChannel channel)
    throws IOException {
    debug("connecting channel...");
    try {
        SctpServerChannel ssc = SctpServerChannel.open();
        ssc.bind(null);
        Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
        Iterator<SocketAddress> iterator = addrs.iterator();
        SocketAddress addr = iterator.next();
        debug("using " + addr + "...");
        channel.connect(addr);
        SctpChannel peerChannel = ssc.accept();
        ssc.close();
        debug("connected");
        return peerChannel;
    } catch (IOException ioe) {
        debug("Cannot connect channel");
        unexpected(ioe);
        throw ioe;
    }
}
 
Example #3
Source File: SctpChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T> SctpChannel setOption(SctpSocketOption<T> name, T value)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();

        SctpNet.setSocketOption(fdVal, name, value, 0 /*oneToOne*/);
    }
    return this;
}
 
Example #4
Source File: Bind.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
SctpChannel connectChannel(SctpChannel channel)
    throws IOException {
    debug("connecting channel...");
    try {
        SctpServerChannel ssc = SctpServerChannel.open();
        ssc.bind(null);
        Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
        Iterator<SocketAddress> iterator = addrs.iterator();
        SocketAddress addr = iterator.next();
        debug("using " + addr + "...");
        channel.connect(addr);
        SctpChannel peerChannel = ssc.accept();
        ssc.close();
        debug("connected");
        return peerChannel;
    } catch (IOException ioe) {
        debug("Cannot connect channel");
        unexpected(ioe);
        throw ioe;
    }
}
 
Example #5
Source File: SctpChannelImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the channel's socket to a local address.
 */
@Override
public SctpChannel bind(SocketAddress local) throws IOException {
    synchronized (receiveLock) {
        synchronized (sendLock) {
            synchronized (stateLock) {
                ensureOpenAndUnconnected();
                if (isBound())
                    SctpNet.throwAlreadyBoundException();
                InetSocketAddress isa = (local == null) ?
                    new InetSocketAddress(0) : Net.checkAddress(local);
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    sm.checkListen(isa.getPort());
                }
                Net.bind(fd, isa.getAddress(), isa.getPort());
                InetSocketAddress boundIsa = Net.localAddress(fd);
                port = boundIsa.getPort();
                localAddresses.add(isa);
                if (isa.getAddress().isAnyLocalAddress())
                    wildcard = true;
            }
        }
    }
    return this;
}
 
Example #6
Source File: SctpChannelImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T> SctpChannel setOption(SctpSocketOption<T> name, T value)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();

        SctpNet.setSocketOption(fdVal, name, value, 0 /*oneToOne*/);
    }
    return this;
}
 
Example #7
Source File: SctpMultiChannelImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SctpChannel branch(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        FileDescriptor bFd = SctpNet.branch(fdVal,
                                            association.associationID());
        /* successfully branched, we can now remove it from assoc list */
        removeAssociation(association);

        return new SctpChannelImpl(provider(), bFd, association);
    }
}
 
Example #8
Source File: SctpChannelImpl.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <T> SctpChannel setOption(SctpSocketOption<T> name, T value)
        throws IOException {
    if (name == null)
        throw new NullPointerException();
    if (!supportedOptions().contains(name))
        throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();

        SctpNet.setSocketOption(fdVal, name, value, 0 /*oneToOne*/);
    }
    return this;
}
 
Example #9
Source File: NonBlockingAccept.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
void doClient(SocketAddress peerAddress) {
    Set<SctpChannel> channels = new HashSet<SctpChannel>(NUM_TEST_CONNECTIONS);

    try {
        for (int i=0; i<NUM_TEST_CONNECTIONS;) {
            debug("connecting " + ++i);
            channels.add(SctpChannel.open(peerAddress, 0, 0));
            sleep(100);
        }

        /* don't close the channels until they have been accepted */
        acceptLatch.await();

        for(SctpChannel sc: channels)
            sc.close();
    } catch (IOException ioe) {
        unexpected(ioe);
    } catch (InterruptedException ie) {
        unexpected(ie);
    }
}
 
Example #10
Source File: SctpChannelImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the channel's socket to a local address.
 */
@Override
public SctpChannel bind(SocketAddress local) throws IOException {
    synchronized (receiveLock) {
        synchronized (sendLock) {
            synchronized (stateLock) {
                ensureOpenAndUnconnected();
                if (isBound())
                    SctpNet.throwAlreadyBoundException();
                InetSocketAddress isa = (local == null) ?
                    new InetSocketAddress(0) : Net.checkAddress(local);
                SecurityManager sm = System.getSecurityManager();
                if (sm != null) {
                    sm.checkListen(isa.getPort());
                }
                Net.bind(fd, isa.getAddress(), isa.getPort());
                InetSocketAddress boundIsa = Net.localAddress(fd);
                port = boundIsa.getPort();
                localAddresses.add(isa);
                if (isa.getAddress().isAnyLocalAddress())
                    wildcard = true;
            }
        }
    }
    return this;
}
 
Example #11
Source File: NioSctpChannel.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new instance
 *
 * @param parent        the {@link Channel} which is the parent of this {@link NioSctpChannel}
 *                      or {@code null}.
 * @param sctpChannel   the underlying {@link SctpChannel}
 */
public NioSctpChannel(Channel parent, SctpChannel sctpChannel) {
    super(parent, sctpChannel, SelectionKey.OP_READ);
    try {
        sctpChannel.configureBlocking(false);
        config = new NioSctpChannelConfig(this, sctpChannel);
        notificationHandler = new SctpNotificationHandler(this);
    } catch (IOException e) {
        try {
            sctpChannel.close();
        } catch (IOException e2) {
            if (logger.isWarnEnabled()) {
                logger.warn(
                        "Failed to close a partially initialized sctp channel.", e2);
            }
        }

        throw new ChannelException("Failed to enter non-blocking mode.", e);
    }
}
 
Example #12
Source File: NonBlockingAccept.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
void doClient(SocketAddress peerAddress) {
    Set<SctpChannel> channels = new HashSet<SctpChannel>(NUM_TEST_CONNECTIONS);

    try {
        for (int i=0; i<NUM_TEST_CONNECTIONS;) {
            debug("connecting " + ++i);
            channels.add(SctpChannel.open(peerAddress, 0, 0));
            sleep(100);
        }

        /* don't close the channels until they have been accepted */
        acceptLatch.await();

        for(SctpChannel sc: channels)
            sc.close();
    } catch (IOException ioe) {
        unexpected(ioe);
    } catch (InterruptedException ie) {
        unexpected(ie);
    }
}
 
Example #13
Source File: SctpMultiChannelImpl.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SctpChannel branch(Association association)
        throws IOException {
    synchronized (stateLock) {
        checkAssociation(association);
        if (!isOpen())
            throw new ClosedChannelException();

        FileDescriptor bFd = SctpNet.branch(fdVal,
                                            association.associationID());
        /* successfully branched, we can now remove it from assoc list */
        removeAssociation(association);

        return new SctpChannelImpl(provider(), bFd, association);
    }
}
 
Example #14
Source File: NonBlockingAccept.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void doClient(SocketAddress peerAddress) {
    Set<SctpChannel> channels = new HashSet<SctpChannel>(NUM_TEST_CONNECTIONS);

    try {
        for (int i=0; i<NUM_TEST_CONNECTIONS;) {
            debug("connecting " + ++i);
            channels.add(SctpChannel.open(peerAddress, 0, 0));
            sleep(100);
        }

        /* don't close the channels until they have been accepted */
        acceptLatch.await();

        for(SctpChannel sc: channels)
            sc.close();
    } catch (IOException ioe) {
        unexpected(ioe);
    } catch (InterruptedException ie) {
        unexpected(ie);
    }
}
 
Example #15
Source File: Bind.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
SctpChannel connectChannel(SctpChannel channel)
    throws IOException {
    debug("connecting channel...");
    try {
        SctpServerChannel ssc = SctpServerChannel.open();
        ssc.bind(null);
        Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
        Iterator<SocketAddress> iterator = addrs.iterator();
        SocketAddress addr = iterator.next();
        debug("using " + addr + "...");
        channel.connect(addr);
        SctpChannel peerChannel = ssc.accept();
        ssc.close();
        debug("connected");
        return peerChannel;
    } catch (IOException ioe) {
        debug("Cannot connect channel");
        unexpected(ioe);
        throw ioe;
    }
}
 
Example #16
Source File: Util.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static boolean isSCTPSupported() {
    try {
        SctpChannel c = SctpChannel.open();
        c.close();
        return true;
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (UnsupportedOperationException e) {
        out.println(e);
    }

    return false;
}
 
Example #17
Source File: SocketOptionTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
<T> void optionalSupport(SctpChannel sc, SctpSocketOption<T> name,
        T value) {
    try {
        sc.setOption(name, value);
        checkOption(sc, name, value);
    } catch (IOException e) {
        /* Informational only, not all options have native support */
        out.println(name + " not supported. " + e);
    }
}
 
Example #18
Source File: Util.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static boolean isSCTPSupported() {
    try {
        SctpChannel c = SctpChannel.open();
        c.close();
        return true;
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (UnsupportedOperationException e) {
        out.println(e);
    }

    return false;
}
 
Example #19
Source File: SctpChannelImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SctpChannel shutdown() throws IOException {
    synchronized(stateLock) {
        if (isShutdown)
            return this;

        ensureSendOpen();
        SctpNet.shutdown(fdVal, -1);
        if (senderThread != 0)
            NativeThread.signal(senderThread);
        isShutdown = true;
    }
    return this;
}
 
Example #20
Source File: SctpChannelImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SctpChannel shutdown() throws IOException {
    synchronized(stateLock) {
        if (isShutdown)
            return this;

        ensureSendOpen();
        SctpNet.shutdown(fdVal, -1);
        if (senderThread != 0)
            NativeThread.signal(senderThread);
        isShutdown = true;
    }
    return this;
}
 
Example #21
Source File: SocketOptionTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
<T> void optionalSupport(SctpChannel sc, SctpSocketOption<T> name,
        T value) {
    try {
        sc.setOption(name, value);
        checkOption(sc, name, value);
    } catch (IOException e) {
        /* Informational only, not all options have native support */
        out.println(name + " not supported. " + e);
    }
}
 
Example #22
Source File: Bind.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
boolean boundAddress(SctpChannel channel, InetAddress addr)
    throws IOException {
    for (SocketAddress boundAddr : channel.getAllLocalAddresses()) {
        if (((InetSocketAddress) boundAddr).getAddress().equals(addr))
            return true;
    }
    return false;
}
 
Example #23
Source File: SocketOptionTests.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
<T> void optionalSupport(SctpChannel sc, SctpSocketOption<T> name,
        T value) {
    try {
        sc.setOption(name, value);
        checkOption(sc, name, value);
    } catch (IOException e) {
        /* Informational only, not all options have native support */
        out.println(name + " not supported. " + e);
    }
}
 
Example #24
Source File: Bind.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
boolean boundAddress(SctpChannel channel, InetAddress addr)
    throws IOException {
    for (SocketAddress boundAddr : channel.getAllLocalAddresses()) {
        if (((InetSocketAddress) boundAddr).getAddress().equals(addr))
            return true;
    }
    return false;
}
 
Example #25
Source File: Util.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static boolean isSCTPSupported() {
    try {
        SctpChannel c = SctpChannel.open();
        c.close();
        return true;
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (UnsupportedOperationException e) {
        out.println(e);
    }

    return false;
}
 
Example #26
Source File: Util.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static boolean isSCTPSupported() {
    try {
        SctpChannel c = SctpChannel.open();
        c.close();
        return true;
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (UnsupportedOperationException e) {
        out.println(e);
    }

    return false;
}
 
Example #27
Source File: OioSctpChannel.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static SctpChannel openChannel() {
    try {
        return SctpChannel.open();
    } catch (IOException e) {
        throw new ChannelException("Failed to open a sctp channel.", e);
    }
}
 
Example #28
Source File: SctpTransferTest.java    From sctp with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @return true if sctp is supported by this OS and false in not
 */
public static boolean checkSctpEnabled() {
	try {
		SctpChannel socketChannel = SctpChannel.open();
		socketChannel.close();
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
Example #29
Source File: NioSctpChannel.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static SctpChannel newSctpChannel() {
    try {
        return SctpChannel.open();
    } catch (IOException e) {
        throw new ChannelException("Failed to open a sctp channel.", e);
    }
}
 
Example #30
Source File: Util.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static boolean isSCTPSupported() {
    try {
        SctpChannel c = SctpChannel.open();
        c.close();
        return true;
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (UnsupportedOperationException e) {
        out.println(e);
    }

    return false;
}