client Result include peerName

This commit is contained in:
Michael Davidsaver
2020-03-02 15:37:43 -08:00
parent e668038250
commit 9e401a35fe
4 changed files with 14 additions and 5 deletions
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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)));
}
+4 -1
View File
@@ -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; }
};
+7 -1
View File
@@ -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<<argv[n]<<"\n"<<result();
std::cout<<argv[n];
try {
auto value = result();
std::cout<<" from "<<result.peerName()<<"\n"<<result();
}catch(std::exception& e){
std::cout<<" Error: "<<e.what()<<"\n";
}
if(remaining.fetch_sub(1)==1)
done.trigger();