Skip to content

Commit 791bffc

Browse files
committed
Send only the number of bytes specified
1 parent c229178 commit 791bffc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/send_buffer.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ int64_t send_file_buffer_write(int fd, int64_t offset, int64_t size, int64_t blo
8181
char buffer[PACKET_DATA_SIZE];
8282
int boundary;
8383
int len;
84+
int bytes_to_read;
8485

8586
retval = 0;
8687
seqnum = 2142894844; /* TODO: generate random number */
@@ -90,11 +91,17 @@ int64_t send_file_buffer_write(int fd, int64_t offset, int64_t size, int64_t blo
9091

9192
while (size > 0)
9293
{
93-
len = pread(fd, buffer, PACKET_DATA_SIZE, offset);
94+
bytes_to_read = (size > PACKET_DATA_SIZE) ? PACKET_DATA_SIZE : size;
95+
len = pread(fd, buffer, bytes_to_read, offset);
9496
if (len < 0) break;
9597
retval += len;
9698
size -= len;
9799

100+
/* if bytes read is less than the desired, then its EOF */
101+
if (len < bytes_to_read) {
102+
size = 0;
103+
}
104+
98105
boundary |= (size > 0) ? PACKET_BOUNDARY_NONE : PACKET_BOUNDARY_END;
99106

100107
packet_clear_header (packet);

0 commit comments

Comments
 (0)