From 6ba31accb2fa05d49cea82ff394ff8ced62a665f Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 30 Dec 2012 17:01:34 -0800 Subject: [PATCH] Fixes for rpc subscriptions. --- src/cpp/ripple/RPCSub.cpp | 34 ++++++++++++++++++++++++++++++---- src/cpp/ripple/RPCSub.h | 2 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/cpp/ripple/RPCSub.cpp b/src/cpp/ripple/RPCSub.cpp index a0759cca46..35ec7b7197 100644 --- a/src/cpp/ripple/RPCSub.cpp +++ b/src/cpp/ripple/RPCSub.cpp @@ -4,10 +4,29 @@ #include "CallRPC.h" +SETUP_LOG(); + RPCSub::RPCSub(const std::string& strUrl, const std::string& strUsername, const std::string& strPassword) : mUrl(strUrl), mUsername(strUsername), mPassword(strPassword) { - mId = 1; + std::string strScheme; + std::string strPath; + + if (!parseUrl(strUrl, strScheme, mIp, mPort, strPath)) + { + throw std::runtime_error("Failed to parse url."); + } + else if (strScheme != "http") + { + throw std::runtime_error("Only http is supported."); + } + else if (!strPath.empty()) + { + // XXX FIXME: support path + throw std::runtime_error("Only empty path is supported."); + } + + mSeq = 1; } void RPCSub::sendThread() @@ -33,7 +52,7 @@ void RPCSub::sendThread() mDeque.pop_front(); jvEvent = pEvent.second; - jvEvent["id"] = pEvent.first; + jvEvent["seq"] = pEvent.first; bSend = true; } @@ -43,7 +62,14 @@ void RPCSub::sendThread() if (bSend) { // Drop result. - (void) callRPC(mIp, mPort, mUsername, mPassword, "event", jvEvent); + try + { + (void) callRPC(mIp, mPort, mUsername, mPassword, "event", jvEvent); + } + catch (const std::exception& e) + { + cLog(lsDEBUG) << boost::str(boost::format("callRPC exception: %s") % e.what()); + } sendThread(); } @@ -61,7 +87,7 @@ void RPCSub::send(const Json::Value& jvObj) mDeque.pop_back(); } - mDeque.push_back(std::make_pair(mId++, jvObj)); + mDeque.push_back(std::make_pair(mSeq++, jvObj)); if (!mSending) { diff --git a/src/cpp/ripple/RPCSub.h b/src/cpp/ripple/RPCSub.h index 2e4921ec14..1ab72c9171 100644 --- a/src/cpp/ripple/RPCSub.h +++ b/src/cpp/ripple/RPCSub.h @@ -18,7 +18,7 @@ class RPCSub : public InfoSub std::string mUsername; std::string mPassword; - int mId; // Next id to allocate. + int mSeq; // Next id to allocate. bool mSending; // Sending threead is active.