MCPcopy Index your code
hub / github.com/RsyncProject/rsync / send_compressed_token

Function send_compressed_token

token.c:925–997  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

923
924#ifdef SUPPORT_LZ4
925static void
926send_compressed_token(int f, int32 token, struct map_struct *buf, OFF_T offset, int32 nb)
927{
928 static int init_done, flush_pending;
929 int size = MAX(LZ4_compressBound(CHUNK_SIZE), MAX_DATA_COUNT+2);
930 int32 n, r;
931
932 if (last_token == -1) {
933 if (!init_done) {
934 obuf = new_array(char, size);
935 init_done = 1;
936 }
937 last_run_end = 0;
938 run_start = token;
939 flush_pending = 0;
940 } else if (last_token == -2) {
941 run_start = token;
942 } else if (nb != 0 || token != last_token + 1 || token >= run_start + 65536) {
943 /* output previous run */
944 r = run_start - last_run_end;
945 n = last_token - run_start;
946 if (r >= 0 && r <= 63) {
947 write_byte(f, (n==0? TOKEN_REL: TOKENRUN_REL) + r);
948 } else {
949 write_byte(f, (n==0? TOKEN_LONG: TOKENRUN_LONG));
950 write_int(f, run_start);
951 }
952 if (n != 0) {
953 write_byte(f, n);
954 write_byte(f, n >> 8);
955 }
956 last_run_end = last_token;
957 run_start = token;
958 }
959
960 last_token = token;
961
962 if (nb != 0 || flush_pending) {
963 int available_in, available_out = 0;
964 const char *next_in;
965
966 do {
967 char *next_out = obuf + 2;
968
969 if (available_out == 0) {
970 available_in = MIN(nb, MAX_DATA_COUNT);
971 next_in = map_ptr(buf, offset, available_in);
972 } else
973 available_in /= 2;
974
975 available_out = LZ4_compress_default(next_in, next_out, available_in, size - 2);
976 if (!available_out) {
977 rprintf(FERROR, "compress returned %d\n", available_out);
978 exit_cleanup(RERR_STREAMIO);
979 }
980 if (available_out <= MAX_DATA_COUNT) {
981 obuf[0] = DEFLATED_DATA + (available_out >> 8);
982 obuf[1] = available_out;

Callers 1

send_tokenFunction · 0.85

Calls 5

write_byteFunction · 0.85
write_intFunction · 0.85
map_ptrFunction · 0.85
write_bufFunction · 0.85
rprintfFunction · 0.70

Tested by

no test coverage detected