Deal with partial writes in the packet writer

Keep track of how many bytes of a packet have been written already.