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. 25
      src/generator.c

1
src/ckpool.h

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

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

Loading…
Cancel
Save