summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortiptorrent development team <tiptorrent@soleta.eu>2021-09-24 10:27:35 +0200
committertiptorrent development team <tiptorrent@soleta.eu>2021-09-29 15:49:15 +0200
commit2f120d9cd272ba76f53ca1d0b31aac680934b688 (patch)
tree59bbfc2874d0855b81bda19d68d48ff61c97b609
parent97fc159ff1ddc44b658e99cb25adcaf3a5dbfe85 (diff)
fix chunk size split logic
Add remainder bytes to the last chunk instead.
-rw-r--r--src/handler.c18
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;