Skip to content

Commit

Permalink
RPC client option: -rpcwait, to wait for server start
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinandresen committed Nov 20, 2013
1 parent 96aaf00 commit 480e75c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/bitcoinrpc.cpp
Expand Up @@ -1124,8 +1124,16 @@ Object CallRPC(const string& strMethod, const Array& params)
asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context);
SSLIOStreamDevice<asio::ip::tcp> d(sslStream, fUseSSL);
iostreams::stream< SSLIOStreamDevice<asio::ip::tcp> > stream(d);
if (!d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(Params().RPCPort()))))
throw runtime_error("couldn't connect to server");

bool fWait = GetBoolArg("-rpcwait", false); // -rpcwait means try until server has started
do {
bool fConnected = d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(Params().RPCPort())));
if (fConnected) break;
if (fWait)
MilliSleep(1000);
else
throw runtime_error("couldn't connect to server");
} while (fWait);

// HTTP basic authentication
string strUserPass64 = EncodeBase64(mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]);
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Expand Up @@ -253,6 +253,7 @@ std::string HelpMessage(HelpMessageMode hmm)
if (hmm == HMM_BITCOIND || hmm == HMM_BITCOIN_CLI)
{
strUsage += " -rpcconnect=<ip> " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n";
strUsage += " -rpcwait " + _("Wait for RPC server to start") + "\n";
}

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

0 comments on commit 480e75c

Please sign in to comment.