Skip to content

Instantly share code, notes, and snippets.

@kazuho
Created September 14, 2009 04:25
Show Gist options
  • Save kazuho/186494 to your computer and use it in GitHub Desktop.
Save kazuho/186494 to your computer and use it in GitHub Desktop.
$ diff -u lib/Sys/Sendfile.xs.orig lib/Sys/Sendfile.xs
--- lib/Sys/Sendfile.xs.orig 2009-09-14 13:16:26.000000000 +0900
+++ lib/Sys/Sendfile.xs 2009-09-15 22:12:08.000000000 +0900
@@ -12,7 +12,7 @@
#if defined linux || defined solaris
#include <sys/sendfile.h>
-#elif defined __FreeBSD__
+#elif defined (__FreeBSD__) || defined (__APPLE__)
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
@@ -24,7 +24,7 @@
#include "perl.h"
#include "XSUB.h"
-#if !defined __linux__ && !defined __solaris__ && !defined __FreeBSD__
+#if !defined __linux__ && !defined __solaris__ && !defined __FreeBSD__ && !defined __APPLE__
#ifdef __GNUC__
#error Your operating system appears to be unsupported
@@ -62,9 +62,17 @@
{
off_t bytes;
int ret = sendfile(in, out, real_offset, count, NULL, &bytes, 0);
- if (ret == -1)
+ if (ret == -1 && ! (errno == EAGAIN || errno == EINTR))
XSRETURN_EMPTY;
else
XSRETURN_IV(bytes);
+#elif defined __APPLE__
+ {
+ off_t bytes = count;
+ int ret = sendfile(in, out, real_offset, &bytes, NULL, 0);
+ if (ret == -1 && ! (errno == EAGAIN || errno == EINTR))
+ XSRETURN_EMPTY;
+ else
+ XSRETURN_IV(bytes);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment