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
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <ngx_config.h>
#if (HAVE_FREEBSD_SENDFILE)
#include <ngx_core.h>
#include <ngx_types.h>
#include <ngx_socket.h>
#include <ngx_errno.h>
#include <ngx_log.h>
#include <ngx_connection.h>
#include <ngx_sendv.h>
#include <ngx_sendfile.h>
/*
CHECK:
check sent if errno == EINTR then should return right sent.
EINTR should not occur according to man.
*/
int ngx_sendfile(ngx_connection_t *c,
ngx_iovec_t *headers, int hdr_cnt,
ngx_fd_t fd, off_t offset, size_t nbytes,
ngx_iovec_t *trailers, int trl_cnt,
off_t *sent, u_int flags)
{
int rc, i;
ngx_err_t err;
struct sf_hdtr hdtr;
hdtr.headers = headers;
hdtr.hdr_cnt = hdr_cnt;
hdtr.trailers = trailers;
hdtr.trl_cnt = trl_cnt;
#if (HAVE_FREEBSD_SENDFILE_NBYTES_BUG)
for (i = 0; i < hdr_cnt; i++) {
nbytes += headers[i].iov_len;
}
#endif
rc = sendfile(fd, c->fd, offset, nbytes, &hdtr, sent, flags);
if (rc == -1) {
err = ngx_errno;
if (err != NGX_EAGAIN && err != NGX_EINTR) {
ngx_log_error(NGX_LOG_ERR, c->log, err, "sendfile failed");
return NGX_ERROR;
} else {
ngx_log_error(NGX_LOG_INFO, c->log, err,
"sendfile sent only %qd bytes", *sent);
return NGX_AGAIN;
}
}
ngx_log_debug(c->log, "sendfile: %d, @%qd %qd:%d" _
rc _ offset _ *sent _ nbytes);
return NGX_OK;
}
#endif
|