Mercurial > hg > nginx
comparison src/os/unix/freebsd/ngx_sendfile.c @ 59:e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 06 Feb 2003 17:21:13 +0000 |
parents | 6a0b3d6e9c13 |
children |
comparison
equal
deleted
inserted
replaced
58:6b13b1cadabe | 59:e8cdc2989cee |
---|---|
3 | 3 |
4 #if (HAVE_FREEBSD_SENDFILE) | 4 #if (HAVE_FREEBSD_SENDFILE) |
5 | 5 |
6 #include <ngx_core.h> | 6 #include <ngx_core.h> |
7 #include <ngx_types.h> | 7 #include <ngx_types.h> |
8 #include <ngx_file.h> | |
9 #include <ngx_socket.h> | 8 #include <ngx_socket.h> |
10 #include <ngx_errno.h> | 9 #include <ngx_errno.h> |
11 #include <ngx_log.h> | 10 #include <ngx_log.h> |
11 #include <ngx_connection.h> | |
12 #include <ngx_sendv.h> | 12 #include <ngx_sendv.h> |
13 #include <ngx_sendfile.h> | 13 #include <ngx_sendfile.h> |
14 | 14 |
15 /* | 15 /* |
16 CHECK: | 16 CHECK: |
17 check sent if errno == EINTR then should return right sent. | 17 check sent if errno == EINTR then should return right sent. |
18 EINTR should not occur according to man. | |
18 */ | 19 */ |
19 | 20 |
20 | 21 |
21 int ngx_sendfile(ngx_socket_t s, | 22 int ngx_sendfile(ngx_connection_t *c, |
22 ngx_iovec_t *headers, int hdr_cnt, | 23 ngx_iovec_t *headers, int hdr_cnt, |
23 ngx_fd_t fd, off_t offset, size_t nbytes, | 24 ngx_fd_t fd, off_t offset, size_t nbytes, |
24 ngx_iovec_t *trailers, int trl_cnt, | 25 ngx_iovec_t *trailers, int trl_cnt, |
25 off_t *sent, | 26 off_t *sent, u_int flags) |
26 ngx_log_t *log) | |
27 { | 27 { |
28 int rc, i; | 28 int rc, i; |
29 ngx_err_t err; | 29 ngx_err_t err; |
30 struct sf_hdtr hdtr; | 30 struct sf_hdtr hdtr; |
31 | 31 |
33 hdtr.hdr_cnt = hdr_cnt; | 33 hdtr.hdr_cnt = hdr_cnt; |
34 hdtr.trailers = trailers; | 34 hdtr.trailers = trailers; |
35 hdtr.trl_cnt = trl_cnt; | 35 hdtr.trl_cnt = trl_cnt; |
36 | 36 |
37 #if (HAVE_FREEBSD_SENDFILE_NBYTES_BUG) | 37 #if (HAVE_FREEBSD_SENDFILE_NBYTES_BUG) |
38 for (i = 0; i < hdr_cnt; i++) | 38 for (i = 0; i < hdr_cnt; i++) { |
39 nbytes += headers[i].iov_len; | 39 nbytes += headers[i].iov_len; |
40 } | |
40 #endif | 41 #endif |
41 | 42 |
42 rc = sendfile(fd, s, offset, nbytes, &hdtr, sent, 0); | 43 rc = sendfile(fd, c->fd, offset, nbytes, &hdtr, sent, flags); |
43 | 44 |
44 if (rc == -1) { | 45 if (rc == -1) { |
45 err = ngx_socket_errno; | 46 err = ngx_errno; |
46 if (err != NGX_EAGAIN && err != NGX_EINTR) { | 47 if (err != NGX_EAGAIN && err != NGX_EINTR) { |
47 ngx_log_error(NGX_LOG_ERR, log, err, | 48 ngx_log_error(NGX_LOG_ERR, c->log, err, "sendfile failed"); |
48 "ngx_sendfile: sendfile failed"); | 49 |
49 return NGX_ERROR; | 50 return NGX_ERROR; |
50 | 51 |
51 } else { | 52 } else { |
52 ngx_log_error(NGX_LOG_INFO, log, err, | 53 ngx_log_error(NGX_LOG_INFO, c->log, err, |
53 "ngx_sendfile: sendfile sent only %qd bytes", *sent); | 54 "sendfile sent only %qd bytes", *sent); |
55 | |
56 return NGX_AGAIN; | |
54 } | 57 } |
55 } | 58 } |
56 | 59 |
57 ngx_log_debug(log, "ngx_sendfile: %d, @%qd %qd:%d" _ | 60 ngx_log_debug(c->log, "sendfile: %d, @%qd %qd:%d" _ |
58 rc _ offset _ *sent _ nbytes); | 61 rc _ offset _ *sent _ nbytes); |
59 | 62 |
60 return NGX_OK; | 63 return NGX_OK; |
61 } | 64 } |
62 | 65 |