diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2016-04-05 03:09:59 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2016-04-05 03:09:59 -0700 |
commit | 4f1df003ed39280c2e4f62581888a62def3e34fe (patch) | |
tree | b0e5f860fddef265c9ff69632f246263d54e824b /gzwrite.c | |
parent | 4423fef8dc5f13a157a3cded687525ca5c91ee4e (diff) | |
download | zlib-4f1df003ed39280c2e4f62581888a62def3e34fe.tar.gz zlib-4f1df003ed39280c2e4f62581888a62def3e34fe.tar.bz2 zlib-4f1df003ed39280c2e4f62581888a62def3e34fe.zip |
Loop on write() calls in gzwrite.c in case of non-blocking I/O.
Diffstat (limited to 'gzwrite.c')
-rw-r--r-- | gzwrite.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -82,12 +82,15 @@ local int gz_comp(state, flush) | |||
82 | 82 | ||
83 | /* write directly if requested */ | 83 | /* write directly if requested */ |
84 | if (state->direct) { | 84 | if (state->direct) { |
85 | got = write(state->fd, strm->next_in, strm->avail_in); | 85 | while (strm->avail_in) { |
86 | if (got < 0 || (unsigned)got != strm->avail_in) { | 86 | got = write(state->fd, strm->next_in, strm->avail_in); |
87 | gz_error(state, Z_ERRNO, zstrerror()); | 87 | if (got < 0) { |
88 | return -1; | 88 | gz_error(state, Z_ERRNO, zstrerror()); |
89 | return -1; | ||
90 | } | ||
91 | strm->avail_in -= got; | ||
92 | strm->next_in += got; | ||
89 | } | 93 | } |
90 | strm->avail_in = 0; | ||
91 | return 0; | 94 | return 0; |
92 | } | 95 | } |
93 | 96 | ||
@@ -98,17 +101,19 @@ local int gz_comp(state, flush) | |||
98 | doing Z_FINISH then don't write until we get to Z_STREAM_END */ | 101 | doing Z_FINISH then don't write until we get to Z_STREAM_END */ |
99 | if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && | 102 | if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && |
100 | (flush != Z_FINISH || ret == Z_STREAM_END))) { | 103 | (flush != Z_FINISH || ret == Z_STREAM_END))) { |
101 | have = (unsigned)(strm->next_out - state->x.next); | 104 | while (strm->next_out > state->x.next) { |
102 | if (have && ((got = write(state->fd, state->x.next, have)) < 0 || | 105 | got = write(state->fd, state->x.next, |
103 | (unsigned)got != have)) { | 106 | strm->next_out - state->x.next); |
104 | gz_error(state, Z_ERRNO, zstrerror()); | 107 | if (got < 0) { |
105 | return -1; | 108 | gz_error(state, Z_ERRNO, zstrerror()); |
109 | return -1; | ||
110 | } | ||
111 | state->x.next += got; | ||
106 | } | 112 | } |
107 | if (strm->avail_out == 0) { | 113 | if (strm->avail_out == 0) { |
108 | strm->avail_out = state->size; | 114 | strm->avail_out = state->size; |
109 | strm->next_out = state->out; | 115 | strm->next_out = state->out; |
110 | } | 116 | } |
111 | state->x.next = strm->next_out; | ||
112 | } | 117 | } |
113 | 118 | ||
114 | /* compress */ | 119 | /* compress */ |