Move sideband server side support into reusable form.
The server side support; this is just the very low level, and the caller needs to know which band it wants to send things out. Signed-off-by: Junio C Hamano <junkio@cox.net> (cherry picked from b786552b67878c7780c50def4c069d46dc54efbe commit)
This commit is contained in:
parent
49a52b1d1f
commit
958c24b1b8
26
sideband.c
26
sideband.c
@ -46,3 +46,29 @@ int recv_sideband(const char *me, int in_stream, int out, int err, char *buf, in
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fd is connected to the remote side; send the sideband data
|
||||||
|
* over multiplexed packet stream.
|
||||||
|
*/
|
||||||
|
ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max)
|
||||||
|
{
|
||||||
|
ssize_t ssz = sz;
|
||||||
|
const char *p = data;
|
||||||
|
|
||||||
|
while (sz) {
|
||||||
|
unsigned n;
|
||||||
|
char hdr[5];
|
||||||
|
|
||||||
|
n = sz;
|
||||||
|
if (packet_max - 5 < n)
|
||||||
|
n = packet_max - 5;
|
||||||
|
sprintf(hdr, "%04x", n + 5);
|
||||||
|
hdr[4] = band;
|
||||||
|
safe_write(fd, hdr, 5);
|
||||||
|
safe_write(fd, p, n);
|
||||||
|
p += n;
|
||||||
|
sz -= n;
|
||||||
|
}
|
||||||
|
return ssz;
|
||||||
|
}
|
||||||
|
@ -7,5 +7,6 @@
|
|||||||
#define DEFAULT_PACKET_MAX 1000
|
#define DEFAULT_PACKET_MAX 1000
|
||||||
|
|
||||||
int recv_sideband(const char *me, int in_stream, int out, int err, char *, int);
|
int recv_sideband(const char *me, int in_stream, int out, int err, char *, int);
|
||||||
|
ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
#include "pkt-line.h"
|
#include "pkt-line.h"
|
||||||
|
#include "sideband.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
@ -33,19 +34,11 @@ static int strip(char *line, int len)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PACKET_MAX 1000
|
|
||||||
static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
|
static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
|
||||||
{
|
{
|
||||||
ssize_t ssz;
|
if (use_sideband)
|
||||||
const char *p;
|
return send_sideband(1, fd, data, sz, DEFAULT_PACKET_MAX);
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
if (!use_sideband)
|
|
||||||
return 0;
|
|
||||||
packet_flush(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!use_sideband) {
|
|
||||||
if (fd == 3)
|
if (fd == 3)
|
||||||
/* emergency quit */
|
/* emergency quit */
|
||||||
fd = 2;
|
fd = 2;
|
||||||
@ -55,24 +48,6 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
|
|||||||
}
|
}
|
||||||
return safe_write(fd, data, sz);
|
return safe_write(fd, data, sz);
|
||||||
}
|
}
|
||||||
p = data;
|
|
||||||
ssz = sz;
|
|
||||||
while (sz) {
|
|
||||||
unsigned n;
|
|
||||||
char hdr[5];
|
|
||||||
|
|
||||||
n = sz;
|
|
||||||
if (PACKET_MAX - 5 < n)
|
|
||||||
n = PACKET_MAX - 5;
|
|
||||||
sprintf(hdr, "%04x", n + 5);
|
|
||||||
hdr[4] = fd;
|
|
||||||
safe_write(1, hdr, 5);
|
|
||||||
safe_write(1, p, n);
|
|
||||||
p += n;
|
|
||||||
sz -= n;
|
|
||||||
}
|
|
||||||
return ssz;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void create_pack_file(void)
|
static void create_pack_file(void)
|
||||||
{
|
{
|
||||||
@ -308,7 +283,8 @@ static void create_pack_file(void)
|
|||||||
goto fail;
|
goto fail;
|
||||||
fprintf(stderr, "flushed.\n");
|
fprintf(stderr, "flushed.\n");
|
||||||
}
|
}
|
||||||
send_client_data(1, NULL, 0);
|
if (use_sideband)
|
||||||
|
packet_flush(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fail:
|
fail:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user