use of java.nio.channels.SelectableChannel in project robovm by robovm.
the class AbstractSelectableChannelTest method test_configureBlocking_Z_IllegalBlockingMode.
/**
* @tests AbstractSelectableChannel#configureBlocking(boolean)
*/
public void test_configureBlocking_Z_IllegalBlockingMode() throws Exception {
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
Selector acceptSelector = SelectorProvider.provider().openSelector();
SelectionKey acceptKey = sc.register(acceptSelector, SelectionKey.OP_READ, null);
assertEquals(sc.keyFor(acceptSelector), acceptKey);
SelectableChannel getChannel = sc.configureBlocking(false);
assertEquals(getChannel, sc);
try {
sc.configureBlocking(true);
fail("Should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
}
use of java.nio.channels.SelectableChannel in project heron by twitter.
the class HeronServerTest method testHandleError.
/**
* Method: handleError(SelectableChannel channel)
*/
@Test
public void testHandleError() throws Exception {
runBase();
Map<SocketChannel, SocketChannelHelper> activeConnections = heronServer.getActiveConnections();
SelectableChannel channel = activeConnections.keySet().iterator().next();
heronServer.handleError(channel);
Assert.assertEquals(0, activeConnections.size());
}
use of java.nio.channels.SelectableChannel in project jeromq by zeromq.
the class ZPoller method add.
// add an item to this poller
protected boolean add(Object socketOrChannel, final ItemHolder holder) {
if (socketOrChannel == null) {
Socket socket = holder.socket();
SelectableChannel ch = holder.item().getRawSocket();
if (socket == null) {
// not a socket
assert (ch != null);
socketOrChannel = ch;
}
if (ch == null) {
// not a channel
assert (socket != null);
socketOrChannel = socket;
}
}
assert (socketOrChannel != null);
Set<ItemHolder> holders = items.get(socketOrChannel);
if (holders == null) {
holders = createContainer(1);
items.put(socketOrChannel, holders);
}
final boolean rc = holders.add(holder);
if (rc) {
all.add(holder);
}
return rc;
}
use of java.nio.channels.SelectableChannel in project jdk8u_jdk by JetBrains.
the class FileChannelImpl method transferToDirectly.
private long transferToDirectly(long position, int icount, WritableByteChannel target) throws IOException {
if (!transferSupported)
return IOStatus.UNSUPPORTED;
FileDescriptor targetFD = null;
if (target instanceof FileChannelImpl) {
if (!fileSupported)
return IOStatus.UNSUPPORTED_CASE;
targetFD = ((FileChannelImpl) target).fd;
} else if (target instanceof SelChImpl) {
// Direct transfer to pipe causes EINVAL on some configurations
if ((target instanceof SinkChannelImpl) && !pipeSupported)
return IOStatus.UNSUPPORTED_CASE;
// Platform-specific restrictions. Now there is only one:
// Direct transfer to non-blocking channel could be forbidden
SelectableChannel sc = (SelectableChannel) target;
if (!nd.canTransferToDirectly(sc))
return IOStatus.UNSUPPORTED_CASE;
targetFD = ((SelChImpl) target).getFD();
}
if (targetFD == null)
return IOStatus.UNSUPPORTED;
int thisFDVal = IOUtil.fdVal(fd);
int targetFDVal = IOUtil.fdVal(targetFD);
if (// Not supported on some configurations
thisFDVal == targetFDVal)
return IOStatus.UNSUPPORTED;
if (nd.transferToDirectlyNeedsPositionLock()) {
synchronized (positionLock) {
long pos = position();
try {
return transferToDirectlyInternal(position, icount, target, targetFD);
} finally {
position(pos);
}
}
} else {
return transferToDirectlyInternal(position, icount, target, targetFD);
}
}
use of java.nio.channels.SelectableChannel in project geode by apache.
the class ServerConnection method makeBlocking.
/**
* Switch this guy to blocking mode so we can use oldIO to read and write msgs.
*/
public void makeBlocking() throws IOException {
// logger.info("DEBUG: makeBlocking " + this);
// if (this.sKey != null) {
// this.sKey = null;
// }
SelectableChannel c = this.theSocket.getChannel();
c.configureBlocking(true);
}
Aggregations