Send a deflated token */
| 364 | |
| 365 | /* Send a deflated token */ |
| 366 | static void |
| 367 | send_deflated_token(int f, int32 token, struct map_struct *buf, OFF_T offset, int32 nb, int32 toklen) |
| 368 | { |
| 369 | static int init_done, flush_pending; |
| 370 | int32 n, r; |
| 371 | |
| 372 | if (last_token == -1) { |
| 373 | /* initialization */ |
| 374 | if (!init_done) { |
| 375 | tx_strm.next_in = NULL; |
| 376 | tx_strm.zalloc = NULL; |
| 377 | tx_strm.zfree = NULL; |
| 378 | if (deflateInit2(&tx_strm, per_file_default_level, |
| 379 | Z_DEFLATED, -15, 8, |
| 380 | Z_DEFAULT_STRATEGY) != Z_OK) { |
| 381 | rprintf(FERROR, "compression init failed\n"); |
| 382 | exit_cleanup(RERR_PROTOCOL); |
| 383 | } |
| 384 | obuf = new_array(char, OBUF_SIZE); |
| 385 | init_done = 1; |
| 386 | } else |
| 387 | deflateReset(&tx_strm); |
| 388 | last_run_end = 0; |
| 389 | run_start = token; |
| 390 | flush_pending = 0; |
| 391 | } else if (last_token == -2) { |
| 392 | run_start = token; |
| 393 | } else if (nb != 0 || token != last_token + 1 || token >= run_start + 65536) { |
| 394 | /* output previous run */ |
| 395 | r = run_start - last_run_end; |
| 396 | n = last_token - run_start; |
| 397 | if (r >= 0 && r <= 63) { |
| 398 | write_byte(f, (n==0? TOKEN_REL: TOKENRUN_REL) + r); |
| 399 | } else { |
| 400 | write_byte(f, (n==0? TOKEN_LONG: TOKENRUN_LONG)); |
| 401 | write_int(f, run_start); |
| 402 | } |
| 403 | if (n != 0) { |
| 404 | write_byte(f, n); |
| 405 | write_byte(f, n >> 8); |
| 406 | } |
| 407 | last_run_end = last_token; |
| 408 | run_start = token; |
| 409 | } |
| 410 | |
| 411 | last_token = token; |
| 412 | |
| 413 | if (nb != 0 || flush_pending) { |
| 414 | /* deflate the data starting at offset */ |
| 415 | int flush = Z_NO_FLUSH; |
| 416 | tx_strm.avail_in = 0; |
| 417 | tx_strm.avail_out = 0; |
| 418 | do { |
| 419 | if (tx_strm.avail_in == 0 && nb != 0) { |
| 420 | /* give it some more input */ |
| 421 | n = MIN(nb, CHUNK_SIZE); |
| 422 | tx_strm.next_in = (Bytef *) |
| 423 | map_ptr(buf, offset, n); |
no test coverage detected