comparison src/event/ngx_event_connect.c @ 120:b776ad95d96d

nginx-0.0.1-2003-07-21-20:24:25 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 21 Jul 2003 16:24:25 +0000
parents cd54bcbaf3b5
children b3655b21375a
comparison
equal deleted inserted replaced
119:cd54bcbaf3b5 120:b776ad95d96d
1 1
2 #include <ngx_event_connect.h> 2 #include <ngx_event_connect.h>
3 3
4 4
5 int ngx_event_connect_peer(ngx_connect_peer_t *cp) 5 int ngx_event_connect_peer(ngx_peer_connecttion_t *pc)
6 { 6 {
7 time_t now; 7 time_t now;
8 8
9 /* TODO: cached connection */ 9 /* TODO: cached connection */
10 10
11 now = ngx_time(); 11 now = ngx_time();
12 12
13 if (cp->peers->number > 1) { 13 if (pc->peers->number > 1) {
14 14
15 /* there are several peers */ 15 /* there are several peers */
16 16
17 if (cp->tries == cp->peers->number) { 17 if (pc->tries == pc->peers->number) {
18 18
19 /* it's a first try - get a current peer */ 19 /* it's a first try - get a current peer */
20 20
21 /* Here is the race condition when the peers are shared between 21 /* Here is the race condition when the peers are shared between
22 the threads or the processes but it should not be serious */ 22 the threads or the processes but it should not be serious */
23 23
24 cp->cur_peer = cp->peers->current++; 24 pc->cur_peer = pc->peers->current++;
25 25
26 if (cp->peers->current >= cp->peers->number) { 26 if (cp->peers->current >= cp->peers->number) {
27 cp->peers->current = 0; 27 pc->peers->current = 0;
28 } 28 }
29 29
30 /* the end of the race condition */ 30 /* the end of the race condition */
31 31
32 #if (NGX_MULTITHREADED || NGX_MULTIPROCESSED) 32 #if (NGX_MULTITHREADED || NGX_MULTIPROCESSED)
33 /* eliminate the sequences of the race condition */ 33 /* eliminate the sequences of the race condition */
34 34
35 if (cp->cur_peer >= cp->peers->number) { 35 if (pc->cur_peer >= pc->peers->number) {
36 cp->cur_peer = 0; 36 pc->cur_peer = 0;
37 } 37 }
38 #endif 38 #endif
39 } 39 }
40 40
41 if (cp->peers->max_fails > 0) { 41 if (pc->peers->max_fails > 0) {
42 42
43 /* the peers support a fault tolerance */ 43 /* the peers support a fault tolerance */
44 44
45 for ( ;; ) { 45 for ( ;; ) {
46 peer = &cp->peers->peers[cp->cur_peer]; 46 peer = &pc->peers->peers[pc->cur_peer];
47 47
48 /* Here is the race condition when the peers are shared between 48 /* Here is the race condition when the peers are shared between
49 the threads or the processes but it should not be serious */ 49 the threads or the processes but it should not be serious */
50 50
51 if (peer->fails <= cp->peers->max_fails 51 if (peer->fails <= pc->peers->max_fails
52 || (now - peer->accessed > cp->peers->fail_timeout)) 52 || (now - peer->accessed > pc->peers->fail_timeout))
53 { 53 {
54 break; 54 break;
55 } 55 }
56 56
57 /* the end of the race condition */ 57 /* the end of the race condition */
58 58
59 cp->cur_peer++; 59 pc->cur_peer++;
60 60
61 if (cp->cur_peer >= cp->peers->number) { 61 if (pc->cur_peer >= pc->peers->number) {
62 cp->cur_peer = 0; 62 pc->cur_peer = 0;
63 } 63 }
64 64
65 cp->tries--; 65 pc->tries--;
66 66
67 if (cp->tries == 0) { 67 if (pc->tries == 0) {
68 return NGX_ERROR; 68 return NGX_ERROR;
69 } 69 }
70 } 70 }
71 } 71 }
72 } 72 }