tqftpserv: allow sending data packet with 0-byte data payload

If the client requests a file that's completely empty, it makes sense to
send a response to that request with - well - 0 bytes of data and just
the 4-byte header.

But also if the client requests for example a file of rsize=53760 and
blksize=7680, then will send 7 full packets of data in the window, but
afterwards we still need to send an empty packet (just the 4 bytes of
header) to make sure the client understands that we've sent all the
requested data. Otherwise it's going to time out and re-request the
blocks and we're stuck in a loop.

So consider pread return value of 0 to not be an error and send a
response packet back.
This commit is contained in:
Luca Weiss 2024-01-19 17:09:17 +01:00 committed by Konrad Dybcio
parent 98d162c9ff
commit 2dd48a2899

View File

@ -89,9 +89,8 @@ static ssize_t tftp_send_data(struct tftp_client *client,
*p++ = block & 0xff;
len = pread(client->fd, p, client->blksize, offset);
if (len <= 0) {
if (len < 0)
printf("[TQFTP] failed to read data\n");
if (len < 0) {
printf("[TQFTP] failed to read data\n");
free(buf);
return len;
}