Browse Source

Don't block on dead servers if possible when calling server_alive from the gen_loop

master
Con Kolivas 9 years ago
parent
commit
bfbe3a1039
  1. 1
      src/ckpool.h
  2. 19
      src/generator.c

1
src/ckpool.h

@ -111,6 +111,7 @@ struct server_instance {
char *auth;
char *pass;
bool notify;
bool alive;
connsock_t cs;
void *data; // Private data

19
src/generator.c

@ -147,6 +147,7 @@ static bool server_alive(ckpool_t *ckp, server_instance_t *si, bool pinging)
/* Has this server already been reconnected? */
if (cs->fd > 0)
return true;
si->alive = false;
if (!extract_sockaddr(si->url, &cs->url, &cs->port)) {
LOGWARNING("Failed to extract address from %s", si->url);
return ret;
@ -189,6 +190,7 @@ out:
/* Close and invalidate the file handle */
Close(cs->fd);
} else {
si->alive = true;
LOGNOTICE("Server alive: %s:%s", cs->url, cs->port);
keep_sockalive(cs->fd);
}
@ -207,19 +209,30 @@ retry:
if (!ping_main(ckp))
goto out;
/* First find a server that is already flagged alive if possible
* without blocking on server_alive() */
for (i = 0; i < ckp->btcds; i++) {
server_instance_t *si = ckp->servers[i];
if (si->alive) {
alive = si;
goto living;
}
}
/* No servers flagged alive, try to connect to them blocking */
for (i = 0; i < ckp->btcds; i++) {
server_instance_t *si = ckp->servers[i];
if (server_alive(ckp, si, false)) {
alive = si;
break;
goto living;
}
}
if (!alive) {
LOGWARNING("CRITICAL: No bitcoinds active!");
sleep(5);
goto retry;
}
living:
cs = &alive->cs;
LOGINFO("Connected to live server %s:%s", cs->url, cs->port);
out:

Loading…
Cancel
Save