From 9e401a35fe14dc7eb9178a94dd7b3f2c6ad5ad94 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sun, 1 Mar 2020 20:41:37 -0800 Subject: [PATCH] client Result include peerName --- src/clientget.cpp | 4 ++-- src/clientintrospect.cpp | 2 +- src/pvxs/client.h | 5 ++++- tools/info.cpp | 8 +++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/clientget.cpp b/src/clientget.cpp index ec3f089..042ede7 100644 --- a/src/clientget.cpp +++ b/src/clientget.cpp @@ -268,8 +268,8 @@ void Connection::handle_GPR(pva_app_msg_t cmd) } else if(gpr->state==GPROp::Exec) { gpr->state = GPROp::Done; - if(cmd!=CMD_PUT) - gpr->result = Result(std::move(data)); + // data always empty for CMD_PUT + gpr->result = Result(std::move(data), peerName); } else { // should be avoided above diff --git a/src/clientintrospect.cpp b/src/clientintrospect.cpp index 5ad9f37..dc9c8df 100644 --- a/src/clientintrospect.cpp +++ b/src/clientintrospect.cpp @@ -141,7 +141,7 @@ void Connection::handle_GET_FIELD() auto done = std::move(info->done); Result res; if(sts.isSuccess()) { - res = Result(std::move(prototype)); + res = Result(std::move(prototype), peerName); } else { res = Result(std::make_exception_ptr(RemoteError(sts.msg))); } diff --git a/src/pvxs/client.h b/src/pvxs/client.h index 04b8b6c..97edd55 100644 --- a/src/pvxs/client.h +++ b/src/pvxs/client.h @@ -41,9 +41,10 @@ struct PVXS_API RemoteError : public std::runtime_error class Result { Value _result; std::exception_ptr _error; + std::string _peerName; public: Result() = default; - Result(Value&& val) :_result(std::move(val)) {} + Result(Value&& val, const std::string& peerName) :_result(std::move(val)), _peerName(peerName) {} explicit Result(const std::exception_ptr& err) :_error(err) {} //! Access to the Value, or rethrow the exception @@ -53,6 +54,8 @@ public: return _result; } + const std::string peerName() const { return _peerName; } + bool error() const { return !!_error; } explicit operator bool() const { return _result || _error; } }; diff --git a/tools/info.cpp b/tools/info.cpp index a4259be..65581e8 100644 --- a/tools/info.cpp +++ b/tools/info.cpp @@ -80,7 +80,13 @@ int main(int argc, char *argv[]) ops.push_back(ctxt.info(argv[n]) .result([&argv, n, &remaining, &done](client::Result&& result) { - std::cout<