client Result include peerName
This commit is contained in:
+2
-2
@@ -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
|
||||
|
||||
@@ -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
@@ -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
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user