Break on first len > 0? The value of write_size isn't actually used, it's just checked for == 0.