int localWrittenBytes = ch.write(buf.buf());
writtenBytes += localWrittenBytes;
if (localWrittenBytes == 0 || writtenBytes >= maxWrittenBytes) {
// Kernel buffer is full or wrote too much
key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
return false;
} else {
key.interestOps(key.interestOps() & (~SelectionKey.OP_WRITE));
// pop and fire event