cmogstored 1.8.1 - use default system stack size
[cmogstored.git] / compat_sendfile.h
blob3fe83a113f7b9b910ea9c77b45f820b19c645c3a
1 /*
2 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4 */
5 #ifndef HAVE_SENDFILE
6 static ssize_t compat_sendfile(int sockfd, int filefd, off_t *off, size_t count)
8 size_t max_pread;
9 void *buf = mog_fsbuf_get(&max_pread);
10 ssize_t r;
11 ssize_t w;
13 max_pread = MIN(max_pread, count);
14 do {
15 r = off ? pread(filefd, buf, max_pread, *off) :
16 read(filefd, buf, max_pread);
17 } while (r < 0 && errno == EINTR);
19 if (r <= 0)
20 return r;
22 w = write(sockfd, buf, r);
23 if (w > 0 && off)
24 *off += w;
25 return w;
27 # define sendfile(out_fd, in_fd, offset, count) \
28 compat_sendfile((out_fd),(in_fd),(offset),(count))
29 #endif