Search in sources :

Example 1 with NotYetBoundException

use of java.nio.channels.NotYetBoundException in project robovm by robovm.

the class NotYetBoundExceptionTest method test_Constructor.

/**
     * @tests {@link java.nio.channels.NotYetBoundException#NotYetBoundException()}
     */
public void test_Constructor() {
    NotYetBoundException e = new NotYetBoundException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
Also used : NotYetBoundException(java.nio.channels.NotYetBoundException)

Example 2 with NotYetBoundException

use of java.nio.channels.NotYetBoundException in project jdk8u_jdk by JetBrains.

the class SctpMultiChannelImpl method receive.

@Override
public <T> MessageInfo receive(ByteBuffer buffer, T attachment, NotificationHandler<T> handler) throws IOException {
    if (buffer == null)
        throw new IllegalArgumentException("buffer cannot be null");
    if (buffer.isReadOnly())
        throw new IllegalArgumentException("Read-only buffer");
    if (receiveInvoked.get())
        throw new IllegalReceiveException("cannot invoke receive from handler");
    receiveInvoked.set(Boolean.TRUE);
    try {
        ResultContainer resultContainer = new ResultContainer();
        do {
            resultContainer.clear();
            synchronized (receiveLock) {
                ensureOpen();
                if (!isBound())
                    throw new NotYetBoundException();
                int n = 0;
                try {
                    begin();
                    synchronized (stateLock) {
                        if (!isOpen())
                            return null;
                        receiverThread = NativeThread.current();
                    }
                    do {
                        n = receive(fdVal, buffer, resultContainer);
                    } while ((n == IOStatus.INTERRUPTED) && isOpen());
                } finally {
                    receiverCleanup();
                    end((n > 0) || (n == IOStatus.UNAVAILABLE));
                    assert IOStatus.check(n);
                }
                if (!resultContainer.isNotification()) {
                    /* message or nothing */
                    if (resultContainer.hasSomething()) {
                        /* Set the association before returning */
                        MessageInfoImpl info = resultContainer.getMessageInfo();
                        info.setAssociation(lookupAssociation(info.associationID()));
                        SecurityManager sm = System.getSecurityManager();
                        if (sm != null) {
                            InetSocketAddress isa = (InetSocketAddress) info.address();
                            if (!addressMap.containsKey(isa)) {
                                /* must be a new association */
                                try {
                                    sm.checkAccept(isa.getAddress().getHostAddress(), isa.getPort());
                                } catch (SecurityException se) {
                                    buffer.clear();
                                    throw se;
                                }
                            }
                        }
                        assert info.association() != null;
                        return info;
                    } else {
                        /* Non-blocking may return null if nothing available*/
                        return null;
                    }
                } else {
                    /* notification */
                    synchronized (stateLock) {
                        handleNotificationInternal(resultContainer);
                    }
                }
            }
        /* receiveLock */
        } while (handler == null ? true : (invokeNotificationHandler(resultContainer, handler, attachment) == HandlerResult.CONTINUE));
    } finally {
        receiveInvoked.set(Boolean.FALSE);
    }
    return null;
}
Also used : NotYetBoundException(java.nio.channels.NotYetBoundException) IllegalReceiveException(com.sun.nio.sctp.IllegalReceiveException) InetSocketAddress(java.net.InetSocketAddress) ResultContainer(sun.nio.ch.sctp.ResultContainer)

Example 3 with NotYetBoundException

use of java.nio.channels.NotYetBoundException in project jdk8u_jdk by JetBrains.

the class SctpServerChannelImpl method accept.

@Override
public SctpChannel accept() throws IOException {
    synchronized (lock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (!isBound())
            throw new NotYetBoundException();
        SctpChannel sc = null;
        int n = 0;
        FileDescriptor newfd = new FileDescriptor();
        InetSocketAddress[] isaa = new InetSocketAddress[1];
        try {
            begin();
            if (!isOpen())
                return null;
            thread = NativeThread.current();
            for (; ; ) {
                n = accept0(fd, newfd, isaa);
                if ((n == IOStatus.INTERRUPTED) && isOpen())
                    continue;
                break;
            }
        } finally {
            acceptCleanup();
            end(n > 0);
            assert IOStatus.check(n);
        }
        if (n < 1)
            return null;
        IOUtil.configureBlocking(newfd, true);
        InetSocketAddress isa = isaa[0];
        sc = new SctpChannelImpl(provider(), newfd);
        SecurityManager sm = System.getSecurityManager();
        if (sm != null)
            sm.checkAccept(isa.getAddress().getHostAddress(), isa.getPort());
        return sc;
    }
}
Also used : NotYetBoundException(java.nio.channels.NotYetBoundException) ClosedChannelException(java.nio.channels.ClosedChannelException) SctpChannel(com.sun.nio.sctp.SctpChannel) InetSocketAddress(java.net.InetSocketAddress) FileDescriptor(java.io.FileDescriptor)

Aggregations

NotYetBoundException (java.nio.channels.NotYetBoundException)3 InetSocketAddress (java.net.InetSocketAddress)2 IllegalReceiveException (com.sun.nio.sctp.IllegalReceiveException)1 SctpChannel (com.sun.nio.sctp.SctpChannel)1 FileDescriptor (java.io.FileDescriptor)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ResultContainer (sun.nio.ch.sctp.ResultContainer)1