use of java.nio.channels.AsynchronousServerSocketChannel in project j2objc by google.
the class AsynchronousServerSocketChannelTest method test_completionHandlerAccept_nyb.
public void test_completionHandlerAccept_nyb() throws Throwable {
AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open();
FutureLikeCompletionHandler<AsynchronousSocketChannel> acceptCompletionHandler = new FutureLikeCompletionHandler<AsynchronousSocketChannel>();
try {
assc.accept(null, /* attachment */
acceptCompletionHandler);
fail();
} catch (NotYetBoundException expected) {
}
assc.close();
}
use of java.nio.channels.AsynchronousServerSocketChannel in project j2objc by google.
the class AsynchronousServerSocketChannelTest method test_group.
public void test_group() throws Throwable {
AsynchronousChannelProvider provider = AsynchronousChannelProvider.provider();
AsynchronousChannelGroup group = provider.openAsynchronousChannelGroup(2, Executors.defaultThreadFactory());
AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open(group);
assertNull(assc.getLocalAddress());
assc.bind(new InetSocketAddress(0));
assertNotNull(assc.getLocalAddress());
assertEquals(provider, assc.provider());
assc.close();
}
use of java.nio.channels.AsynchronousServerSocketChannel in project j2objc by google.
the class AsynchronousServerSocketChannelTest method test_futureAccept.
/* j2objc: b/162760509
public void test_bind_used() throws Throwable {
AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open();
ServerSocket ss = new ServerSocket(0);
try {
assc.bind(ss.getLocalSocketAddress());
fail();
} catch (BindException expected) {}
assertNull(assc.getLocalAddress());
ss.close();
assc.close();
}
*/
public void test_futureAccept() throws Throwable {
AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open();
assc.bind(new InetSocketAddress(0));
Future<AsynchronousSocketChannel> acceptFuture = assc.accept();
Socket s = new Socket();
s.connect(assc.getLocalAddress());
AsynchronousSocketChannel asc = acceptFuture.get(1000, TimeUnit.MILLISECONDS);
assertTrue(s.isConnected());
assertNotNull(asc.getLocalAddress());
assertEquals(asc.getLocalAddress(), s.getRemoteSocketAddress());
assertNotNull(asc.getRemoteAddress());
assertEquals(asc.getRemoteAddress(), s.getLocalSocketAddress());
asc.close();
s.close();
assc.close();
}
use of java.nio.channels.AsynchronousServerSocketChannel in project j2objc by google.
the class AsynchronousServerSocketChannelTest method test_completionHandlerAccept_attachment.
public void test_completionHandlerAccept_attachment() throws Throwable {
AsynchronousServerSocketChannel assc = AsynchronousServerSocketChannel.open();
assc.bind(new InetSocketAddress(0));
FutureLikeCompletionHandler<AsynchronousSocketChannel> acceptCompletionHandler = new FutureLikeCompletionHandler<AsynchronousSocketChannel>();
Integer attachment = new Integer(123);
assc.accept(attachment, acceptCompletionHandler);
Socket s = new Socket();
s.connect(assc.getLocalAddress());
AsynchronousSocketChannel asc = acceptCompletionHandler.get(1000);
assertNotNull(asc);
assertTrue(s.isConnected());
assertEquals(attachment, acceptCompletionHandler.getAttachment());
asc.close();
s.close();
assc.close();
}
use of java.nio.channels.AsynchronousServerSocketChannel 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());
}
Aggregations