|
11 | 11 | * stream, aka "verbose"). A message over band #3 is a signal that
|
12 | 12 | * the remote died unexpectedly. A flush() concludes the stream.
|
13 | 13 | */
|
14 |
| -int recv_sideband(const char *me, int in_stream, int out, int err, char *buf, int bufsz) |
| 14 | +int recv_sideband(const char *me, int in_stream, int out, int err) |
15 | 15 | {
|
| 16 | + char buf[7 + LARGE_PACKET_MAX + 1]; |
| 17 | + strcpy(buf, "remote:"); |
16 | 18 | while (1) {
|
17 |
| - int len = packet_read_line(in_stream, buf, bufsz); |
| 19 | + int band, len; |
| 20 | + len = packet_read_line(in_stream, buf+7, LARGE_PACKET_MAX); |
18 | 21 | if (len == 0)
|
19 | 22 | break;
|
20 | 23 | if (len < 1) {
|
21 | 24 | len = sprintf(buf, "%s: protocol error: no band designator\n", me);
|
22 | 25 | safe_write(err, buf, len);
|
23 | 26 | return SIDEBAND_PROTOCOL_ERROR;
|
24 | 27 | }
|
| 28 | + band = buf[7] & 0xff; |
25 | 29 | len--;
|
26 |
| - switch (buf[0] & 0xFF) { |
| 30 | + switch (band) { |
27 | 31 | case 3:
|
28 |
| - safe_write(err, "remote: ", 8); |
29 |
| - safe_write(err, buf+1, len); |
30 |
| - safe_write(err, "\n", 1); |
| 32 | + buf[7] = ' '; |
| 33 | + buf[8+len] = '\n'; |
| 34 | + safe_write(err, buf, 8+len+1); |
31 | 35 | return SIDEBAND_REMOTE_ERROR;
|
32 | 36 | case 2:
|
33 |
| - safe_write(err, "remote: ", 8); |
34 |
| - safe_write(err, buf+1, len); |
| 37 | + buf[7] = ' '; |
| 38 | + safe_write(err, buf, 8+len); |
35 | 39 | continue;
|
36 | 40 | case 1:
|
37 |
| - safe_write(out, buf+1, len); |
| 41 | + safe_write(out, buf+8, len); |
38 | 42 | continue;
|
39 | 43 | default:
|
40 |
| - len = sprintf(buf + 1, |
| 44 | + len = sprintf(buf, |
41 | 45 | "%s: protocol error: bad band #%d\n",
|
42 |
| - me, buf[0] & 0xFF); |
43 |
| - safe_write(err, buf+1, len); |
| 46 | + me, band); |
| 47 | + safe_write(err, buf, len); |
44 | 48 | return SIDEBAND_PROTOCOL_ERROR;
|
45 | 49 | }
|
46 | 50 | }
|
|
0 commit comments