1. David Krentzlin
  2. sendfile

Commits

Jim Ursetto  committed 925f5c2

Fix OS X sendfile corruption when EAGAIN occurs with partial data

  • Participants
  • Parent commits 36e4e00
  • Branches default

Comments (0)

Files changed (1)

File strategies/sendfile.macos.scm

View file
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <errno.h>")
+
+;; EAGAIN may be signaled even when partial data is sent, but the caller expects EAGAIN
+;; to mean zero bytes sent, so we return the number of bytes sent when non-zero.
 (define %sendfile-implementation
   (foreign-lambda* double ((integer src) (integer dst) (double offset) (unsigned-integer to_send))
     "off_t res = (off_t)to_send;"
     "if(sendfile(src,dst,(off_t)offset,&res,NULL/*&hdtr*/,0) < 0){"
-    "  C_return(errno == EAGAIN ? -2 : -1);"
+    "  if(errno == EAGAIN)"
+    "    C_return(res == 0 ? -2 : (double)(offset + res));"
+    "  else C_return(-1);"
     "}"
     "C_return((double)(offset + res));"))