Methods Summary |
---|
public static long | flushChannel(java.nio.channels.SocketChannel socketChannel, java.nio.ByteBuffer bb)Flush the buffer by looping until the ByteBuffer is empty
return flushChannel(socketChannel,bb,defaultWriteTimeout);
|
public static long | flushChannel(java.nio.channels.SocketChannel socketChannel, java.nio.ByteBuffer bb, long writeTimeout)Flush the buffer by looping until the ByteBuffer is empty
if (bb == null){
throw new IllegalStateException("Invalid Response State. ByteBuffer"
+ " cannot be null.");
}
if (socketChannel == null){
throw new IllegalStateException("Invalid Response State. " +
"SocketChannel cannot be null.");
}
SelectionKey key = null;
Selector writeSelector = null;
int attempts = 0;
int bytesProduced = 0;
try {
while ( bb.hasRemaining() ) {
int len = socketChannel.write(bb);
attempts++;
if (len < 0){
throw new EOFException();
}
bytesProduced += len;
if (len == 0) {
if ( writeSelector == null ){
writeSelector = SelectorFactory.getSelector();
if ( writeSelector == null){
// Continue using the main one.
continue;
}
}
key = socketChannel.register(writeSelector, key.OP_WRITE);
if (writeSelector.select(writeTimeout) == 0) {
if (attempts > 2)
throw new IOException("Client disconnected");
} else {
attempts--;
}
} else {
attempts = 0;
}
}
} finally {
if (key != null) {
key.cancel();
key = null;
}
if ( writeSelector != null ) {
// Cancel the key.
writeSelector.selectNow();
SelectorFactory.returnSelector(writeSelector);
}
}
return bytesProduced;
|
public static long | flushChannel(java.nio.channels.SocketChannel socketChannel, java.nio.ByteBuffer[] bb)Flush the buffer by looping until the ByteBuffer is empty
return flushChannel(socketChannel,bb,defaultWriteTimeout);
|
public static long | flushChannel(java.nio.channels.SocketChannel socketChannel, java.nio.ByteBuffer[] bb, long writeTimeout)Flush the buffer by looping until the ByteBuffer is empty
if (bb == null){
throw new IllegalStateException("Invalid Response State. ByteBuffer"
+ " cannot be null.");
}
if (socketChannel == null){
throw new IllegalStateException("Invalid Response State. " +
"SocketChannel cannot be null.");
}
SelectionKey key = null;
Selector writeSelector = null;
int attempts = 0;
long totalBytes = 0;
for (ByteBuffer aBb : bb) {
totalBytes += aBb.remaining();
}
long byteProduced = 0;
try {
while (byteProduced < totalBytes ) {
long len = socketChannel.write(bb);
attempts++;
byteProduced += len;
if (len < 0){
throw new EOFException();
}
if (len == 0) {
if ( writeSelector == null ){
writeSelector = SelectorFactory.getSelector();
if ( writeSelector == null){
// Continue using the main one.
continue;
}
}
key = socketChannel.register(writeSelector, key.OP_WRITE);
if (writeSelector.select(writeTimeout) == 0) {
if (attempts > 2)
throw new IOException("Client disconnected");
} else {
attempts--;
}
} else {
attempts = 0;
}
}
} finally {
if (key != null) {
key.cancel();
key = null;
}
if ( writeSelector != null ) {
// Cancel the key.
writeSelector.selectNow();
SelectorFactory.returnSelector(writeSelector);
}
}
return byteProduced;
|
public static int | getDefaultWriteTimeout()
return defaultWriteTimeout;
|
public static void | setDefaultWriteTimeout(int aDefaultWriteTimeout)
defaultWriteTimeout = aDefaultWriteTimeout;
|