nginx-0.0.1-2003-07-21-20:24:25 import

This commit is contained in:
Igor Sysoev 2003-07-21 16:24:25 +00:00
parent 890fc96596
commit 5b8d38832b
3 changed files with 33 additions and 18 deletions

View File

@ -319,6 +319,19 @@ static int ngx_select_process_events(ngx_log_t *log)
if (timer) { if (timer) {
#if (HAVE_SELECT_CHANGE_TIMEOUT) #if (HAVE_SELECT_CHANGE_TIMEOUT)
delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000); delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000);
#if 0
/*
* update the cached time if the sum of the last deltas
* is more than 0.5 seconds
*/
deltas += delta;
if (deltas > 500000) {
ngx_cached_time = ngx_real_time();
deltas = 0;
}
#endif
#else #else
delta = ngx_msec() - delta; delta = ngx_msec() - delta;
#endif #endif

View File

@ -2,7 +2,7 @@
#include <ngx_event_connect.h> #include <ngx_event_connect.h>
int ngx_event_connect_peer(ngx_connect_peer_t *cp) int ngx_event_connect_peer(ngx_peer_connecttion_t *pc)
{ {
time_t now; time_t now;
@ -10,21 +10,21 @@ int ngx_event_connect_peer(ngx_connect_peer_t *cp)
now = ngx_time(); now = ngx_time();
if (cp->peers->number > 1) { if (pc->peers->number > 1) {
/* there are several peers */ /* there are several peers */
if (cp->tries == cp->peers->number) { if (pc->tries == pc->peers->number) {
/* it's a first try - get a current peer */ /* it's a first try - get a current peer */
/* Here is the race condition when the peers are shared between /* Here is the race condition when the peers are shared between
the threads or the processes but it should not be serious */ the threads or the processes but it should not be serious */
cp->cur_peer = cp->peers->current++; pc->cur_peer = pc->peers->current++;
if (cp->peers->current >= cp->peers->number) { if (cp->peers->current >= cp->peers->number) {
cp->peers->current = 0; pc->peers->current = 0;
} }
/* the end of the race condition */ /* the end of the race condition */
@ -32,39 +32,39 @@ int ngx_event_connect_peer(ngx_connect_peer_t *cp)
#if (NGX_MULTITHREADED || NGX_MULTIPROCESSED) #if (NGX_MULTITHREADED || NGX_MULTIPROCESSED)
/* eliminate the sequences of the race condition */ /* eliminate the sequences of the race condition */
if (cp->cur_peer >= cp->peers->number) { if (pc->cur_peer >= pc->peers->number) {
cp->cur_peer = 0; pc->cur_peer = 0;
} }
#endif #endif
} }
if (cp->peers->max_fails > 0) { if (pc->peers->max_fails > 0) {
/* the peers support a fault tolerance */ /* the peers support a fault tolerance */
for ( ;; ) { for ( ;; ) {
peer = &cp->peers->peers[cp->cur_peer]; peer = &pc->peers->peers[pc->cur_peer];
/* Here is the race condition when the peers are shared between /* Here is the race condition when the peers are shared between
the threads or the processes but it should not be serious */ the threads or the processes but it should not be serious */
if (peer->fails <= cp->peers->max_fails if (peer->fails <= pc->peers->max_fails
|| (now - peer->accessed > cp->peers->fail_timeout)) || (now - peer->accessed > pc->peers->fail_timeout))
{ {
break; break;
} }
/* the end of the race condition */ /* the end of the race condition */
cp->cur_peer++; pc->cur_peer++;
if (cp->cur_peer >= cp->peers->number) { if (pc->cur_peer >= pc->peers->number) {
cp->cur_peer = 0; pc->cur_peer = 0;
} }
cp->tries--; pc->tries--;
if (cp->tries == 0) { if (pc->tries == 0) {
return NGX_ERROR; return NGX_ERROR;
} }
} }

View File

@ -25,7 +25,7 @@ typedef struct {
int fail_timeout; int fail_timeout;
/* ngx_mutex_t *mutex; */ /* ngx_mutex_t *mutex; */
/* ngx_connection_t *cached; */ ngx_connection_t *cached;
ngx_peer_t peers[1]; ngx_peer_t peers[1];
} ngx_peers_t; } ngx_peers_t;
@ -36,8 +36,10 @@ typedef struct {
int cur_peer; int cur_peer;
int tries; int tries;
ngx_connection_t *connection;
unsigned cached:1; unsigned cached:1;
} ngx_connect_peer_t; } ngx_peer_connection_t;
#endif /* _NGX_EVENT_CONNECT_H_INCLUDED_ */ #endif /* _NGX_EVENT_CONNECT_H_INCLUDED_ */