Klaus Demo nginx / 95d00c4
nginx-0.0.11-2004-09-16-20:10:13 import Igor Sysoev 17 years ago
5 changed file(s) with 62 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
11 #define _NGINX_H_INCLUDED_
22
33
4 #define NGINX_VER "nginx/0.0.10"
4 #define NGINX_VER "nginx/0.0.11"
55
66 #define NGINX_VAR "NGINX"
77 #define NGX_NEWPID_EXT ".newbin"
107107 ngx_atomic_t old,
108108 ngx_atomic_t set)
109109 {
110 uint32_t res = (u_int32_t) set;
110 uint32_t res = (uint32_t) set;
111111
112112 __asm__ volatile (
113113
1111 /*
1212 * Although FreeBSD sendfile() allows to pass a header and a trailer
1313 * it can not send a header with a part of the file in one packet until
14 * FreeBSD 5.2-STABLE. Besides over the fast ethernet connection sendfile()
14 * FreeBSD 5.3. Besides over the fast ethernet connection sendfile()
1515 * may send the partially filled packets, i.e. the 8 file pages may be sent
1616 * as the 11 full 1460-bytes packets, then one incomplete 324-bytes packet,
1717 * and then again the 11 full 1460-bytes packets.
1818 *
1919 * So we use the TCP_NOPUSH option (similar to Linux's TCP_CORK)
2020 * to postpone the sending - it not only sends a header and the first part
21 * of the file in one packet but also sends file pages in the full packets.
21 * of the file in one packet but also sends the file pages in the full packets.
2222 *
2323 * But until FreeBSD 4.5 the turning TCP_NOPUSH off does not flush a pending
2424 * data that less than MSS so that data may be sent with 5 second delay.
2525 * So we do not use TCP_NOPUSH on FreeBSD prior to 4.5 although it can be used
2626 * for non-keepalive HTTP connections.
2727 */
28
29
30 #define NGX_HEADERS 8
31 #define NGX_TRAILERS 4
2832
2933
3034 ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
3640 size_t hsize, fsize;
3741 ssize_t size;
3842 ngx_uint_t eintr, eagain, complete;
39 struct iovec *iov;
40 struct sf_hdtr hdtr;
4143 ngx_err_t err;
4244 ngx_buf_t *file;
4345 ngx_array_t header, trailer;
4446 ngx_event_t *wev;
4547 ngx_chain_t *cl;
48 struct sf_hdtr hdtr;
49 struct iovec *iov, headers[NGX_HEADERS], trailers[NGX_TRAILERS];
4650
4751 wev = c->write;
4852
6468
6569 send = 0;
6670 eagain = 0;
71
72 header.elts = headers;
73 header.size = sizeof(struct iovec);
74 header.nalloc = NGX_HEADERS;
75 header.pool = c->pool;
76
77 trailer.elts = trailers;
78 trailer.size = sizeof(struct iovec);
79 trailer.nalloc = NGX_TRAILERS;
80 trailer.pool = c->pool;
6781
6882 for ( ;; ) {
6983 file = NULL;
7387 complete = 0;
7488 sprev = send;
7589
76 ngx_init_array(header, c->pool, 10, sizeof(struct iovec),
77 NGX_CHAIN_ERROR);
78 ngx_init_array(trailer, c->pool, 10, sizeof(struct iovec),
79 NGX_CHAIN_ERROR);
90 header.nelts = 0;
91 trailer.nelts = 0;
8092
8193 /* create the header iovec and coalesce the neighbouring bufs */
8294
105117 iov->iov_len += size;
106118
107119 } else {
108 ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR);
120 if (!(iov = ngx_array_push(&header))) {
121 return NGX_CHAIN_ERROR;
122 }
123
109124 iov->iov_base = (void *) cl->buf->pos;
110125 iov->iov_len = size;
111126 }
176191 iov->iov_len += size;
177192
178193 } else {
179 ngx_test_null(iov, ngx_push_array(&trailer),
180 NGX_CHAIN_ERROR);
194 if (!(iov = ngx_array_push(&trailer))) {
195 return NGX_CHAIN_ERROR;
196 }
197
181198 iov->iov_base = (void *) cl->buf->pos;
182199 iov->iov_len = size;
183200 }
1616 *
1717 * Linux 2.4.21 has a new sendfile64() syscall #239.
1818 */
19
20
21 #define NGX_HEADERS 8
1922
2023
2124 ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
2730 size_t fsize;
2831 ssize_t size, sent;
2932 ngx_uint_t eintr, complete;
30 struct iovec *iov;
3133 ngx_err_t err;
3234 ngx_buf_t *file;
3335 ngx_array_t header;
3436 ngx_event_t *wev;
3537 ngx_chain_t *cl;
38 struct iovec *iov, headers[NGX_HEADERS];
3639 #if (HAVE_SENDFILE64)
3740 off_t offset;
3841 #else
4649 }
4750
4851 send = 0;
52
53 header.elts = headers;
54 header.size = sizeof(struct iovec);
55 header.nalloc = NGX_HEADERS;
56 header.pool = c->pool;
4957
5058 for ( ;; ) {
5159 file = NULL;
5462 complete = 0;
5563 sprev = send;
5664
57 ngx_init_array(header, c->pool, 10, sizeof(struct iovec),
58 NGX_CHAIN_ERROR);
65 header.nelts = 0;
5966
6067 prev = NULL;
6168 iov = NULL;
8491 iov->iov_len += size;
8592
8693 } else {
87 ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR);
94 if (!(iov = ngx_array_push(&header))) {
95 return NGX_CHAIN_ERROR;
96 }
97
8898 iov->iov_base = (void *) cl->buf->pos;
8999 iov->iov_len = size;
90100 }
66 #include <ngx_config.h>
77 #include <ngx_core.h>
88 #include <ngx_event.h>
9
10
11 #define NGX_SENDFILEVECS 16
912
1013
1114 ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in,
1821 ssize_t n;
1922 ngx_int_t eintr, complete;
2023 ngx_err_t err;
21 sendfilevec_t *sfv;
24 sendfilevec_t *sfv, sfvs[NGX_SENDFILEVECS];
2225 ngx_array_t vec;
2326 ngx_event_t *wev;
2427 ngx_chain_t *cl, *tail;
3134
3235 send = 0;
3336 complete = 0;
37
38 vec.elts = sfvs;
39 vec.size = sizeof(sendfilevec_t);
40 vec.nalloc = NGX_SENDFILEVECS;
41 vec.pool = c->pool;
3442
3543 for ( ;; ) {
3644 fd = SFV_FD_SELF;
4149 sent = 0;
4250 sprev = send;
4351
44 ngx_init_array(vec, c->pool, 10, sizeof(sendfilevec_t),
45 NGX_CHAIN_ERROR);
52 vec.nelts = 0;
4653
4754 /* create the sendfilevec and coalesce the neighbouring bufs */
4855
6572 sfv->sfv_len += size;
6673
6774 } else {
68 ngx_test_null(sfv, ngx_push_array(&vec), NGX_CHAIN_ERROR);
75 if (!(sfv = ngx_array_push(&vec))) {
76 return NGX_CHAIN_ERROR;
77 }
78
6979 sfv->sfv_fd = SFV_FD_SELF;
7080 sfv->sfv_flag = 0;
7181 sfv->sfv_off = (off_t) (uintptr_t) cl->buf->pos;
95105 sfv->sfv_len += size;
96106
97107 } else {
98 ngx_test_null(sfv, ngx_push_array(&vec), NGX_CHAIN_ERROR);
108 if (!(sfv = ngx_array_push(&vec))) {
109 return NGX_CHAIN_ERROR;
110 }
111
99112 fd = cl->buf->file->fd;
100113 sfv->sfv_fd = fd;
101114 sfv->sfv_flag = 0;