forked from azatoth/minidlna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendfile.h
53 lines (37 loc) · 907 Bytes
/
sendfile.h
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#if defined(HAVE_LINUX_SENDFILE_API)
#include <sys/sendfile.h>
int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len)
{
return sendfile(sock, sendfd, offset, len);
}
#elif defined(HAVE_DARWIN_SENDFILE_API)
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len)
{
int ret;
ret = sendfile(sendfd, sock, *offset, &len, NULL, 0);
*offset += len;
return ret;
}
#elif defined(HAVE_FREEBSD_SENDFILE_API)
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len)
{
int ret;
size_t nbytes = len;
ret = sendfile(sendfd, sock, *offset, nbytes, NULL, &len, SF_MNOWAIT);
*offset += len;
return ret;
}
#else
#include <errno.h>
int sys_sendfile(int sock, int sendfd, off_t *offset, off_t len)
{
errno = EINVAL;
return -1;
}
#endif