java.nio.channels.UnsupportedAddressTypeException#java.nio.channels.AlreadyConnectedException源码实例Demo

下面列出了java.nio.channels.UnsupportedAddressTypeException#java.nio.channels.AlreadyConnectedException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netty-4.1.22   文件: SocketMultipleConnectTest.java
public void testMultipleConnect(ServerBootstrap sb, Bootstrap cb) throws Exception {
    Channel sc = null;
    Channel cc = null;
    try {
        sb.childHandler(new ChannelInboundHandlerAdapter());
        sc = sb.bind(NetUtil.LOCALHOST, 0).syncUninterruptibly().channel();

        cb.handler(new ChannelInboundHandlerAdapter());
        cc = cb.register().syncUninterruptibly().channel();
        cc.connect(sc.localAddress()).syncUninterruptibly();
        ChannelFuture connectFuture2 = cc.connect(sc.localAddress()).await();
        assertTrue(connectFuture2.cause() instanceof AlreadyConnectedException);
    } finally {
        if (cc != null) {
            cc.close();
        }
        if (sc != null) {
            sc.close();
        }
    }
}
 
源代码2 项目: netty-4.1.22   文件: Errors.java
static void throwConnectException(String method, NativeConnectException refusedCause, int err)
        throws IOException {
    if (err == refusedCause.expectedErr()) {
        throw refusedCause;
    }
    if (err == ERROR_EALREADY_NEGATIVE) {
        throw new ConnectionPendingException();
    }
    if (err == ERROR_ENETUNREACH_NEGATIVE) {
        throw new NoRouteToHostException();
    }
    if (err == ERROR_EISCONN_NEGATIVE) {
        throw new AlreadyConnectedException();
    }
    if (err == ERRNO_ENOENT_NEGATIVE) {
        throw new FileNotFoundException();
    }
    throw new ConnectException(method + "(..) failed: " + ERRORS[-err]);
}
 
源代码3 项目: dragonwell8_jdk   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码4 项目: netty-4.1.22   文件: AbstractKQueueChannel.java
/**
 * Connect to the remote peer
 */
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
    if (localAddress instanceof InetSocketAddress) {
        checkResolvable((InetSocketAddress) localAddress);
    }

    InetSocketAddress remoteSocketAddr = remoteAddress instanceof InetSocketAddress
            ? (InetSocketAddress) remoteAddress : null;
    if (remoteSocketAddr != null) {
        checkResolvable(remoteSocketAddr);
    }

    if (remote != null) {
        // Check if already connected before trying to connect. This is needed as connect(...) will not return -1
        // and set errno to EISCONN if a previous connect(...) attempt was setting errno to EINPROGRESS and finished
        // later.
        throw new AlreadyConnectedException();
    }

    if (localAddress != null) {
        socket.bind(localAddress);
    }

    boolean connected = doConnect0(remoteAddress);
    if (connected) {
        remote = remoteSocketAddr == null ?
                remoteAddress : computeRemoteAddr(remoteSocketAddr, socket.remoteAddress());
    }
    // We always need to set the localAddress even if not connected yet as the bind already took place.
    //
    // See https://github.com/netty/netty/issues/3463
    local = socket.localAddress();
    return connected;
}
 
源代码5 项目: netty-4.1.22   文件: AbstractEpollChannel.java
/**
 * Connect to the remote peer
 */
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
    if (localAddress instanceof InetSocketAddress) {
        checkResolvable((InetSocketAddress) localAddress);
    }

    InetSocketAddress remoteSocketAddr = remoteAddress instanceof InetSocketAddress
            ? (InetSocketAddress) remoteAddress : null;
    if (remoteSocketAddr != null) {
        checkResolvable(remoteSocketAddr);
    }

    if (remote != null) {
        // Check if already connected before trying to connect. This is needed as connect(...) will not return -1
        // and set errno to EISCONN if a previous connect(...) attempt was setting errno to EINPROGRESS and finished
        // later.
        throw new AlreadyConnectedException();
    }

    if (localAddress != null) {
        socket.bind(localAddress);
    }

    boolean connected = doConnect0(remoteAddress);
    if (connected) {
        remote = remoteSocketAddr == null ?
                remoteAddress : computeRemoteAddr(remoteSocketAddr, socket.remoteAddress());
    }
    // We always need to set the localAddress even if not connected yet as the bind already took place.
    //
    // See https://github.com/netty/netty/issues/3463
    local = socket.localAddress();
    return connected;
}
 
源代码6 项目: TencentKona-8   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码7 项目: jdk8u60   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码8 项目: quarkus   文件: VirtualChannel.java
@Override
public void connect(final SocketAddress remoteAddress,
        SocketAddress localAddress, final ChannelPromise promise) {
    if (!promise.setUncancellable() || !ensureOpen(promise)) {
        return;
    }

    if (state == State.CONNECTED) {
        Exception cause = new AlreadyConnectedException();
        safeSetFailure(promise, cause);
        pipeline().fireExceptionCaught(cause);
        return;
    }

    if (connectPromise != null) {
        throw new ConnectionPendingException();
    }

    connectPromise = promise;

    if (state != State.BOUND) {
        // Not bound yet and no localAddress specified - get one.
        if (localAddress == null) {
            localAddress = new VirtualAddress(VirtualChannel.this);
        }
    }

    if (localAddress != null) {
        try {
            doBind(localAddress);
        } catch (Throwable t) {
            safeSetFailure(promise, t);
            close(voidPromise());
            return;
        }
    }

}
 
源代码9 项目: openjdk-jdk8u   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码11 项目: openjdk-jdk9   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码12 项目: jdk8u-jdk   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码13 项目: hottub   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码14 项目: openjdk-8-source   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码15 项目: openjdk-8   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码16 项目: jdk8u_jdk   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码17 项目: jdk8u-jdk   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码18 项目: jdk8u-dev-jdk   文件: SctpChannelImpl.java
private void ensureOpenAndUnconnected() throws IOException {
    synchronized (stateLock) {
        if (!isOpen())
            throw new ClosedChannelException();
        if (isConnected())
            throw new AlreadyConnectedException();
        if (state == ChannelState.PENDING)
            throw new ConnectionPendingException();
    }
}
 
源代码19 项目: j2objc   文件: SocketChannelTest.java
/**
 *
 * 'SocketChannelImpl.connect(SocketAddress)'
 */
public void testCFII_Data_ConnectWithServer() throws Exception {
    ensureServerOpen();
    java.nio.ByteBuffer writeBuf = java.nio.ByteBuffer
            .allocate(CAPACITY_NORMAL);
    java.nio.ByteBuffer[] writeBufArr = new java.nio.ByteBuffer[1];
    writeBufArr[0] = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
    assertFalse(this.channel1.isRegistered());
    assertTrue(this.channel1.isBlocking());

    this.channel1.connect(localAddr1);

    assertTrue(this.channel1.isBlocking());
    assertTrue(this.channel1.isConnected());
    assertFalse(this.channel1.isConnectionPending());
    assertTrue(this.channel1.isOpen());
    assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
    assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBufArr, 0, 1));

    this.channel1.configureBlocking(false);
    try {
        this.channel1.connect(localAddr1);
        fail("Should throw AlreadyConnectedException");
    } catch (AlreadyConnectedException e) {
        // correct
    }

    assertFalse(this.channel1.isRegistered());
    tryFinish();
}
 
源代码20 项目: j2objc   文件: SocketChannelTest.java
public void testCFII_Data_ConnectWithServer_nonBlocking() throws Exception {
    ensureServerOpen();
    java.nio.ByteBuffer writeBuf = java.nio.ByteBuffer
            .allocate(CAPACITY_NORMAL);
    java.nio.ByteBuffer[] writeBufArr = new java.nio.ByteBuffer[1];
    writeBufArr[0] = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
    assertFalse(this.channel1.isRegistered());
    assertTrue(this.channel1.isBlocking());
    this.channel1.configureBlocking(false);
    this.channel1.connect(localAddr1);

    assertFalse(this.channel1.isBlocking());
    boolean connected = channel1.isConnected();
    if (!connected) {
        assertTrue(this.channel1.isConnectionPending());
        assertTrue(this.channel1.isOpen());
    }
    if (tryFinish()) {
        assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
        assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBufArr, 0, 1));

        this.channel1.configureBlocking(false);
        try {
            this.channel1.connect(localAddr1);
            fail("Should throw AlreadyConnectedException");
        } catch (AlreadyConnectedException e) {
            // correct
        }
    }

    assertFalse(this.channel1.isRegistered());
    tryFinish();
}
 
源代码21 项目: j2objc   文件: AlreadyConnectedExceptionTest.java
/**
 * @tests {@link java.nio.channels.AlreadyConnectedException#AlreadyConnectedException()}
 */
public void test_Constructor() {
    AlreadyConnectedException e = new AlreadyConnectedException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
 
源代码22 项目: Bytecoder   文件: DatagramChannelImpl.java
/**
 * Connects the channel's socket.
 *
 * @param sa the remote address to which this channel is to be connected
 * @param check true to check if the channel is already connected.
 */
DatagramChannel connect(SocketAddress sa, boolean check) throws IOException {
    InetSocketAddress isa = Net.checkAddress(sa, family);
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        InetAddress ia = isa.getAddress();
        if (ia.isMulticastAddress()) {
            sm.checkMulticast(ia);
        } else {
            sm.checkConnect(ia.getHostAddress(), isa.getPort());
            sm.checkAccept(ia.getHostAddress(), isa.getPort());
        }
    }

    readLock.lock();
    try {
        writeLock.lock();
        try {
            synchronized (stateLock) {
                ensureOpen();
                if (check && state == ST_CONNECTED)
                    throw new AlreadyConnectedException();

                // ensure that the socket is bound
                if (localAddress == null) {
                    bindInternal(null);
                }

                // capture local address before connect
                initialLocalAddress = localAddress;

                int n = Net.connect(family,
                                    fd,
                                    isa.getAddress(),
                                    isa.getPort());
                if (n <= 0)
                    throw new Error();      // Can't happen

                // connected
                remoteAddress = isa;
                state = ST_CONNECTED;

                // refresh local address
                localAddress = Net.localAddress(fd);

                // flush any packets already received.
                boolean blocking = isBlocking();
                if (blocking) {
                    IOUtil.configureBlocking(fd, false);
                }
                try {
                    ByteBuffer buf = ByteBuffer.allocate(100);
                    while (receive(buf, false) >= 0) {
                        buf.clear();
                    }
                } finally {
                    if (blocking) {
                        IOUtil.configureBlocking(fd, true);
                    }
                }
            }
        } finally {
            writeLock.unlock();
        }
    } finally {
        readLock.unlock();
    }
    return this;
}
 
源代码23 项目: j2objc   文件: AlreadyConnectedExceptionTest.java
/**
 * @tests serialization/deserialization compatibility.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new AlreadyConnectedException());
}
 
源代码24 项目: j2objc   文件: AlreadyConnectedExceptionTest.java
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new AlreadyConnectedException());
}
 
public Value<Integer> handleException(AlreadyConnectedException e) {
  assertNotNull(e);
  trace("ImmediateThrowCatchJob.handleException.AlreadyBoundException");
  return immediate(EXPECTED_RESULT1);
}
 
public Value<Integer> handleException(AlreadyConnectedException e) {
  assertNotNull(e);
  trace("TestSimpleCatchJob.handleException.AlreadyBoundException");
  return immediate(EXPECTED_RESULT1);
}