5 * Receive multiplexed output stream over git native protocol.
6 * in_stream is the input stream from the remote, which carries data
7 * in pkt_line format with band designator. Demultiplex it into out
8 * and err and return error appropriately. Band #1 carries the
9 * primary payload. Things coming over band #2 is not necessarily
10 * error; they are usually informative message on the standard error
11 * stream, aka "verbose"). A message over band #3 is a signal that
12 * the remote died unexpectedly. A flush() concludes the stream.
14 int recv_sideband(const char *me
, int in_stream
, int out
, int err
)
16 char buf
[7 + LARGE_PACKET_MAX
+ 1];
17 strcpy(buf
, "remote:");
20 len
= packet_read_line(in_stream
, buf
+7, LARGE_PACKET_MAX
);
24 len
= sprintf(buf
, "%s: protocol error: no band designator\n", me
);
25 safe_write(err
, buf
, len
);
26 return SIDEBAND_PROTOCOL_ERROR
;
34 safe_write(err
, buf
, 8+len
+1);
35 return SIDEBAND_REMOTE_ERROR
;
43 if (buf
[brk
-1] == '\n' ||
47 safe_write(err
, buf
, brk
);
49 memmove(buf
+ 8, buf
+ brk
, len
- brk
);
56 safe_write(out
, buf
+8, len
);
60 "%s: protocol error: bad band #%d\n",
62 safe_write(err
, buf
, len
);
63 return SIDEBAND_PROTOCOL_ERROR
;
70 * fd is connected to the remote side; send the sideband data
71 * over multiplexed packet stream.
73 ssize_t
send_sideband(int fd
, int band
, const char *data
, ssize_t sz
, int packet_max
)
83 if (packet_max
- 5 < n
)
85 sprintf(hdr
, "%04x", n
+ 5);
87 safe_write(fd
, hdr
, 5);