Mercurial > hg > nginx
comparison src/os/unix/ngx_sendfile.c @ 0:4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
The first code that uses "ngx_" prefix, the previous one used "gx_" prefix.
At that point the code is not yet usable. The first draft ideas are dated
back to 23.10.2001.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 06 Aug 2002 16:39:45 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4eff17414a43 |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 #include <ngx_types.h> | |
4 #include <ngx_errno.h> | |
5 #include <ngx_log.h> | |
6 #include <ngx_sendv.h> | |
7 #include <ngx_sendfile.h> | |
8 | |
9 /* | |
10 TODO: | |
11 FreeBSD: | |
12 check sent if errno == EINTR then should return right sent. | |
13 */ | |
14 | |
15 /* | |
16 returns | |
17 0 done | |
18 -1 error | |
19 */ | |
20 | |
21 #if (HAVE_FREEBSD_SENDFILE) | |
22 | |
23 int ngx_sendfile(ngx_socket_t s, | |
24 ngx_iovec_t *headers, int hdr_cnt, | |
25 ngx_file_t fd, off_t offset, size_t nbytes, | |
26 ngx_iovec_t *trailers, int trl_cnt, | |
27 off_t *sent, | |
28 ngx_log_t *log) | |
29 { | |
30 int rc, i; | |
31 ngx_err_t err; | |
32 struct sf_hdtr hdtr; | |
33 | |
34 hdtr.headers = headers; | |
35 hdtr.hdr_cnt = hdr_cnt; | |
36 hdtr.trailers = trailers; | |
37 hdtr.trl_cnt = trl_cnt; | |
38 | |
39 #if (HAVE_FREEBSD_SENDFILE_NBYTES_BUG) | |
40 for (i = 0; i < hdr_cnt; i++) | |
41 nbytes += headers[i].iov_len; | |
42 #endif | |
43 | |
44 rc = sendfile(fd, s, offset, nbytes, &hdtr, sent, 0); | |
45 | |
46 if (rc == -1) { | |
47 err = ngx_socket_errno; | |
48 if (err != NGX_EAGAIN && err != NGX_EINTR) { | |
49 ngx_log_error(NGX_LOG_ERR, log, err, | |
50 "ngx_sendfile: sendfile failed"); | |
51 return -1; | |
52 | |
53 } else { | |
54 ngx_log_error(NGX_LOG_INFO, log, err, | |
55 "ngx_sendfile: sendfile sent only %qd bytes", *sent); | |
56 } | |
57 } | |
58 | |
59 ngx_log_debug(log, "ngx_sendfile: %d, @%qd %d:%qd" _ | |
60 rc _ offset _ nbytes _ *sent); | |
61 | |
62 return 0; | |
63 } | |
64 | |
65 #endif |