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