Skip to content

Commit 34f5b0a

Browse files
committed
Merge pull request #3283 from gavinandresen/rpcwait
RPC client option: -rpcwait, to wait for server start
2 parents d980f9b + 480e75c commit 34f5b0a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/bitcoinrpc.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,16 @@ Object CallRPC(const string& strMethod, const Array& params)
11221122
asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context);
11231123
SSLIOStreamDevice<asio::ip::tcp> d(sslStream, fUseSSL);
11241124
iostreams::stream< SSLIOStreamDevice<asio::ip::tcp> > stream(d);
1125-
if (!d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(Params().RPCPort()))))
1126-
throw runtime_error("couldn't connect to server");
1125+
1126+
bool fWait = GetBoolArg("-rpcwait", false); // -rpcwait means try until server has started
1127+
do {
1128+
bool fConnected = d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(Params().RPCPort())));
1129+
if (fConnected) break;
1130+
if (fWait)
1131+
MilliSleep(1000);
1132+
else
1133+
throw runtime_error("couldn't connect to server");
1134+
} while (fWait);
11271135

11281136
// HTTP basic authentication
11291137
string strUserPass64 = EncodeBase64(mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]);

src/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ std::string HelpMessage(HelpMessageMode hmm)
253253
if (hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_CLI)
254254
{
255255
strUsage += " -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n";
256+
strUsage += " -rpcwait " + _("Wait for RPC server to start") + "\n";
256257
}
257258

258259
strUsage += " -rpcuser=<user> " + _("Username for JSON-RPC connections") + "\n";

0 commit comments

Comments
 (0)