Mercurial > hg > nginx
comparison src/event/ngx_event_connect.c @ 561:e48ebafc6939 release-0.3.2
nginx-0.3.2-RELEASE import
*) Feature: the Sun Studio 10 C compiler support.
*) Feature: the "proxy_upstream_max_fails",
"proxy_upstream_fail_timeout", "fastcgi_upstream_max_fails", and
"fastcgi_upstream_fail_timeout" directives.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 12 Oct 2005 13:50:36 +0000 |
parents | 0148586012ab |
children | 9c2f3ed7a247 |
comparison
equal
deleted
inserted
replaced
560:8886091eddd2 | 561:e48ebafc6939 |
---|---|
12 | 12 |
13 ngx_int_t | 13 ngx_int_t |
14 ngx_event_connect_peer(ngx_peer_connection_t *pc) | 14 ngx_event_connect_peer(ngx_peer_connection_t *pc) |
15 { | 15 { |
16 int rc; | 16 int rc; |
17 ngx_uint_t instance, level, i; | 17 ngx_uint_t level, i; |
18 u_int event; | 18 u_int event; |
19 time_t now; | 19 time_t now; |
20 ngx_err_t err; | 20 ngx_err_t err; |
21 ngx_peer_t *peer; | 21 ngx_peer_t *peer; |
22 ngx_socket_t s; | 22 ngx_socket_t s; |
79 } | 79 } |
80 | 80 |
81 for ( ;; ) { | 81 for ( ;; ) { |
82 peer = &pc->peers->peer[pc->cur_peer]; | 82 peer = &pc->peers->peer[pc->cur_peer]; |
83 | 83 |
84 if (peer->fails <= peer->max_fails) { | 84 if (peer->max_fails == 0 || peer->fails <= peer->max_fails) { |
85 break; | 85 break; |
86 } | 86 } |
87 | 87 |
88 if (now - peer->accessed > peer->fail_timeout) { | 88 if (now - peer->accessed > peer->fail_timeout) { |
89 peer->fails = 0; | 89 peer->fails = 0; |
136 ngx_close_socket_n "failed"); | 136 ngx_close_socket_n "failed"); |
137 } | 137 } |
138 | 138 |
139 return NGX_ERROR; | 139 return NGX_ERROR; |
140 } | 140 } |
141 | |
142 rev = c->read; | |
143 wev = c->write; | |
144 | |
145 ngx_memzero(c, sizeof(ngx_connection_t)); | |
146 | |
147 c->read = rev; | |
148 c->write = wev; | |
149 c->fd = s; | |
150 c->log = pc->log; | |
151 | 141 |
152 if (pc->rcvbuf) { | 142 if (pc->rcvbuf) { |
153 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, | 143 if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, |
154 (const void *) &pc->rcvbuf, sizeof(int)) == -1) { | 144 (const void *) &pc->rcvbuf, sizeof(int)) == -1) { |
155 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, | 145 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, |
189 if (peer->sockaddr->sa_family != AF_INET) { | 179 if (peer->sockaddr->sa_family != AF_INET) { |
190 c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; | 180 c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; |
191 c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED; | 181 c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED; |
192 } | 182 } |
193 | 183 |
194 instance = rev->instance; | 184 rev = c->read; |
195 | 185 wev = c->write; |
196 ngx_memzero(rev, sizeof(ngx_event_t)); | |
197 ngx_memzero(wev, sizeof(ngx_event_t)); | |
198 | |
199 rev->instance = !instance; | |
200 wev->instance = !instance; | |
201 | |
202 rev->index = NGX_INVALID_INDEX; | |
203 wev->index = NGX_INVALID_INDEX; | |
204 | |
205 rev->data = c; | |
206 wev->data = c; | |
207 | |
208 wev->write = 1; | |
209 | 186 |
210 rev->log = pc->log; | 187 rev->log = pc->log; |
211 wev->log = pc->log; | 188 wev->log = pc->log; |
212 | 189 |
213 pc->connection = c; | 190 pc->connection = c; |
214 | 191 |
215 /* | 192 /* |
216 * TODO: MT: - atomic increment (x86: lock xadd) | 193 * TODO: MT: - ngx_atomic_fetch_add() |
217 * or protection by critical section or mutex | 194 * or protection by critical section or mutex |
218 * | 195 * |
219 * TODO: MP: - allocated in a shared memory | 196 * TODO: MP: - allocated in a shared memory |
220 * - atomic increment (x86: lock xadd) | 197 * - ngx_atomic_fetch_add() |
221 * or protection by critical section or mutex | 198 * or protection by critical section or mutex |
222 */ | 199 */ |
223 | 200 |
224 c->number = ngx_atomic_inc(ngx_connection_counter); | 201 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); |
225 | 202 |
226 #if (NGX_THREADS) | 203 #if (NGX_THREADS) |
227 rev->lock = pc->lock; | 204 rev->lock = pc->lock; |
228 wev->lock = pc->lock; | 205 wev->lock = pc->lock; |
229 rev->own_lock = &c->lock; | 206 rev->own_lock = &c->lock; |