Refactor: Clean up batch header reading in server

Replace manual unpacking of batch_meta_header_t fields with direct
struct field reads. The magic was already read separately, so we
now read count, total_name_len, and total_size directly into the
struct fields, which is cleaner and less error-prone.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Theo Tappe
2026-06-24 12:43:59 +02:00
parent bc46269f37
commit 1a9d6fde96
3 changed files with 5 additions and 9 deletions
BIN
View File
Binary file not shown.
+5 -9
View File
@@ -303,19 +303,15 @@ void handle_client(int sock_fd, const char *dest_dir) {
if (magic == MAGIC_BATCH_META) {
// Handle batch metadata
// We already read the magic, now read the rest of the header
// We already read the magic (4 bytes), now read the rest of the header (16 bytes)
batch_meta_header_t batch_hdr;
uint32_t rest_of_header[3]; // count, total_name_len, total_size_hi
uint32_t total_size_lo;
if (readn(sock_fd, &rest_of_header, sizeof(rest_of_header)) != sizeof(rest_of_header) ||
readn(sock_fd, &total_size_lo, sizeof(total_size_lo)) != sizeof(total_size_lo)) {
batch_hdr.magic = magic;
if (readn(sock_fd, &batch_hdr.count, sizeof(batch_hdr.count)) != sizeof(batch_hdr.count) ||
readn(sock_fd, &batch_hdr.total_name_len, sizeof(batch_hdr.total_name_len)) != sizeof(batch_hdr.total_name_len) ||
readn(sock_fd, &batch_hdr.total_size, sizeof(batch_hdr.total_size)) != sizeof(batch_hdr.total_size)) {
fprintf(stderr, "Failed to read batch header\n");
break;
}
batch_hdr.magic = magic;
batch_hdr.count = rest_of_header[0];
batch_hdr.total_name_len = rest_of_header[1];
batch_hdr.total_size = ((uint64_t)rest_of_header[2] << 32) | total_size_lo;
if (batch_hdr.count > BATCH_MAX_FILES) {
fprintf(stderr, "Batch count %u exceeds max %d\n", batch_hdr.count, BATCH_MAX_FILES);
BIN
View File
Binary file not shown.