MCPcopy Create free account
hub / github.com/apache/trafficserver / invoke

Method invoke

include/shared/rpc/RPCClient.h:50–89  ·  view source on GitHub ↗

@brief invoke the remote function using the passed jsonrpc message string. This function will connect with the remote rpc node and send the passed json string. If you don't want to deal with the endode/decode you can just call @c invoke(JSONRPCRequest const &req). @throw runtime_error

Source from the content-addressed store, hash-verified

48 /// endode/decode you can just call @c invoke(JSONRPCRequest const &req).
49 /// @throw runtime_error
50 std::string
51 invoke(std::string_view req, std::chrono::milliseconds timeout_ms, int attempts)
52 {
53 std::string err_text; // for error messages.
54 try {
55 _client.connect();
56 if (!_client.is_closed()) {
57 std::string resp;
58 _client.send(req);
59 switch (_client.read_all(resp, timeout_ms, attempts)) {
60 case IPCSocketClient::ReadStatus::NO_ERROR: {
61 _client.disconnect();
62 return resp;
63 }
64 case IPCSocketClient::ReadStatus::BUFFER_FULL:
65 // we don't expect this to happen as client will not let us know about
66 // this for now. Keep this in case we decide to put a limit on
67 // responses.
68 ink_assert(!"Buffer full, not enough space to read the response.");
69 break;
70 case IPCSocketClient::ReadStatus::READ_ERROR:
71 err_text = swoc::bwprint(err_text, "READ_ERROR: Error while reading response. {}({})", std::strerror(errno), errno);
72 break;
73 case IPCSocketClient::ReadStatus::TIMEOUT:
74 err_text = swoc::bwprint(err_text, "TIMEOUT: Couldn't get the response. {}({})", std::strerror(errno), errno);
75 break;
76 default:
77 err_text = "Something happened, we can't read the response. Unknown error.";
78 break;
79 }
80 } else {
81 swoc::bwprint(err_text, "Node seems not available: {}", std ::strerror(errno));
82 }
83 } catch (std::exception const &ex) {
84 swoc::bwprint(err_text, "RPC Node Error: {}", ex.what());
85 }
86 _client.disconnect();
87 // If we've got this far, then there must be an error to report back.
88 throw std::runtime_error(err_text);
89 }
90
91 /// @brief Invoke the rpc node passing the JSONRPC objects.
92 /// This function will connect with the remote rpc node and send the passed objects which will be encoded and decoded using the

Callers

nothing calls this directly

Calls 7

encodeFunction · 0.85
disconnectMethod · 0.80
connectMethod · 0.45
is_closedMethod · 0.45
sendMethod · 0.45
read_allMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected