use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class SocketChannelTest method test_writev.
/**
* @tests java.nio.channels.SocketChannel#write(ByteBuffer[])
*/
public void test_writev() throws Exception {
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(localAddr2);
SocketChannel sc = SocketChannel.open();
sc.connect(localAddr2);
SocketChannel sock = ssc.accept();
ByteBuffer[] buf = { ByteBuffer.allocate(10), ByteBuffer.allocateDirect(20) };
while (buf[0].remaining() != 0 && buf[1].remaining() != 0) {
assertTrue(sc.write(buf, 0, 2) >= 0);
}
ByteBuffer target = ByteBuffer.allocate(30);
while (target.remaining() != 0) {
assertTrue(sock.read(target) >= 0);
}
ssc.close();
sc.close();
sock.close();
}
use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class OldServerSocketTest method test_accept.
public void test_accept() throws IOException {
ServerSocket newSocket = new ServerSocket(0);
newSocket.setSoTimeout(500);
try {
Socket accepted = newSocket.accept();
fail("SocketTimeoutException was not thrown: " + accepted);
} catch (SocketTimeoutException expected) {
}
newSocket.close();
ServerSocketChannel ssc = ServerSocketChannel.open();
ServerSocket ss = ssc.socket();
try {
ss.accept();
fail("IllegalBlockingModeException was not thrown.");
} catch (IllegalBlockingModeException ibme) {
//expected
} finally {
ss.close();
ssc.close();
}
}
use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class SelectorTest method testNonBlockingConnect_immediate.
public void testNonBlockingConnect_immediate() throws Exception {
// Test the case where we [probably] connect immediately.
Selector selector = Selector.open();
ServerSocketChannel ssc = ServerSocketChannel.open();
try {
ssc.configureBlocking(false);
ssc.socket().bind(null);
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
sc.connect(ssc.socket().getLocalSocketAddress());
SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
assertEquals(1, selector.select());
assertEquals(SelectionKey.OP_CONNECT, key.readyOps());
sc.finishConnect();
} finally {
selector.close();
ssc.close();
}
}
use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class ServerSocketChannelTest method testNonBlockingAccept.
// http://code.google.com/p/android/issues/detail?id=16579
public void testNonBlockingAccept() throws Exception {
ServerSocketChannel ssc = ServerSocketChannel.open();
try {
ssc.configureBlocking(false);
ssc.socket().bind(null);
// Should return immediately, since we're non-blocking.
assertNull(ssc.accept());
} finally {
ssc.close();
}
}
use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class ChannelsTest method test_newReader_LReadableByteChannel_LString.
/**
* @tests java.nio.channels.Channels#newReader(ReadableByteChannel channel,
* String charsetName)
*/
public void test_newReader_LReadableByteChannel_LString() throws IOException {
InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1", Support_PortManager.getNextPort());
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(localAddr);
SocketChannel sc = SocketChannel.open();
sc.connect(localAddr);
sc.configureBlocking(false);
assertFalse(sc.isBlocking());
ssc.accept().close();
ssc.close();
assertFalse(sc.isBlocking());
Reader reader = Channels.newReader(sc, "UTF16");
try {
int i = reader.read();
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
try {
Channels.newInputStream(sc).read();
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException expected) {
}
sc.close();
}
Aggregations