diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2013-11-20 15:54:13 +1000 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2013-11-20 16:00:51 +1000 |
commit | 480e75ceabdf83438023d066ed494c371fcef239 (patch) | |
tree | 3c9913ff526e0c0ecd53094fa786a6fc91409790 /src/bitcoinrpc.cpp | |
parent | 96aaf006a5dcb67f1b4f26a60b214a18572e3d87 (diff) |
RPC client option: -rpcwait, to wait for server start
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r-- | src/bitcoinrpc.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index c715f13fd2..343bb1a5e8 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -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"]); |