Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork219
Update rpclib to version 2.3.0.#799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletionslibraries/rpclib/src/rpc/client.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionlibraries/rpclib/src/rpc/client.inl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
50 changes: 29 additions & 21 deletionslibraries/rpclib/src/rpc/detail/async_writer.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletionslibraries/rpclib/src/rpc/detail/client_error.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #include "format.h" | ||
| #include "rpc/detail/client_error.h" | ||
| namespace rpc { | ||
| namespace detail { | ||
| client_error::client_error(code c, const std::string &msg) | ||
| : what_(RPCLIB_FMT::format("client error C{0:04x}: {1}", | ||
| static_cast<uint16_t>(c), msg)) {} | ||
| const char *client_error::what() const noexcept { return what_.c_str(); } | ||
| } | ||
| } | ||
10 changes: 9 additions & 1 deletionlibraries/rpclib/src/rpc/detail/log.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletionslibraries/rpclib/src/rpc/detail/response.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #include "rpc/detail/response.h" | ||
| #include "rpc/detail/log.h" | ||
| #include "rpc/detail/util.h" | ||
| #include <assert.h> | ||
| namespace rpc { | ||
| namespace detail { | ||
| response::response() : id_(0), error_(), result_(), empty_(false) {} | ||
| response::response(RPCLIB_MSGPACK::object_handle o) : response() { | ||
| response_type r; | ||
| o.get().convert(r); | ||
| // TODO: check protocol [t.szelei 2015-12-30] | ||
| id_ = std::get<1>(r); | ||
| auto &&error_obj = std::get<2>(r); | ||
| if (!error_obj.is_nil()) { | ||
| error_ = std::make_shared<RPCLIB_MSGPACK::object_handle>(); | ||
| *error_ = RPCLIB_MSGPACK::clone(error_obj); | ||
| } | ||
| result_ = std::make_shared<RPCLIB_MSGPACK::object_handle>( | ||
| std::get<3>(r), std::move(o.zone())); | ||
| } | ||
| RPCLIB_MSGPACK::sbuffer response::get_data() const { | ||
| RPCLIB_MSGPACK::sbuffer data; | ||
| response_type r(1, id_, error_ ? error_->get() : RPCLIB_MSGPACK::object(), | ||
| result_ ? result_->get() : RPCLIB_MSGPACK::object()); | ||
| RPCLIB_MSGPACK::pack(data, r); | ||
| return data; | ||
| } | ||
| uint32_t response::get_id() const { return id_; } | ||
| std::shared_ptr<RPCLIB_MSGPACK::object_handle> response::get_error() const { return error_; } | ||
| std::shared_ptr<RPCLIB_MSGPACK::object_handle> response::get_result() const { | ||
| return result_; | ||
| } | ||
| response response::empty() { | ||
| response r; | ||
| r.empty_ = true; | ||
| return r; | ||
| } | ||
| bool response::is_empty() const { return empty_; } | ||
| void response::capture_result(RPCLIB_MSGPACK::object_handle &r) { | ||
| if (!result_) { | ||
| result_ = std::make_shared<RPCLIB_MSGPACK::object_handle>(); | ||
| } | ||
| result_->set(std::move(r).get()); | ||
| } | ||
| void response::capture_error(RPCLIB_MSGPACK::object_handle &e) { | ||
| if (!error_) { | ||
| error_ = std::shared_ptr<RPCLIB_MSGPACK::object_handle>(); | ||
| } | ||
| error_->set(std::move(e).get()); | ||
| } | ||
| } /* detail */ | ||
| } /* rpc */ |
7 changes: 6 additions & 1 deletionlibraries/rpclib/src/rpc/detail/server_session.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletionslibraries/rpclib/src/rpc/dispatcher.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| #include "rpc/dispatcher.h" | ||
| #include "format.h" | ||
| #include "rpc/detail/client_error.h" | ||
| #include "rpc/this_handler.h" | ||
| namespace rpc { | ||
| namespace detail { | ||
| using detail::response; | ||
| void dispatcher::dispatch(RPCLIB_MSGPACK::sbuffer const &msg) { | ||
| auto unpacked = RPCLIB_MSGPACK::unpack(msg.data(), msg.size()); | ||
| dispatch(unpacked.get()); | ||
| } | ||
| response dispatcher::dispatch(RPCLIB_MSGPACK::object const &msg, | ||
| bool suppress_exceptions) { | ||
| switch (msg.via.array.size) { | ||
| case 3: | ||
| return dispatch_notification(msg, suppress_exceptions); | ||
| case 4: | ||
| return dispatch_call(msg, suppress_exceptions); | ||
| default: | ||
| return response::empty(); | ||
| } | ||
| } | ||
| response dispatcher::dispatch_call(RPCLIB_MSGPACK::object const &msg, | ||
| bool suppress_exceptions) { | ||
| call_t the_call; | ||
| msg.convert(the_call); | ||
| // TODO: proper validation of protocol (and responding to it) | ||
| // auto &&type = std::get<0>(the_call); | ||
| // assert(type == 0); | ||
| auto &&id = std::get<1>(the_call); | ||
| auto &&name = std::get<2>(the_call); | ||
| auto &&args = std::get<3>(the_call); | ||
| auto it_func = funcs_.find(name); | ||
| if (it_func != end(funcs_)) { | ||
| LOG_DEBUG("Dispatching call to '{}'", name); | ||
| try { | ||
| auto result = (it_func->second)(args); | ||
| return response::make_result(id, std::move(result)); | ||
| } catch (rpc::detail::client_error &e) { | ||
| return response::make_error( | ||
| id, RPCLIB_FMT::format("rpclib: {}", e.what())); | ||
| } catch (std::exception &e) { | ||
| if (!suppress_exceptions) { | ||
| throw; | ||
| } | ||
| return response::make_error( | ||
| id, | ||
| RPCLIB_FMT::format("rpclib: function '{0}' (called with {1} " | ||
| "arg(s)) " | ||
| "threw an exception. The exception " | ||
| "contained this information: {2}.", | ||
| name, args.via.array.size, e.what())); | ||
| } catch (rpc::detail::handler_error &) { | ||
| // doing nothing, the exception was only thrown to | ||
| // return immediately | ||
| } catch (rpc::detail::handler_spec_response &) { | ||
| // doing nothing, the exception was only thrown to | ||
| // return immediately | ||
| } catch (...) { | ||
| if (!suppress_exceptions) { | ||
| throw; | ||
| } | ||
| return response::make_error( | ||
| id, | ||
| RPCLIB_FMT::format("rpclib: function '{0}' (called with {1} " | ||
| "arg(s)) threw an exception. The exception " | ||
| "is not derived from std::exception. No " | ||
| "further information available.", | ||
| name, args.via.array.size)); | ||
| } | ||
| } | ||
| return response::make_error( | ||
| id, RPCLIB_FMT::format("rpclib: server could not find " | ||
| "function '{0}' with argument count {1}.", | ||
| name, args.via.array.size)); | ||
| } | ||
| response dispatcher::dispatch_notification(RPCLIB_MSGPACK::object const &msg, | ||
| bool suppress_exceptions) { | ||
| notification_t the_call; | ||
| msg.convert(the_call); | ||
| // TODO: proper validation of protocol (and responding to it) | ||
| // auto &&type = std::get<0>(the_call); | ||
| // assert(type == static_cast<uint8_t>(request_type::notification)); | ||
| auto &&name = std::get<1>(the_call); | ||
| auto &&args = std::get<2>(the_call); | ||
| auto it_func = funcs_.find(name); | ||
| if (it_func != end(funcs_)) { | ||
| LOG_DEBUG("Dispatching call to '{}'", name); | ||
| try { | ||
| auto result = (it_func->second)(args); | ||
| } catch (rpc::detail::handler_error &) { | ||
| // doing nothing, the exception was only thrown to | ||
| // return immediately | ||
| } catch (rpc::detail::handler_spec_response &) { | ||
| // doing nothing, the exception was only thrown to | ||
| // return immediately | ||
| } catch (...) { | ||
| if (!suppress_exceptions) { | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| return response::empty(); | ||
| } | ||
| void dispatcher::enforce_arg_count(std::string const &func, std::size_t found, | ||
| std::size_t expected) { | ||
| using detail::client_error; | ||
| if (found != expected) { | ||
| throw client_error( | ||
| client_error::code::wrong_arity, | ||
| RPCLIB_FMT::format( | ||
| "Function '{0}' was called with an invalid number of " | ||
| "arguments. Expected: {1}, got: {2}", | ||
| func, expected, found)); | ||
| } | ||
| } | ||
| void dispatcher::enforce_unique_name(std::string const &func) { | ||
| auto pos = funcs_.find(func); | ||
| if (pos != end(funcs_)) { | ||
| throw std::logic_error( | ||
| RPCLIB_FMT::format("Function name already bound: '{}'. " | ||
| "Please use unique function names", func)); | ||
| } | ||
| } | ||
| } | ||
| } /* rpc */ |
13 changes: 13 additions & 0 deletionslibraries/rpclib/src/rpc/dispatcher.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.