channel.currentWriteEvent = channel.writeBuffer.poll();
channel.currentWriteIndex =
((ByteArray) channel.currentWriteEvent.getMessage()).firstIndex();
}
ByteArray a = (ByteArray) channel.currentWriteEvent.getMessage();
int localWrittenBytes = 0;
try {
for (int i = channel.getConfig().getWriteSpinCount(); i > 0; i --) {
localWrittenBytes = a.copyTo(
channel.socket,
channel.currentWriteIndex,
Math.min(maxWrittenBytes - writtenBytes, a.length() - (channel.currentWriteIndex - a.firstIndex())));
if (localWrittenBytes != 0) {
break;
}
}
} catch (Throwable t) {
channel.currentWriteEvent.getFuture().setFailure(t);
fireExceptionCaught(channel, t);
}
writtenBytes += localWrittenBytes;
channel.currentWriteIndex += localWrittenBytes;
if (channel.currentWriteIndex == a.endIndex()) {
channel.currentWriteEvent.getFuture().setSuccess();
channel.currentWriteEvent = null;
} else if (localWrittenBytes == 0 || writtenBytes < maxWrittenBytes) {
addOpWrite = true;
break;