Guillem Jover wrote:
> On Wed, 2010-02-03 at 10:25:49 -0600, Jonathan Nieder wrote:
>> From gz_comp(), it seems the length of partial writes are still
>> sometimes forgotten:
>>
>> if (have && write(state->fd, state->next, have) != have) {
>> gz_error(state, Z_ERRNO, zstrerror());
>> return -1;
>> }
>
> When interrupted or on non-blocking mode write(2) can either return > 0
> (possibly a partial write) or -1 with any of those error codes, but it
> should never return with a partial write and errno set to any of those,
> which is possible with fwrite (as internally it might be doing several
> write(2) calls and the last one might fail with any of those errors).
>
> So in the gz_comp case as long as the write returns -1 and never does a
> partial write it's fine to restart it. OTOH if it's a partial write
> errno will be bogus.
Ah, okay, so with "fast" devices (such as disks), it’s fine.
For "slow" devices such as pipes, it would be nice to report the
partial writes. If this causes the calling operation to fail, I am
not sure what the right way to report this is. If this happens in the
middle of a block, fwrite() just tries to resume; but that is not
always very good behavior.
Maybe this should be configurable via a new flag in the 'mode' string
(e.g., 'B' for non-blocking)?
Jonathan
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]