use of java.nio.channels.AlreadyBoundException in project j2objc by google.
the class SocketChannelImpl method bind.
/** @hide Until ready for a public API change */
@Override
public final synchronized SocketChannel bind(SocketAddress local) throws IOException {
if (!isOpen()) {
throw new ClosedChannelException();
}
if (isBound) {
throw new AlreadyBoundException();
}
if (local == null) {
local = new InetSocketAddress(Inet4Address.ANY, 0);
} else if (!(local instanceof InetSocketAddress)) {
throw new UnsupportedAddressTypeException();
}
InetSocketAddress localAddress = (InetSocketAddress) local;
NetworkBridge.bind(fd, localAddress.getAddress(), localAddress.getPort());
onBind(true);
return this;
}
use of java.nio.channels.AlreadyBoundException in project j2objc by google.
the class SocketChannelTest method test_bind.
public void test_bind() throws IOException {
InetSocketAddress socketAddress = new InetSocketAddress(Inet4Address.LOOPBACK, 0);
SocketChannel sc = SocketChannel.open();
sc.bind(socketAddress);
assertEquals(socketAddress.getAddress(), ((InetSocketAddress) (sc.getLocalAddress())).getAddress());
assertTrue(((InetSocketAddress) (sc.getLocalAddress())).getPort() > 0);
try {
sc.bind(socketAddress);
fail();
} catch (AlreadyBoundException expected) {
}
socketAddress = new InetSocketAddress(Inet4Address.LOOPBACK, ((InetSocketAddress) (sc.getLocalAddress())).getPort());
try (SocketChannel sc1 = SocketChannel.open()) {
sc1.bind(socketAddress);
fail();
} catch (BindException expected) {
}
sc.close();
socketAddress = new InetSocketAddress(Inet4Address.LOOPBACK, 0);
try {
sc.bind(socketAddress);
fail();
} catch (ClosedChannelException expected) {
}
}
use of java.nio.channels.AlreadyBoundException in project j2objc by google.
the class AsynchronousServerSocketChannelTest method test_bind_null.
public void test_bind_null() throws Throwable {
AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open();
assertTrue(assc.isOpen());
assertNull(assc.getLocalAddress());
assc.bind(null);
assertNotNull(assc.getLocalAddress());
try {
assc.bind(null);
fail();
} catch (AlreadyBoundException expected) {
}
assc.close();
assertFalse(assc.isOpen());
}
use of java.nio.channels.AlreadyBoundException in project j2objc by google.
the class AsynchronousServerSocketChannelTest method test_bind.
/* J2ObjC removed: unsupported ResourceLeakageDetector
@Rule
public LeakageDetectorRule leakageDetectorRule = ResourceLeakageDetector.getRule();
*/
public void test_bind() throws Throwable {
AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open();
assertTrue(assc.isOpen());
assertNull(assc.getLocalAddress());
assc.bind(new InetSocketAddress(0));
assertNotNull(assc.getLocalAddress());
try {
assc.bind(new InetSocketAddress(0));
fail();
} catch (AlreadyBoundException expected) {
}
assc.close();
assertFalse(assc.isOpen());
}
use of java.nio.channels.AlreadyBoundException in project j2objc by google.
the class SocketChannelImpl method bind.
@Override
public SocketChannel bind(SocketAddress local) throws IOException {
synchronized (readLock) {
synchronized (writeLock) {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (state == ST_PENDING)
throw new ConnectionPendingException();
if (localAddress != null)
throw new AlreadyBoundException();
InetSocketAddress isa = (local == null) ? new InetSocketAddress(0) : Net.checkAddress(local);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkListen(isa.getPort());
}
NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort());
Net.bind(fd, isa.getAddress(), isa.getPort());
localAddress = Net.localAddress(fd);
}
}
}
return this;
}
Aggregations