|
|
|
@ -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: |
|
|
|
|