# HG changeset patch
# User Jim Ursetto <jim@3e8.org>
# Date 1321555876 21600
# Node ID 925f5c2655b318572d021b799a73f91e45f8d3d4
# Parent 36e4e006e0f5a94affc96f8de228bd491ccad8ac
Fix OS X sendfile corruption when EAGAIN occurs with partial data
diff --git a/strategies/sendfile.macos.scm b/strategies/sendfile.macos.scm
a
|
b
|
|
3 | 3 | #include <sys/types.h> |
4 | 4 | #include <sys/uio.h> |
5 | 5 | #include <errno.h>") |
| 6 | |
| 7 | ;; EAGAIN may be signaled even when partial data is sent, but the caller expects EAGAIN |
| 8 | ;; to mean zero bytes sent, so we return the number of bytes sent when non-zero. |
6 | 9 | (define %sendfile-implementation |
7 | 10 | (foreign-lambda* double ((integer src) (integer dst) (double offset) (unsigned-integer to_send)) |
8 | 11 | "off_t res = (off_t)to_send;" |
9 | 12 | "if(sendfile(src,dst,(off_t)offset,&res,NULL/*&hdtr*/,0) < 0){" |
10 | | " C_return(errno == EAGAIN ? -2 : -1);" |
| 13 | " if(errno == EAGAIN)" |
| 14 | " C_return(res == 0 ? -2 : (double)(offset + res));" |
| 15 | " else C_return(-1);" |
11 | 16 | "}" |
12 | 17 | "C_return((double)(offset + res));")) |