Skip to content

Commit

Permalink
give priority to progress messages
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
npitre authored and gitster committed Nov 13, 2009
1 parent 1b19fa4 commit 6b59f51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
14 changes: 6 additions & 8 deletions builtin-upload-archive.c
Expand Up @@ -132,7 +132,6 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)

while (1) {
struct pollfd pfd[2];
ssize_t processed[2] = { 0, 0 };
int status;

pfd[0].fd = fd1[0];
Expand All @@ -147,15 +146,14 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
}
continue;
}
if (pfd[0].revents & POLLIN)
/* Data stream ready */
processed[0] = process_input(pfd[0].fd, 1);
if (pfd[1].revents & POLLIN)
/* Status stream ready */
processed[1] = process_input(pfd[1].fd, 2);
/* Always finish to read data when available */
if (processed[0] || processed[1])
continue;
if (process_input(pfd[1].fd, 2))
continue;
if (pfd[0].revents & POLLIN)
/* Data stream ready */
if (process_input(pfd[0].fd, 1))
continue;

if (waitpid(writer, &status, 0) < 0)
error_clnt("%s", lostchild);
Expand Down
32 changes: 17 additions & 15 deletions upload-pack.c
Expand Up @@ -218,6 +218,23 @@ static void create_pack_file(void)
}
continue;
}
if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
/* Status ready; we ship that in the side-band
* or dump to the standard error.
*/
sz = xread(pack_objects.err, progress,
sizeof(progress));
if (0 < sz)
send_client_data(2, progress, sz);
else if (sz == 0) {
close(pack_objects.err);
pack_objects.err = -1;
}
else
goto fail;
/* give priority to status messages */
continue;
}
if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
/* Data ready; we keep the last byte to ourselves
* in case we detect broken rev-list, so that we
Expand Down Expand Up @@ -255,21 +272,6 @@ static void create_pack_file(void)
if (sz < 0)
goto fail;
}
if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
/* Status ready; we ship that in the side-band
* or dump to the standard error.
*/
sz = xread(pack_objects.err, progress,
sizeof(progress));
if (0 < sz)
send_client_data(2, progress, sz);
else if (sz == 0) {
close(pack_objects.err);
pack_objects.err = -1;
}
else
goto fail;
}
}

if (finish_command(&pack_objects)) {
Expand Down

0 comments on commit 6b59f51

Please sign in to comment.