diff options
author | Eric Wong <normalperson@yhbt.net> | 2012-02-05 05:04:54 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2012-02-05 05:04:54 +0000 |
commit | 843c54972296af794252359d776cf456e1cb0542 (patch) | |
tree | 9cad0e2bef7f09d266fa15a27cd46f390a6a4eac /http_get.c | |
parent | 5dde8e7c430bfe60fba562175d9ade62e1fbc8c3 (diff) | |
download | cmogstored-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.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -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) { |