about summary refs log tree commit homepage
path: root/http_get.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-02-05 05:04:54 +0000
committerEric Wong <normalperson@yhbt.net>2012-02-05 05:04:54 +0000
commit843c54972296af794252359d776cf456e1cb0542 (patch)
tree9cad0e2bef7f09d266fa15a27cd46f390a6a4eac /http_get.c
parent5dde8e7c430bfe60fba562175d9ade62e1fbc8c3 (diff)
downloadcmogstored-843c54972296af794252359d776cf456e1cb0542.tar.gz
We can optimize this later to use SF_NODISKIO, but for
now it looks like the Linux version.
Diffstat (limited to 'http_get.c')
-rw-r--r--http_get.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/http_get.c b/http_get.c
index c58da34..cd55612 100644
--- a/http_get.c
+++ b/http_get.c
@@ -2,9 +2,37 @@
  * Copyright (C) 2012, Eric Wong <normalperson@yhbt.net>
  * License: GPLv3 or later (see COPYING for details)
  */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+
 #include "cmogstored.h"
 #include "http.h"
-#include <sys/sendfile.h>
+#ifdef __linux__
+#  include <sys/sendfile.h>
+#else
+/*
+ * make BSD sendfile look like Linux for now...
+ * we can support SF_NODISKIO later
+ */
+static ssize_t my_sendfile(int sockfd, int filefd, off_t *off, size_t count)
+{
+        int flags = 0;
+        off_t sbytes = 0;
+        int rc;
+
+        rc = sendfile(filefd, sockfd, *off, count, NULL, &sbytes, flags);
+        if (sbytes > 0) {
+                *off += sbytes;
+                return (ssize_t)sbytes;
+        }
+
+        return (ssize_t)rc;
+}
+#  define sendfile(out_fd, in_fd, offset, count) \
+          my_sendfile((out_fd),(in_fd),(offset),(count))
+#endif /* ! __linux__ */
 
 void mog_http_get_open(struct mog_http *http, char *buf, bool head_only)
 {