Make sure writebuffer is reset if total written == writeBuffer.size()