use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class SocketChannelTest method test_socketChannel_write_ByteBufferII.
/**
* @tests SocketChannel#write(ByteBuffer[], int, int)
*/
public void test_socketChannel_write_ByteBufferII() throws Exception {
// regression 2 for HARMONY-549
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(localAddr2);
SocketChannel sc = SocketChannel.open();
sc.connect(localAddr2);
SocketChannel sock = ssc.accept();
ByteBuffer[] buf = { ByteBuffer.allocate(10), null };
try {
sc.write(buf, 0, 2);
fail("should throw NPE");
} catch (NullPointerException e) {
// expected
}
ssc.close();
sc.close();
ByteBuffer target = ByteBuffer.allocate(10);
assertEquals(-1, sock.read(target));
}
use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class SinkChannelTest method test_socketChannel_read_write.
public void test_socketChannel_read_write() throws Exception {
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), 49999));
SocketChannel sc = SocketChannel.open();
sc.connect(new InetSocketAddress(InetAddress.getLocalHost(), 49999));
SocketChannel sock = ssc.accept();
ByteBuffer[] buf = { ByteBuffer.allocate(10), null };
try {
sc.write(buf, 0, 2);
fail("should throw NPE");
} catch (NullPointerException expected) {
}
ssc.close();
sc.close();
ByteBuffer target = ByteBuffer.allocate(10);
assertEquals(-1, sock.read(target));
}
use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class SocketChannelTest method test_write$NonBlockingException.
/**
* @tests java.nio.channels.SocketChannel#write(ByteBuffer[])
*
* In non-blocking mode, the native system call will return EAGAIN/EWOULDBLOCK error
* code on Linux/Unix and return WSATRY_AGAIN/WSAEWOULDBLOCK error code on Windows.
* These error code means try again but not fatal error, so we should not throw exception.
*/
public void test_write$NonBlockingException() throws Exception {
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.configureBlocking(false);
ssc.socket().bind(null);
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
boolean connected = sc.connect(ssc.socket().getLocalSocketAddress());
SocketChannel sock = ssc.accept();
if (!connected) {
sc.finishConnect();
}
try {
for (int i = 0; i < 100; i++) {
ByteBuffer buf1 = ByteBuffer.allocate(10);
sc.socket().setSendBufferSize(512);
int bufSize = sc.socket().getSendBufferSize();
ByteBuffer buf2 = ByteBuffer.allocate(bufSize * 10);
ByteBuffer[] sent = new ByteBuffer[2];
sent[0] = buf1;
sent[1] = buf2;
sc.write(sent);
}
} finally {
ssc.close();
sc.close();
sock.close();
}
}
use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class SocketChannelTest method test_socketChannel_read_ByteBufferII_bufNULL.
/**
* @tests SocketChannel#read(ByteBuffer[], int, int) with a null ByteBuffer
*/
public void test_socketChannel_read_ByteBufferII_bufNULL() throws Exception {
// regression 3 for HARMONY-549
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(localAddr2);
SocketChannel sc = SocketChannel.open();
sc.connect(localAddr2);
ssc.accept();
ByteBuffer[] buf = new ByteBuffer[2];
buf[0] = ByteBuffer.allocate(1);
// let buf[1] be null
try {
sc.read(buf, 0, 2);
fail("should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
ssc.close();
sc.close();
}
use of java.nio.channels.ServerSocketChannel in project robovm by robovm.
the class SocketChannelTest method test_writev2.
/**
* @tests java.nio.channels.SocketChannel#write(ByteBuffer[])
*/
public void test_writev2() throws Exception {
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.configureBlocking(false);
ssc.socket().bind(null);
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
boolean connected = sc.connect(ssc.socket().getLocalSocketAddress());
SocketChannel sock = ssc.accept();
if (!connected) {
sc.finishConnect();
}
ByteBuffer buf1 = ByteBuffer.allocate(10);
sc.socket().setSendBufferSize(512);
int bufSize = sc.socket().getSendBufferSize();
ByteBuffer buf2 = ByteBuffer.allocate(bufSize * 10);
ByteBuffer[] sent = new ByteBuffer[2];
sent[0] = buf1;
sent[1] = buf2;
long whole = buf1.remaining() + buf2.remaining();
long write = sc.write(sent);
ssc.close();
sc.close();
sock.close();
assertTrue(whole == (write + buf1.remaining() + buf2.remaining()));
}
Aggregations