nginx-0.0.10-2004-09-14-23:39:54 import
Igor Sysoev
17 years ago
222 | 222 | #define ngx_log_debug4(level, log, err, fmt, arg1, arg2, arg3, arg4) |
223 | 223 | #define ngx_log_debug5(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5) |
224 | 224 | #define ngx_log_debug6(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6) |
225 | #define ngx_log_debug7(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, arg6, | |
226 | arg7) | |
225 | #define ngx_log_debug7(level, log, err, fmt, arg1, arg2, arg3, arg4, arg5, \ | |
226 | arg6, arg7) | |
227 | 227 | |
228 | 228 | #endif |
229 | 229 |
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | /* alloc a new pool block */ | |
88 | /* allocate a new pool block */ | |
89 | 89 | |
90 | 90 | if (!(n = ngx_create_pool((size_t) (p->end - (char *) p), p->log))) { |
91 | 91 | return NULL; |
98 | 98 | return m; |
99 | 99 | } |
100 | 100 | |
101 | /* alloc a large block */ | |
101 | /* allocate a large block */ | |
102 | 102 | |
103 | 103 | large = NULL; |
104 | 104 | last = NULL; |
61 | 61 | ngx_uint_t ngx_accept_mutex_held; |
62 | 62 | ngx_msec_t ngx_accept_mutex_delay; |
63 | 63 | ngx_int_t ngx_accept_disabled; |
64 | ||
65 | ||
66 | #if (NGX_STAT_STUB) | |
67 | ||
68 | ngx_atomic_t ngx_stat_accepted0; | |
69 | ngx_atomic_t *ngx_stat_accepted = &ngx_stat_accepted0; | |
70 | ngx_atomic_t ngx_stat_requests0; | |
71 | ngx_atomic_t *ngx_stat_requests = &ngx_stat_requests0; | |
72 | ngx_atomic_t ngx_stat_active0; | |
73 | ngx_atomic_t *ngx_stat_active = &ngx_stat_active0; | |
74 | ngx_atomic_t ngx_stat_reading0; | |
75 | ngx_atomic_t *ngx_stat_reading = &ngx_stat_reading0; | |
76 | ngx_atomic_t ngx_stat_writing0; | |
77 | ngx_atomic_t *ngx_stat_writing = &ngx_stat_reading0; | |
78 | ||
79 | #endif | |
64 | 80 | |
65 | 81 | |
66 | 82 | |
186 | 202 | size = 128 /* ngx_accept_mutex */ |
187 | 203 | + 128; /* ngx_connection_counter */ |
188 | 204 | |
205 | #if (NGX_STAT_STUB) | |
206 | ||
207 | size += 128 /* ngx_stat_accepted */ | |
208 | + 128 /* ngx_stat_requests */ | |
209 | + 128 /* ngx_stat_active */ | |
210 | + 128 /* ngx_stat_reading */ | |
211 | + 128; /* ngx_stat_writing */ | |
212 | ||
213 | #endif | |
214 | ||
189 | 215 | if (!(shared = ngx_create_shared_memory(size, cycle->log))) { |
190 | 216 | return NGX_ERROR; |
191 | 217 | } |
192 | 218 | |
193 | 219 | ngx_accept_mutex_ptr = (ngx_atomic_t *) shared; |
194 | 220 | ngx_connection_counter = (ngx_atomic_t *) (shared + 128); |
221 | ||
222 | #if (NGX_STAT_STUB) | |
223 | ||
224 | ngx_stat_accepted = (ngx_atomic_t *) (shared + 2 * 128); | |
225 | ngx_stat_requests = (ngx_atomic_t *) (shared + 3 * 128); | |
226 | ngx_stat_active = (ngx_atomic_t *) (shared + 4 * 128); | |
227 | ngx_stat_reading = (ngx_atomic_t *) (shared + 5 * 128); | |
228 | ngx_stat_writing = (ngx_atomic_t *) (shared + 6 * 128); | |
229 | ||
230 | #endif | |
195 | 231 | |
196 | 232 | ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
197 | 233 | "counter: " PTR_FMT ", %d", |
432 | 432 | extern ngx_int_t ngx_accept_disabled; |
433 | 433 | |
434 | 434 | |
435 | #if (NGX_STAT_STUB) | |
436 | ||
437 | extern ngx_atomic_t *ngx_stat_accepted; | |
438 | extern ngx_atomic_t *ngx_stat_requests; | |
439 | extern ngx_atomic_t *ngx_stat_active; | |
440 | extern ngx_atomic_t *ngx_stat_reading; | |
441 | extern ngx_atomic_t *ngx_stat_writing; | |
442 | ||
443 | #endif | |
444 | ||
445 | ||
446 | ||
435 | 447 | #define ngx_accept_mutex_unlock() \ |
436 | 448 | if (ngx_accept_mutex_held) { \ |
437 | 449 | *ngx_accept_mutex = 0; \ |
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | #if (NGX_STAT_STUB) | |
130 | (*ngx_stat_accepted)++; | |
131 | (*ngx_stat_active)++; | |
132 | #endif | |
129 | 133 | |
130 | 134 | ngx_accept_disabled = (ngx_uint_t) s + NGX_ACCEPT_THRESHOLD |
131 | 135 | - ecf->connections; |
1177 | 1177 | ngx_http_type_t *type; |
1178 | 1178 | |
1179 | 1179 | if (lcf->types == NULL) { |
1180 | ngx_test_null(lcf->types, | |
1181 | ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME | |
1182 | * sizeof(ngx_array_t)), | |
1183 | NGX_CONF_ERROR); | |
1180 | lcf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME | |
1181 | * sizeof(ngx_array_t)); | |
1182 | if (lcf->types == NULL) { | |
1183 | return NGX_CONF_ERROR; | |
1184 | } | |
1184 | 1185 | |
1185 | 1186 | for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { |
1186 | ngx_init_array(lcf->types[i], cf->pool, 5, sizeof(ngx_http_type_t), | |
1187 | NGX_CONF_ERROR); | |
1187 | if (ngx_array_init(&lcf->types[i], cf->pool, 5, | |
1188 | sizeof(ngx_http_type_t)) == NGX_ERROR) | |
1189 | { | |
1190 | return NGX_CONF_ERROR; | |
1191 | } | |
1188 | 1192 | } |
1189 | 1193 | } |
1190 | 1194 | |
1193 | 1197 | for (i = 1; i < cf->args->nelts; i++) { |
1194 | 1198 | ngx_http_types_hash_key(key, args[i]); |
1195 | 1199 | |
1196 | ngx_test_null(type, ngx_push_array(&lcf->types[key]), NGX_CONF_ERROR); | |
1200 | if (!(type = ngx_array_push(&lcf->types[key]))) { | |
1201 | return NGX_CONF_ERROR; | |
1202 | } | |
1203 | ||
1197 | 1204 | type->exten = args[i]; |
1198 | 1205 | type->type = args[0]; |
1199 | 1206 | } |
95 | 95 | { |
96 | 96 | ngx_event_t *rev; |
97 | 97 | ngx_http_log_ctx_t *ctx; |
98 | ||
99 | #if (NGX_STAT_STUB) | |
100 | (*ngx_stat_reading)++; | |
101 | #endif | |
98 | 102 | |
99 | 103 | if (!(ctx = ngx_pcalloc(c->pool, sizeof(ngx_http_log_ctx_t)))) { |
100 | 104 | ngx_http_close_connection(c); |
312 | 316 | return; |
313 | 317 | } |
314 | 318 | |
315 | r->cleanup.elts = ngx_palloc(r->pool, 5 * sizeof(ngx_http_cleanup_t)); | |
316 | if (r->cleanup.elts == NULL) { | |
319 | if (ngx_array_init(&r->cleanup, r->pool, 5, sizeof(ngx_http_cleanup_t)) | |
320 | == NGX_ERROR) | |
321 | { | |
317 | 322 | ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
318 | 323 | ngx_http_close_connection(c); |
319 | 324 | return; |
320 | 325 | } |
321 | ||
322 | /* | |
323 | * set by ngx_pcalloc(): | |
324 | * | |
325 | * r->cleanup.nelts = 0; | |
326 | */ | |
327 | r->cleanup.nalloc = 5; | |
328 | r->cleanup.size = sizeof(ngx_http_cleanup_t); | |
329 | r->cleanup.pool = r->pool; | |
330 | 326 | |
331 | 327 | |
332 | 328 | if (ngx_list_init(&r->headers_out.headers, r->pool, 20, |
358 | 354 | r->headers_out.last_modified_time = -1; |
359 | 355 | |
360 | 356 | r->http_state = NGX_HTTP_READING_REQUEST_STATE; |
357 | ||
358 | #if (NGX_STAT_STUB) | |
359 | (*ngx_stat_requests)++; | |
360 | #endif | |
361 | 361 | |
362 | 362 | rev->event_handler(rev); |
363 | 363 | } |
865 | 865 | if (rev->timer_set) { |
866 | 866 | ngx_del_timer(rev); |
867 | 867 | } |
868 | ||
869 | #if (NGX_STAT_STUB) | |
870 | (*ngx_stat_reading)--; | |
871 | (*ngx_stat_writing)++; | |
872 | #endif | |
868 | 873 | |
869 | 874 | rev->event_handler = ngx_http_block_read; |
870 | 875 | ngx_http_handler(r); |
1142 | 1147 | } |
1143 | 1148 | |
1144 | 1149 | if (rc == NGX_HTTP_CLIENT_CLOSED_REQUEST || r->closed) { |
1150 | ||
1151 | #if (NGX_STAT_STUB) | |
1152 | (*ngx_stat_writing)--; | |
1153 | #endif | |
1154 | ||
1145 | 1155 | ngx_http_close_request(r, 0); |
1146 | 1156 | ngx_http_close_connection(r->connection); |
1147 | 1157 | return; |
1152 | 1162 | return; |
1153 | 1163 | |
1154 | 1164 | } else if (rc == NGX_ERROR) { |
1165 | ||
1166 | #if (NGX_STAT_STUB) | |
1167 | (*ngx_stat_writing)--; | |
1168 | #endif | |
1169 | ||
1155 | 1170 | ngx_http_close_request(r, 0); |
1156 | 1171 | ngx_http_close_connection(r->connection); |
1157 | 1172 | return; |
1160 | 1175 | ngx_http_set_write_handler(r); |
1161 | 1176 | return; |
1162 | 1177 | } |
1178 | ||
1179 | #if (NGX_STAT_STUB) | |
1180 | (*ngx_stat_writing)--; | |
1181 | #endif | |
1163 | 1182 | |
1164 | 1183 | if (r->connection->read->timer_set) { |
1165 | 1184 | ngx_del_timer(r->connection->read); |
1886 | 1905 | ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
1887 | 1906 | "close http connection: %d", c->fd); |
1888 | 1907 | |
1908 | #if (NGX_STAT_STUB) | |
1909 | (*ngx_stat_active)--; | |
1910 | #endif | |
1911 | ||
1889 | 1912 | ngx_close_connection(c); |
1890 | 1913 | } |
1891 | 1914 |
145 | 145 | size_t connection_type; |
146 | 146 | ssize_t keep_alive_n; |
147 | 147 | |
148 | unsigned msie; | |
149 | unsigned msie4; | |
148 | unsigned msie:1; | |
149 | unsigned msie4:1; | |
150 | 150 | } ngx_http_headers_in_t; |
151 | 151 | |
152 | 152 |
43 | 43 | #if 0 |
44 | 44 | peers->peers[0].addr = inet_addr("81.19.69.70"); |
45 | 45 | peers->peers[0].addr_port_text.len = sizeof("81.19.69.70:110") - 1; |
46 | peers->peers[0].addr_port_text.data = "81.19.69.70:110"; | |
46 | peers->peers[0].addr_port_text.data = (u_char *) "81.19.69.70:110"; | |
47 | 47 | peers->peers[0].port = htons(110); |
48 | 48 | #else |
49 | 49 | peers->peers[0].addr = inet_addr("81.19.64.101"); |
50 | 50 | peers->peers[0].addr_port_text.len = sizeof("81.19.64.101:110") - 1; |
51 | peers->peers[0].addr_port_text.data = "81.19.64.101:110"; | |
51 | peers->peers[0].addr_port_text.data = (u_char *) "81.19.64.101:110"; | |
52 | 52 | peers->peers[0].port = htons(110); |
53 | 53 | #endif |
54 | 54 |