comparison src/event/ngx_event_connect.c @ 136:da00cde00e8a

nginx-0.0.1-2003-10-02-09:39:37 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 02 Oct 2003 05:39:37 +0000
parents 049e78b1f852
children 2a615b036870
comparison
equal deleted inserted replaced
135:e29909bd9b8a 136:da00cde00e8a
1 1
2 #include <ngx_config.h>
3 #include <ngx_core.h>
4 #include <ngx_event.h>
2 #include <ngx_event_connect.h> 5 #include <ngx_event_connect.h>
3 6
4 7
5 /* AF_INET only */ 8 /* AF_INET only */
6 9
7 int ngx_event_connect_peer(ngx_peer_connection_t *pc) 10 int ngx_event_connect_peer(ngx_peer_connection_t *pc)
8 { 11 {
12 int rc, instance;
9 time_t now; 13 time_t now;
10 ngx_peer_r *peer; 14 ngx_err_t err;
15 ngx_peer_t *peer;
11 ngx_socket_t s; 16 ngx_socket_t s;
12 struct sockaddr_in *addr; 17 ngx_event_t *rev, *wev;
18 ngx_connection_t *c;
19 struct sockaddr_in addr;
13 20
14 now = ngx_time(); 21 now = ngx_time();
15 22
16 /* ngx_lock_mutex(pc->peers->mutex); */ 23 /* ngx_lock_mutex(pc->peers->mutex); */
17 24
29 } 36 }
30 37
31 pc->cached = 0; 38 pc->cached = 0;
32 pc->connection = NULL; 39 pc->connection = NULL;
33 40
41 peer = &pc->peers->peers[0];
42
34 if (pc->peers->number > 1) { 43 if (pc->peers->number > 1) {
35 44
36 /* there are several peers */ 45 /* there are several peers */
37 46
38 if (pc->tries == pc->peers->number) { 47 if (pc->tries == pc->peers->number) {
39 48
40 /* it's a first try - get a current peer */ 49 /* it's a first try - get a current peer */
41 50
42 pc->cur_peer = pc->peers->current++; 51 pc->cur_peer = pc->peers->current++;
43 52
44 if (cp->peers->current >= cp->peers->number) { 53 if (pc->peers->current >= pc->peers->number) {
45 pc->peers->current = 0; 54 pc->peers->current = 0;
46 } 55 }
47 } 56 }
48 57
49 if (pc->peers->max_fails > 0) { 58 if (pc->peers->max_fails > 0) {
67 76
68 pc->tries--; 77 pc->tries--;
69 78
70 if (pc->tries == 0) { 79 if (pc->tries == 0) {
71 /* ngx_unlock_mutex(pc->peers->mutex); */ 80 /* ngx_unlock_mutex(pc->peers->mutex); */
81
72 return NGX_ERROR; 82 return NGX_ERROR;
73 } 83 }
74 } 84 }
75 } 85 }
76 } 86 }
77 87
78 /* ngx_unlock_mutex(pc->peers->mutex); */ 88 /* ngx_unlock_mutex(pc->peers->mutex); */
79 89
90 #if 0
80 pc->addr_port_text = peer->addr_port_text; 91 pc->addr_port_text = peer->addr_port_text;
92 #endif
81 93
82 s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0); 94 s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
83 95
84 if (s == -1) { 96 if (s == -1) {
85 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, 97 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
161 if (ngx_add_conn(c) == NGX_ERROR) { 173 if (ngx_add_conn(c) == NGX_ERROR) {
162 return NGX_ERROR; 174 return NGX_ERROR;
163 } 175 }
164 } 176 }
165 177
166 addr = p->sockaddr; 178 addr.sin_family = AF_INET;
167 179 addr.sin_addr.s_addr = peer->addr;
168 addr->sin_family = AF_INET; 180 addr.sin_port = htons(peer->port);
169 addr->sin_addr.s_addr = peer->addr; 181
170 addr->sin_port = htons(peer->port); 182 rc = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
171
172 rc = connect(s, p->sockaddr, sizeof(struct sockaddr_in));
173 183
174 if (rc == -1) { 184 if (rc == -1) {
175 err = ngx_socket_errno; 185 err = ngx_socket_errno;
176 if (err != NGX_EINPROGRESS) { 186 if (err != NGX_EINPROGRESS) {
177 ngx_log_error(NGX_LOG_CRIT, pc->log, err, "connect() failed"); 187 ngx_log_error(NGX_LOG_CRIT, pc->log, err, "connect() failed");
183 193
184 return NGX_CONNECT_ERROR; 194 return NGX_CONNECT_ERROR;
185 } 195 }
186 } 196 }
187 197
188 c->data = ???; 198 return NGX_OK;
189
190
191 } 199 }
192 200
193 201
194 void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc) 202 void ngx_event_connect_peer_failed(ngx_peer_connection_t *pc)
195 { 203 {