Skip to content

Commit

Permalink
lfp_sendfile: don't return EAGAIN in case of partial write
Browse files Browse the repository at this point in the history
In order to match the semantics of the Linux sendfile(), the wrapper
now hides EAGAIN if a partial write (more than 0 bytes, but fewer then
requested) was performed.
  • Loading branch information
sionescu committed Jan 18, 2022
1 parent 2774b8f commit cc50634
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lib/sendfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ lfp_sendfile(int out_fd, int in_fd, off_t offset, size_t nbytes)
off_t off = offset;
return (ssize_t) sendfile(out_fd, in_fd, &off, nbytes);
# elif defined(__FreeBSD__) || defined(__DragonFly__)
off_t sbytes;
off_t sbytes = 0;
int res = sendfile(in_fd, out_fd, offset, nbytes, NULL, &sbytes, 0);
if (res == 0) { return sbytes; }
return res;
if (res == 0 || (res < 0 && errno == EAGAIN && sbytes > 0)) {
return sbytes;
}
return -1;
# elif defined(__APPLE__)
off_t len = nbytes;
int res = sendfile(in_fd, out_fd, offset, &len, NULL, 0);
if (res == 0) { return len; }
if (res == 0 || (res < 0 && errno == EAGAIN && len > 0)) {
return len;
}
return -1;
# else
# error "It appears that this OS has sendfile(), but LFP doesn't use it at the moment"
Expand Down

0 comments on commit cc50634

Please sign in to comment.