Mercurial > hg > nginx-quic
comparison src/http/ngx_http_busy_lock.c @ 175:e92c2c647c57
nginx-0.0.1-2003-11-05-20:03:41 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 05 Nov 2003 17:03:41 +0000 |
parents | ea464a6c0581 |
children | c0552e5ab567 |
comparison
equal
deleted
inserted
replaced
174:ea464a6c0581 | 175:e92c2c647c57 |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_http.h> | 4 #include <ngx_http.h> |
5 | |
6 | |
7 int ngx_http_busy_lock(ngx_http_busy_lock_t *bl, u_char *md5) | |
8 { | |
9 int i, b, busy, free; | |
10 u_int mask; | |
11 | |
12 b = 0; | |
13 busy = 0; | |
14 free = -1; | |
15 | |
16 #if (NGX_SUPPRESS_WARN) | |
17 mask = 0; | |
18 #endif | |
19 | |
20 for (i = 0; i < bl->max_conn; i++) { | |
21 | |
22 if ((b & 7) == 0) { | |
23 mask = bl->busy_mask[i / 8]; | |
24 } | |
25 | |
26 if (mask & 1) { | |
27 if (ngx_memcmp(&bl->busy[i * 16], md5, 16) == 0) { | |
28 return NGX_AGAIN; | |
29 } | |
30 busy++; | |
31 | |
32 } else if (free == -1) { | |
33 free = i; | |
34 } | |
35 | |
36 if (busy == bl->busy_n) { | |
37 if (busy < bl->max_conn) { | |
38 free = i + 1; | |
39 } | |
40 | |
41 break; | |
42 } | |
43 | |
44 mask >>= 1; | |
45 b++; | |
46 } | |
47 | |
48 if (free == -1) { | |
49 return NGX_ERROR; | |
50 } | |
51 | |
52 ngx_memcpy(&bl->busy[free * 16], md5, 16); | |
53 bl->busy_mask[free / 8] |= free % 8; | |
54 | |
55 bl->busy_n++; | |
56 bl->conn_n++; | |
57 | |
58 return NGX_OK; | |
59 } | |
5 | 60 |
6 | 61 |
7 char *ngx_http_set_busy_lock_slot(ngx_conf_t *cf, ngx_command_t *cmd, | 62 char *ngx_http_set_busy_lock_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
8 void *conf) | 63 void *conf) |
9 { | 64 { |
24 } | 79 } |
25 *blp = bl; | 80 *blp = bl; |
26 | 81 |
27 value = (ngx_str_t *) cf->args->elts; | 82 value = (ngx_str_t *) cf->args->elts; |
28 | 83 |
29 for (i = 1; i < 3; i++) { | 84 for (i = 1; i < 4; i++) { |
30 | 85 |
31 if (value[i].len > 2 && ngx_strncasecmp(value[i].data, "c:", 2) == 0) { | 86 if (value[i].len > 2 && ngx_strncasecmp(value[i].data, "c:", 2) == 0) { |
32 if (bl->max_conn) { | 87 if (bl->max_conn) { |
33 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 88 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
34 "duplicate \"%s\"", value[i].data); | 89 "duplicate \"%s\"", value[i].data); |
66 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 121 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
67 "duplicate timeout \"%s\"", value[i].data); | 122 "duplicate timeout \"%s\"", value[i].data); |
68 return NGX_CONF_ERROR; | 123 return NGX_CONF_ERROR; |
69 } | 124 } |
70 | 125 |
71 bl->timeout = ngx_parse_time(&value[1], 0); | 126 bl->timeout = ngx_parse_time(&value[1], 1); |
72 if (bl->timeout == NGX_ERROR) { | 127 if (bl->timeout == NGX_ERROR) { |
73 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 128 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
74 "invalid timeout \"%s\"", value[i].data); | 129 "invalid timeout \"%s\"", value[i].data); |
75 return NGX_CONF_ERROR; | 130 return NGX_CONF_ERROR; |
76 } | 131 } |