diff options
author | tiptorrent development team <tiptorrent@soleta.eu> | 2021-09-24 10:27:35 +0200 |
---|---|---|
committer | tiptorrent development team <tiptorrent@soleta.eu> | 2021-09-29 15:49:15 +0200 |
commit | 2f120d9cd272ba76f53ca1d0b31aac680934b688 (patch) | |
tree | 59bbfc2874d0855b81bda19d68d48ff61c97b609 | |
parent | 97fc159ff1ddc44b658e99cb25adcaf3a5dbfe85 (diff) |
fix chunk size split logic
Add remainder bytes to the last chunk instead.
-rw-r--r-- | src/handler.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/handler.c b/src/handler.c index 8534c69..1c107dd 100644 --- a/src/handler.c +++ b/src/handler.c @@ -167,6 +167,7 @@ int tip_client_state_process_payload(struct tip_client *cli) int tip_client_state_process_payload_reply(struct tip_client *cli) { uint64_t chunk_size; + uint32_t remainder; off_t chunk_offset; char buf[1024]; int fd; @@ -191,18 +192,13 @@ int tip_client_state_process_payload_reply(struct tip_client *cli) break; chunk_size = cli->size / MAX_CHUNKS; - if (cli->size % MAX_CHUNKS) { - if (cli->chunk < MAX_CHUNKS - 1) { - chunk_size++; - chunk_offset = chunk_size * cli->chunk; - } else { - chunk_offset = chunk_size * cli->chunk; - chunk_offset += MAX_CHUNKS - 1; - chunk_size--; - } - } else { - chunk_offset = chunk_size * cli->chunk; + chunk_offset = chunk_size * cli->chunk; + + if (cli->chunk == MAX_CHUNKS - 1) { + remainder = cli->size % MAX_CHUNKS; + chunk_size += remainder; } + cli->size = chunk_size; cli->offset = chunk_offset; break; |