final CompositeQueueRecord queueRecord) throws IOException {
final int bufferSize = Math.min(queueRecord.size,
connection.getWriteBufferSize() * 3 / 2);
final DirectByteBufferRecord directByteBufferRecord =
DirectByteBufferRecord.get();
try {
final SocketChannel socketChannel = (SocketChannel) connection.getChannel();
fill(queueRecord, bufferSize, directByteBufferRecord);
directByteBufferRecord.finishBufferSlice();
final int arraySize = directByteBufferRecord.getArraySize();
final int written = arraySize == 1 ?
TCPNIOUtils.flushByteBuffer(
socketChannel, directByteBufferRecord.getArray()[0]) :
TCPNIOUtils.flushByteBuffers(
socketChannel, directByteBufferRecord.getArray(), 0, arraySize) ;
return update(queueRecord, written);
} catch (IOException e) {
// Mark connection as closed remotely.
((TCPNIOConnection) connection).terminate0(null,
new CloseReason(CloseType.REMOTELY, e));
throw e;
} finally {
directByteBufferRecord.release();
}
}