@matheusbsbs / matheus-bagliano / commits / 6b59f51b31
Fork 0

give priority to progress messages

In theory it is possible for sideband channel #2 to be delayed if pack data is quick to come up for sideband channel #1. And because data for channel #2 is read only 128 bytes at a time while pack data is read 8192 bytes at a time, it is possible for many pack blocks to be sent to the client before the progress message fifo is emptied, making the situation even worse. This would result in totally garbled progress display on the client's console as local progress gets mixed with partial remote progress lines. Let's prevent such situations by giving transmission priority to progress messages over pack data at all times. Signed-off-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nicolas Pitre committed Nov 11, 2009 at 17:24 UTC 6b59f51b312f06d9420d34c09fa408c658aac6d2
2 files changed +23 -23
builtin-upload-archive.c
+6 -8
@@ -132,7 +132,6 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
132
133 while (1) {
134 struct pollfd pfd[2];
135 - ssize_t processed[2] = { 0, 0 };
135 int status;
136
137 pfd[0].fd = fd1[0];
@@ -147,15 +146,14 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
146 }
147 continue;
148 }
150 - if (pfd[0].revents & POLLIN)
151 - /* Data stream ready */
152 - processed[0] = process_input(pfd[0].fd, 1);
149 if (pfd[1].revents & POLLIN)
150 /* Status stream ready */
155 - processed[1] = process_input(pfd[1].fd, 2);
156 - /* Always finish to read data when available */
157 - if (processed[0] || processed[1])
158 - continue;
151 + if (process_input(pfd[1].fd, 2))
152 + continue;
153 + if (pfd[0].revents & POLLIN)
154 + /* Data stream ready */
155 + if (process_input(pfd[0].fd, 1))
156 + continue;
157
158 if (waitpid(writer, &status, 0) < 0)
159 error_clnt("%s", lostchild);
upload-pack.c
+17 -15
@@ -218,6 +218,23 @@ static void create_pack_file(void)
218 }
219 continue;
220 }
221 + if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
222 + /* Status ready; we ship that in the side-band
223 + * or dump to the standard error.
224 + */
225 + sz = xread(pack_objects.err, progress,
226 + sizeof(progress));
227 + if (0 < sz)
228 + send_client_data(2, progress, sz);
229 + else if (sz == 0) {
230 + close(pack_objects.err);
231 + pack_objects.err = -1;
232 + }
233 + else
234 + goto fail;
235 + /* give priority to status messages */
236 + continue;
237 + }
238 if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
239 /* Data ready; we keep the last byte to ourselves
240 * in case we detect broken rev-list, so that we
@@ -255,21 +272,6 @@ static void create_pack_file(void)
272 if (sz < 0)
273 goto fail;
274 }
258 - if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
259 - /* Status ready; we ship that in the side-band
260 - * or dump to the standard error.
261 - */
262 - sz = xread(pack_objects.err, progress,
263 - sizeof(progress));
264 - if (0 < sz)
265 - send_client_data(2, progress, sz);
266 - else if (sz == 0) {
267 - close(pack_objects.err);
268 - pack_objects.err = -1;
269 - }
270 - else
271 - goto fail;
272 - }
275 }
276
277 if (finish_command(&pack_objects)) {