public boolean connect (SocketAddress remote, int timeout) throws IOException { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (connectionPending) throw new ConnectionPendingException(); if (!(remote instanceof InetSocketAddress)) throw new UnsupportedAddressTypeException(); connectAddress = (InetSocketAddress) remote; if (connectAddress.isUnresolved()) throw new UnresolvedAddressException(); connected = channel.connect(connectAddress, timeout); connectionPending = !connected; return connected; }
@Override public void connect(SocketAddress remoteAddr, int timeout) throws IOException { if (!channel.isBlocking()) { throw new IllegalBlockingModeException(); } if (isConnected()) { throw new AlreadyConnectedException(); } super.connect(remoteAddr, timeout); channel.onBind(false); if (super.isConnected()) { InetSocketAddress remoteInetAddress = (InetSocketAddress) remoteAddr; channel.onConnectStatusChanged( remoteInetAddress, SOCKET_STATUS_CONNECTED, false /* updateSocketState */); } }
/** * @tests serialization/deserialization compatibility. */ @TestTargets({ @TestTargetNew( level = TestLevel.COMPLETE, notes = "Verifies serialization/deserialization compatibility.", method = "!SerializationSelf", args = {} ), @TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, notes = "Verifies serialization/deserialization compatibility.", method = "AlreadyConnectedException", args = {} ) }) public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new AlreadyConnectedException()); }
/** * @tests serialization/deserialization compatibility with RI. */ @TestTargets({ @TestTargetNew( level = TestLevel.COMPLETE, notes = "Verifies serialization/deserialization compatibility.", method = "!SerializationGolden", args = {} ), @TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, notes = "Verifies serialization/deserialization compatibility.", method = "AlreadyConnectedException", args = {} ) }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new AlreadyConnectedException()); }
/** * @see java.net.Socket#connect(java.net.SocketAddress, int) */ @Override public void connect(SocketAddress remoteAddr, int timeout) throws IOException { if (!channel.isBlocking()) { throw new IllegalBlockingModeException(); } if (isConnected()) { throw new AlreadyConnectedException(); } super.connect(remoteAddr, timeout); channel.localAddress = networkSystem.getSocketLocalAddress( channel.fd, false); if (super.isConnected()) { channel.setConnected(); channel.isBound = super.isBound(); } }
private void assertSocketAction_Block_BeforeConnect(Socket s) throws IOException { assertFalse(this.channel1.isConnected()); this.server2 = new ServerSocket(localAddr2.getPort()); s.connect(localAddr2); assertTrue(this.channel1.isConnected()); assertTrue(s.isConnected()); assertSocketAfterConnect(s, localAddr2); try { s.bind(localAddr2); fail("Should throw AlreadyConnectedException"); } catch (AlreadyConnectedException e) { // OK. } s.close(); assertTrue(s.isClosed()); assertFalse(this.channel1.isOpen()); }
@Override public void connect(SocketAddress remoteAddr, int timeout) throws IOException { if (!channel.isBlocking()) { throw new IllegalBlockingModeException(); } if (isConnected()) { throw new AlreadyConnectedException(); } super.connect(remoteAddr, timeout); channel.localAddress = networkSystem.getSocketLocalAddress( channel.fd, false); if (super.isConnected()) { channel.setConnected(); channel.isBound = super.isBound(); } }
private void ensureOpenAndUnconnected() throws IOException { synchronized (stateLock) { if (!isOpen()) throw new ClosedChannelException(); if (isConnected()) throw new AlreadyConnectedException(); if (state == ChannelState.PENDING) throw new ConnectionPendingException(); } }
@Override public void bind(SocketAddress localAddr) throws SocketException { if (channelImpl.isConnected()) { throw new AlreadyConnectedException(); } super.bind(localAddr); channelImpl.onBind(false /* updateSocketState */); }
synchronized private void checkUnconnected() throws IOException { if (!isOpen()) { throw new ClosedChannelException(); } if (status == SOCKET_STATUS_CONNECTED) { throw new AlreadyConnectedException(); } if (status == SOCKET_STATUS_PENDING) { throw new ConnectionPendingException(); } }
@Override public void bind(SocketAddress localAddr) throws IOException { if (channel.isConnected()) { throw new AlreadyConnectedException(); } if (SocketChannelImpl.SOCKET_STATUS_PENDING == channel.status) { throw new ConnectionPendingException(); } super.bind(localAddr); channel.onBind(false); }
public void setTarget( SocketAddress target ) { synchronized( generalSync ) { if( isConnected() ) throw new AlreadyConnectedException(); this.target = target; } }
/** * @see java.net.DatagramSocket#bind(java.net.SocketAddress) */ @Override public void bind(SocketAddress localAddr) throws SocketException { if (channelImpl.isConnected()) { throw new AlreadyConnectedException(); } super.bind(localAddr); channelImpl.isBound = true; }
@Override public void connect(SocketAddress remoteAddr, int timeout) throws IOException { if (!channel.isBlocking()) { throw new IllegalBlockingModeException(); } if (isConnected()) { throw new AlreadyConnectedException(); } super.connect(remoteAddr, timeout); channel.initLocalAddressAndPort(); if (super.isConnected()) { channel.setConnected(); channel.isBound = super.isBound(); } }
@Override public void bind(SocketAddress localAddr) throws IOException { if (channel.isConnected()) { throw new AlreadyConnectedException(); } if (SocketChannelImpl.SOCKET_STATUS_PENDING == channel.status) { throw new ConnectionPendingException(); } super.bind(localAddr); // keep here to see if need next version // channel.Address = getLocalSocketAddress(); // channel.localport = getLocalPort(); channel.isBound = true; }
/** * @tests {@link java.nio.channels.AlreadyConnectedException#AlreadyConnectedException()} */ public void test_Constructor() { AlreadyConnectedException e = new AlreadyConnectedException(); assertNull(e.getMessage()); assertNull(e.getLocalizedMessage()); assertNull(e.getCause()); }
/** * @see java.net.Socket#bind(java.net.SocketAddress) */ @Override public void bind(SocketAddress localAddr) throws IOException { if (channel.isConnected()) { throw new AlreadyConnectedException(); } if (SocketChannelImpl.SOCKET_STATUS_PENDING == channel.status) { throw new ConnectionPendingException(); } super.bind(localAddr); channel.isBound = true; channel.localAddress = super.getLocalAddress(); channel.localPort = super.getLocalPort(); }
/** * * '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(); }
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(); }