diff --git a/.ci/build.py b/.ci/build.py index f416a19..6a456fc 100644 --- a/.ci/build.py +++ b/.ci/build.py @@ -47,7 +47,8 @@ def add(self, compiler, compiler_version, cppstd, build_type="Release", setting options = options or {} if "asio" not in options: options.update(self._get_boost_options()) - options["msgpack:header_only"] = True + options["msgpack:cpp_api"] = True + options["msgpack:c_api"] = False options["cppstd"] = cppstd env_vars = {} @@ -75,7 +76,8 @@ def test_linux(): builder = Packager() # Test coroutines - builder.add(compiler=CLANG, compiler_version="10", cppstd="17", settings={"compiler.libcxx": "libc++"}, options={"coroutines": True}) + builder.add(compiler=CLANG, compiler_version="10", cppstd="20", settings={"compiler.libcxx": "libc++"}, options={"boost": "1.74.0", "coroutines": True}) + builder.add(compiler=CLANG, compiler_version="10", cppstd="20", settings={"compiler.libcxx": "libc++"}, options={"asio": "1.17.0", "packio:standalone_asio": True, "coroutines": True}) # Test debug build builder.add(compiler=GCC, compiler_version="10", cppstd="20", build_type="Debug") @@ -105,6 +107,7 @@ def test_linux(): builder.add(compiler=GCC, compiler_version="10", cppstd="20", options={"asio": "1.13.0", "packio:standalone_asio": True}) builder.add(compiler=GCC, compiler_version="10", cppstd="20", options={"asio": "1.14.1", "packio:standalone_asio": True}) builder.add(compiler=GCC, compiler_version="10", cppstd="20", options={"asio": "1.16.1", "packio:standalone_asio": True}) + builder.add(compiler=GCC, compiler_version="10", cppstd="20", options={"asio": "1.17.0", "packio:standalone_asio": True}) # Test logs builder.add(compiler=GCC, compiler_version="10", cppstd="20", options={"loglevel": "trace"}) @@ -125,7 +128,6 @@ def test_windows(): builder.add(compiler=MSVC, compiler_version="16", cppstd="17") builder.add(compiler=MSVC, compiler_version="16", cppstd="20") builder.add(compiler=MSVC, compiler_version="16", cppstd="20", build_type="Debug") - builder.add(compiler=MSVC, compiler_version="16", cppstd="17", options={"coroutines": True}) builder.run() diff --git a/Doxyfile b/Doxyfile index 26e6456..ceb31fd 100644 --- a/Doxyfile +++ b/Doxyfile @@ -680,7 +680,7 @@ SHOW_FILES = YES # Folder Tree View (if specified). # The default value is: YES. -SHOW_NAMESPACES = NO +SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from @@ -762,7 +762,7 @@ WARN_NO_PARAMDOC = NO # a warning is encountered. # The default value is: NO. -WARN_AS_ERROR = NO +WARN_AS_ERROR = YES # The WARN_FORMAT tag determines the format of the warning messages that doxygen # can produce. The string should contain the $file, $line, and $text tags, which @@ -2016,7 +2016,7 @@ ENABLE_PREPROCESSING = YES # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -MACRO_EXPANSION = NO +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then # the macro expansion is limited to the macros specified with the PREDEFINED and diff --git a/README.md b/README.md index 6b26446..df0e2b4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ +## Header-only | JSON-RPC | msgpack-RPC | asio | coroutines -## Header-only | msgpack-RPC | asio | coroutines - -This library requires C++17 and is designed as an extension to `boost.asio`. It will let you build asynchronous servers or client for msgpack-RPC. +This library requires C++17 and is designed as an extension to `boost.asio`. It will let you build asynchronous servers or client for JSON-RPC or msgpack-RPC. The project is hosted on [GitHub](https://github.com/qchateau/packio/) and available on [Conan Center](https://conan.io/center/). Documentation is available on [GitHub Pages](https://qchateau.github.io/packio/). @@ -12,27 +11,36 @@ The project is hosted on [GitHub](https://github.com/qchateau/packio/) and avail #include +using packio::arg; +using packio::nl_json_rpc::completion_handler; +using packio::nl_json_rpc::make_client; +using packio::nl_json_rpc::make_server; +using packio::nl_json_rpc::rpc; + int main(int, char**) { + using namespace packio::arg_literals; + // Declare a server and a client, sharing the same io_context packio::net::io_context io; packio::net::ip::tcp::endpoint bind_ep{ packio::net::ip::make_address("127.0.0.1"), 0}; - auto server = packio::make_server(packio::net::ip::tcp::acceptor{io, bind_ep}); - auto client = packio::make_client(packio::net::ip::tcp::socket{io}); + auto server = make_server(packio::net::ip::tcp::acceptor{io, bind_ep}); + auto client = make_client(packio::net::ip::tcp::socket{io}); - // Declare a synchronous callback - server->dispatcher()->add("add", [](int a, int b) { return a + b; }); - // Declare an asynchronous callback + // Declare a synchronous callback with named arguments + server->dispatcher()->add( + "add", {"a", "b"}, [](int a, int b) { return a + b; }); + // Declare an asynchronous callback with named arguments server->dispatcher()->add_async( - "multiply", [&io](packio::completion_handler complete, int a, int b) { + "multiply", {"a", "b"}, [&io](completion_handler complete, int a, int b) { // Call the completion handler later packio::net::post( io, [a, b, complete = std::move(complete)]() mutable { complete(a * b); }); }); - // Declare a coroutine + // Declare a coroutine with unnamed arguments server->dispatcher()->add_coro( "pow", io, [](int a, int b) -> packio::net::awaitable { co_return std::pow(a, b); @@ -45,40 +53,32 @@ int main(int, char**) // Run the io_context std::thread thread{[&] { io.run(); }}; - // Make an asynchronous call + // Make an asynchronous call with named arguments std::promise add1_result, multiply_result; client->async_call( "add", - std::tuple{42, 24}, - [&](packio::error_code, msgpack::object_handle r) { - add1_result.set_value(r->as()); + std::tuple{arg("a") = 42, arg("b") = 24}, + [&](packio::error_code, const rpc::response_type& r) { + add1_result.set_value(r.result.get()); }); std::cout << "42 + 24 = " << add1_result.get_future().get() << std::endl; - // Use auto result type conversion - std::promise add2_result; - client->async_call( - "add", - std::tuple{11, 32}, - packio::as([&](packio::error_code, std::optional r) { - add2_result.set_value(*r); - })); - std::cout << "11 + 32 = " << add2_result.get_future().get() << std::endl; - - // Use packio::net::use_future - std::future add_future = client->async_call( - "multiply", std::tuple{12, 23}, packio::net::use_future); - std::cout << "12 * 23 = " << add_future.get()->as() << std::endl; + // Use packio::net::use_future with named arguments and literals + auto add_future = client->async_call( + "multiply", + std::tuple{"a"_arg = 12, "b"_arg = 23}, + packio::net::use_future); + std::cout << "12 * 23 = " << add_future.get().result.get() << std::endl; // Spawn the coroutine and wait for its completion std::promise pow_result; packio::net::co_spawn( io, [&]() -> packio::net::awaitable { - // Call using an awaitable - msgpack::object_handle res = co_await client->async_call( + // Call using an awaitable and positional arguments + auto res = co_await client->async_call( "pow", std::tuple{2, 8}, packio::net::use_awaitable); - pow_result.set_value(res->as()); + pow_result.set_value(res.result.get()); }, packio::net::detached); std::cout << "2 ** 8 = " << pow_result.get_future().get() << std::endl; @@ -94,8 +94,12 @@ int main(int, char**) - C++17 or C++20 - msgpack >= 3.2.1 +- nlohmann_json >= 3.9.1 - boost.asio >= 1.70.0 or asio >= 1.13.0 +Older version of `msgpack` and `nlohmann_json` are probably compatible +but they are not tested on the CI. + ### Standalone or boost asio By default, `packio` uses `boost.asio`. It is also compatible with standalone `asio`. To use the standalone version, the preprocessor macro `PACKIO_STANDALONE_ASIO=1` must be defined. @@ -126,12 +130,13 @@ conan install packio/x.x.x ## Coroutines `packio` is compatible with C++20 coroutines: + - calls can use the `packio::asio::use_awaitable` completion token - coroutines can be registered in the server Coroutines are tested for the following compilers: -- clang-9 with libc++ -- Visual Studio 2019 Version 16 + +- clang-10 with libc++ ## Bonus @@ -142,6 +147,9 @@ Let's compute fibonacci's numbers recursively using `packio` and coroutines on a #include +using packio::msgpack_rpc::make_client; +using packio::msgpack_rpc::make_server; + int main(int argc, char** argv) { if (argc < 2) { @@ -153,8 +161,8 @@ int main(int argc, char** argv) packio::net::io_context io; packio::net::ip::tcp::endpoint bind_ep{ packio::net::ip::make_address("127.0.0.1"), 0}; - auto server = packio::make_server(packio::net::ip::tcp::acceptor{io, bind_ep}); - auto client = packio::make_client(packio::net::use_awaitable_t<>::as_default_on( + auto server = make_server(packio::net::ip::tcp::acceptor{io, bind_ep}); + auto client = make_client(packio::net::use_awaitable_t<>::as_default_on( packio::net::ip::tcp::socket{io})); server->dispatcher()->add_coro( @@ -166,7 +174,7 @@ int main(int argc, char** argv) auto r1 = co_await client->async_call("fibonacci", std::tuple{n - 1}); auto r2 = co_await client->async_call("fibonacci", std::tuple{n - 2}); - co_return r1->as() + r2->as(); + co_return r1.result.as() + r2.result.as(); }); client->socket().connect(server->acceptor().local_endpoint()); @@ -175,12 +183,10 @@ int main(int argc, char** argv) int result = 0; client->async_call( - "fibonacci", - std::tuple{n}, - packio::as([&](packio::error_code, std::optional r) { - result = *r; + "fibonacci", std::tuple{n}, [&](packio::error_code, auto r) { + result = r.result.template as(); io.stop(); - })); + }); io.run(); diff --git a/appveyor.yml b/appveyor.yml index 8031720..c3dd4f7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,39 +5,55 @@ environment: CONAN_REQUEST_TIMEOUT: 300 matrix: - # Linux job - - job_name: Linux build - job_group: Build - appveyor_build_worker_image: Ubuntu2004 + # Windows job + - job_name: Windows build + appveyor_build_worker_image: Visual Studio 2019 # Mac job - job_name: MacOS build - job_group: Build appveyor_build_worker_image: macos - # Windows job - - job_name: Windows build - job_group: Build - appveyor_build_worker_image: Visual Studio 2019 + # Linux jobs + - job_name: Linux build 0 + job_group: Linux build + appveyor_build_worker_image: Ubuntu2004 -for: + - job_name: Linux build 1 + job_group: Linux build + appveyor_build_worker_image: Ubuntu2004 - - - matrix: +for: + - matrix: only: - - job_name: Linux build + - job_group: Linux build + + environment: + CONAN_TOTAL_PAGES: 2 install: - source ~/venv3.7/bin/activate - python -m pip install -U conan conan_package_tools - sudo apt-get update - sudo apt-get install -y - clang-6.0 clang-7 clang-8 clang-9 clang-10 - g++-7 g++-8 g++-9 g++-10 - libc++-10-dev libc++abi-10-dev + clang-6.0 clang-7 clang-8 clang-9 clang-10 + g++-7 g++-8 g++-9 g++-10 + libc++-10-dev libc++abi-10-dev + + - matrix: + only: + - job_name: Linux build 0 + + environment: + CONAN_CURRENT_PAGE: 1 + + - matrix: + only: + - job_name: Linux build 1 + + environment: + CONAN_CURRENT_PAGE: 2 - - - matrix: + - matrix: only: - job_name: MacOS build @@ -45,8 +61,7 @@ for: - source ~/venv3.7/bin/activate - python -m pip install -U conan conan_package_tools - - - matrix: + - matrix: only: - job_name: Windows build diff --git a/conanfile.py b/conanfile.py index 3cc153c..e21a508 100644 --- a/conanfile.py +++ b/conanfile.py @@ -7,15 +7,36 @@ class PackioConan(ConanFile): license = "MPL-2.0" author = "Quentin Chateau " url = "https://github.com/qchateau/packio" - description = "C++ implementation of msgpack-RPC" - topics = ("rpc", "msgpack", "cpp17", "cpp20", "coroutine") + description = "Asynchrnous msgpack-RPC and JSON-RPC server and client" + topics = ( + "rpc", + "async", + "msgpack", + "json", + "msgpack-rpc", + "json-rpc", + "cpp17", + "cpp20", + "coroutine", + ) exports_sources = "include/*" no_copy_source = True - options = {"standalone_asio": [True, False]} - default_options = {"standalone_asio": False} + options = { + "standalone_asio": [True, False], + "msgpack": [True, False], + "nlohmann_json": [True, False], + } + default_options = { + "standalone_asio": False, + "msgpack": True, + "nlohmann_json": True, + } def requirements(self): - self.requires("msgpack/3.2.1") + if self.options.msgpack: + self.requires("msgpack/3.2.1") + if self.options.nlohmann_json: + self.requires("nlohmann_json/3.9.1") if self.options.standalone_asio: self.requires("asio/[>=1.13.0]") diff --git a/docs/annotated.html b/docs/annotated.html index 66e6ce1..c9afe74 100644 --- a/docs/annotated.html +++ b/docs/annotated.html @@ -68,22 +68,32 @@
Here are the classes, structs, unions and interfaces with brief descriptions:
-
[detail level 123]
+
[detail level 1234]
- - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +
 Npackio
 Ntraits
 CAsCallHandlerAsCallHandler
 CAsVoidCallHandlerAsVoidCallHandler
 CAsyncProcedureAsyncProcedure trait
 CCallHandlerCallHandler trait
 CCoroProcedureCoroProcedure trait
 CNotifyHandlerNotifyHandler trait
 CServeHandlerServeHandler trait
 CSyncProcedureSyncProcedure trait
 CclientThe client class
 Ccompletion_handlerThe completion_handler class
 CdispatcherThe dispatcher class, used to store and dispatch procedures
 CserverThe server class
 Cserver_sessionThe server_session class, created by the server
 Nmsgpack_rpc
 Ninternal
 Cincremental_parserThe incremental parser for msgpack-RPC objects
 CrequestThe object representing a client request
 CresponseThe object representing the response to a call
 CrpcThe msgpack RPC protocol implementation
 Nnl_json_rpc
 Ninternal
 Cincremental_parserThe incremental parser for JSON-RPC objects
 CrequestThe object representing a client request
 CresponseThe object representing the response to a call
 CrpcThe JSON-RPC protocol implementation
 Ntraits
 CAsyncProcedureAsyncProcedure trait
 CCallHandlerCallHandler trait
 CCoroProcedureCoroProcedure trait
 CNotifyHandlerNotifyHandler trait
 CServeHandlerServeHandler trait
 CSyncProcedureSyncProcedure trait
 CclientThe client class
 Ccompletion_handlerThe completion_handler class
 CdispatcherThe dispatcher class, used to store and dispatch procedures
 CserverThe server class
 Cserver_sessionThe server_session class, created by the server
diff --git a/docs/arg_8h.html b/docs/arg_8h.html new file mode 100644 index 0000000..1623e93 --- /dev/null +++ b/docs/arg_8h.html @@ -0,0 +1,92 @@ + + + + + + + + + packio: packio/arg.h File Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
arg.h File Reference
+
+
+
#include <string>
+#include <string_view>
+
+

Go to the source code of this file.

+ + + + +

+Namespaces

 packio
 
+

Detailed Description

+

Class arg

+
+ + + + \ No newline at end of file diff --git a/docs/arg_8h_source.html b/docs/arg_8h_source.html new file mode 100644 index 0000000..6ea332c --- /dev/null +++ b/docs/arg_8h_source.html @@ -0,0 +1,139 @@ + + + + + + + + + packio: packio/arg.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
arg.h
+
+
+Go to the documentation of this file.
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_ARG_H
+
6 #define PACKIO_ARG_H
+
7 
+
10 
+
11 #include <string>
+
12 #include <string_view>
+
13 
+
14 namespace packio {
+
15 
+
16 class arg {
+
17 public:
+
18  template <typename T>
+
19  struct with_value {
+
20  const std::string name;
+
21  T value;
+
22  };
+
23 
+
24  explicit constexpr arg(std::string_view name) : name_{name} {}
+
25 
+
26  template <typename T>
+
27  constexpr with_value<T> operator=(T&& value)
+
28  {
+
29  return {std::string{name_}, std::forward<T>(value)};
+
30  }
+
31 
+
32 private:
+
33  std::string_view name_;
+
34 };
+
35 
+
36 template <typename T>
+
37 struct is_arg_impl : std::false_type {
+
38 };
+
39 
+
40 template <typename T>
+
41 struct is_arg_impl<arg::with_value<T>> : std::true_type {
+
42 };
+
43 
+
44 template <typename T>
+
45 struct is_arg : is_arg_impl<std::decay_t<T>> {
+
46 };
+
47 
+
48 template <typename T>
+
49 constexpr bool is_arg_v = is_arg<T>::value;
+
50 
+
51 namespace arg_literals {
+
52 
+
53 constexpr arg operator"" _arg(const char* str, std::size_t)
+
54 {
+
55  return arg{str};
+
56 }
+
57 
+
58 } // arg_literals
+
59 
+
60 } // packio
+
61 
+
62 #endif // PACKIO_INTERNAL_ARG_H
+
+
Definition: arg.h:14
+ + + + \ No newline at end of file diff --git a/docs/classes.html b/docs/classes.html index 27406ac..0ae2702 100644 --- a/docs/classes.html +++ b/docs/classes.html @@ -67,41 +67,52 @@
Class Index
-
a | c | d | n | s
+
a | c | d | i | n | r | s
- + + + + + + - - + + + + + - + + - - - - - - - - + + + - - - + - + + + + + + + - - -
  a  
  c  
+
completion_handler (packio)   incremental_parser (packio::nl_json_rpc::internal)   request (packio::nl_json_rpc::internal)   server (packio)   
CoroProcedure (packio::traits)   
  n  
CoroProcedure (packio::traits)   
  s  
+
response (packio::nl_json_rpc::internal)   server_session (packio)   
AsyncProcedure (packio::traits)   
  d  
response (packio::msgpack_rpc::internal)    SyncProcedure (packio::traits)   
  d  
+
  c  
NotifyHandler (packio::traits)   rpc (packio::msgpack_rpc)   
AsCallHandler (packio::traits)   CallHandler (packio::traits)   ServeHandler (packio::traits)   
AsVoidCallHandler (packio::traits)   client (packio)   dispatcher (packio)   server (packio)   
dispatcher (packio)   
  r  
+
rpc (packio::nl_json_rpc)   
AsyncProcedure (packio::traits)   completion_handler (packio)   
  n  
+
CallHandler (packio::traits)   
  i  
server_session (packio)   
  s  
+
client (packio)   request (packio::msgpack_rpc::internal)   
incremental_parser (packio::msgpack_rpc::internal)   ServeHandler (packio::traits)   
NotifyHandler (packio::traits)   
-
a | c | d | n | s
+
a | c | d | i | n | r | s
diff --git a/docs/classpackio_1_1client-members.html b/docs/classpackio_1_1client-members.html index 9db4686..7e93563 100644 --- a/docs/classpackio_1_1client-members.html +++ b/docs/classpackio_1_1client-members.html @@ -68,28 +68,31 @@
-
packio::client< Socket, Map > Member List
+
packio::client< Rpc, Socket, Map > Member List
-

This is the complete list of members for packio::client< Socket, Map >, including all inherited members.

+

This is the complete list of members for packio::client< Rpc, Socket, Map >, including all inherited members.

- - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + +
async_call(std::string_view name, const std::tuple< Args... > &args, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)packio::client< Socket, Map >inline
async_call(std::string_view name, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)packio::client< Socket, Map >inline
async_notify(std::string_view name, const std::tuple< Args... > &args, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))packio::client< Socket, Map >inline
async_notify(std::string_view name, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))packio::client< Socket, Map >inline
cancel(id_type id)packio::client< Socket, Map >inline
cancel()packio::client< Socket, Map >inline
client(socket_type socket)packio::client< Socket, Map >inlineexplicit
executor_type typedefpackio::client< Socket, Map >
get_buffer_reserve_size() const noexceptpackio::client< Socket, Map >inline
get_executor()packio::client< Socket, Map >inline
kDefaultBufferReserveSizepackio::client< Socket, Map >static
protocol_type typedefpackio::client< Socket, Map >
set_buffer_reserve_size(std::size_t size) noexceptpackio::client< Socket, Map >inline
socket() noexceptpackio::client< Socket, Map >inline
socket() const noexceptpackio::client< Socket, Map >inline
socket_type typedefpackio::client< Socket, Map >
async_call(std::string_view name, ArgsTuple &&args, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)packio::client< Rpc, Socket, Map >inline
async_call(std::string_view name, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)packio::client< Rpc, Socket, Map >inline
async_notify(std::string_view name, ArgsTuple &&args, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())packio::client< Rpc, Socket, Map >inline
async_notify(std::string_view name, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())packio::client< Rpc, Socket, Map >inline
cancel(id_type id)packio::client< Rpc, Socket, Map >inline
cancel()packio::client< Rpc, Socket, Map >inline
client(socket_type socket)packio::client< Rpc, Socket, Map >inlineexplicit
executor_type typedefpackio::client< Rpc, Socket, Map >
get_buffer_reserve_size() const noexceptpackio::client< Rpc, Socket, Map >inline
get_executor()packio::client< Rpc, Socket, Map >inline
id_type typedefpackio::client< Rpc, Socket, Map >
kDefaultBufferReserveSizepackio::client< Rpc, Socket, Map >static
protocol_type typedefpackio::client< Rpc, Socket, Map >
response_type typedefpackio::client< Rpc, Socket, Map >
rpc_type typedefpackio::client< Rpc, Socket, Map >
set_buffer_reserve_size(std::size_t size) noexceptpackio::client< Rpc, Socket, Map >inline
socket() noexceptpackio::client< Rpc, Socket, Map >inline
socket() const noexceptpackio::client< Rpc, Socket, Map >inline
socket_type typedefpackio::client< Rpc, Socket, Map >
diff --git a/docs/classpackio_1_1client.html b/docs/classpackio_1_1client.html index 947ac59..0523de5 100644 --- a/docs/classpackio_1_1client.html +++ b/docs/classpackio_1_1client.html @@ -7,7 +7,7 @@ - packio: packio::client< Socket, Map > Class Template Reference + packio: packio::client< Rpc, Socket, Map > Class Template Reference @@ -73,7 +73,7 @@ Static Public Attributes | List of all members
-
packio::client< Socket, Map > Class Template Reference
+
packio::client< Rpc, Socket, Map > Class Template Reference
@@ -84,104 +84,117 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + +

Public Types

-using socket_type = Socket
 The socket type.
 
-using protocol_type = typename socket_type::protocol_type
 The protocol type.
 
-using executor_type = typename socket_type::executor_type
 The executor type.
 
+using rpc_type = Rpc
 The RPC protocol type.
 
+using id_type = typename rpc_type::id_type
 The call ID type.
 
+using response_type = typename rpc_type::response_type
 The response of a RPC call.
 
+using socket_type = Socket
 The socket type.
 
+using protocol_type = typename socket_type::protocol_type
 The protocol type.
 
+using executor_type = typename socket_type::executor_type
 The executor type.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

 client (socket_type socket)
 The constructor. More...
 
-socket_typesocket () noexcept
 Get the underlying socket.
 
-const socket_typesocket () const noexcept
 Get the underlying socket, const.
 
-void set_buffer_reserve_size (std::size_t size) noexcept
 Set the size reserved by the reception buffer.
 
-std::size_t get_buffer_reserve_size () const noexcept
 Get the size reserved by the reception buffer.
 
-executor_type get_executor ()
 Get the executor associated with the object.
 
void cancel (id_type id)
 Cancel a pending call. More...
 
void cancel ()
 Cancel all pending calls. More...
 
template<typename Buffer = msgpack::sbuffer, NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename... Args>
auto async_notify (std::string_view name, const std::tuple< Args... > &args, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 Send a notify request to the server with argument. More...
 
-template<typename Buffer = msgpack::sbuffer, NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename = std::enable_if_t<!internal::is_tuple_v<NotifyHandler>>>
auto async_notify (std::string_view name, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 Send a notify request to the server with no argument This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename Buffer = msgpack::sbuffer, CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename... Args>
auto async_call (std::string_view name, const std::tuple< Args... > &args, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)
 Call a remote procedure. More...
 
-template<typename Buffer = msgpack::sbuffer, CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename = std::enable_if_t<!internal::is_tuple_v<CallHandler>>>
auto async_call (std::string_view name, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)
 Call a remote procedure This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
 client (socket_type socket)
 The constructor. More...
 
+socket_typesocket () noexcept
 Get the underlying socket.
 
+const socket_typesocket () const noexcept
 Get the underlying socket, const.
 
+void set_buffer_reserve_size (std::size_t size) noexcept
 Set the size reserved by the reception buffer.
 
+std::size_t get_buffer_reserve_size () const noexcept
 Get the size reserved by the reception buffer.
 
+executor_type get_executor ()
 Get the executor associated with the object.
 
void cancel (id_type id)
 Cancel a pending call. More...
 
void cancel ()
 Cancel all pending calls. More...
 
template<typename NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename ArgsTuple , typename = std::enable_if_t<internal::is_tuple_v<ArgsTuple>>>
auto async_notify (std::string_view name, ArgsTuple &&args, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())
 Send a notify request to the server with argument. More...
 
+template<typename NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename = std::enable_if_t<!internal::is_tuple_v<NotifyHandler>>>
auto async_notify (std::string_view name, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename ArgsTuple , typename = std::enable_if_t<internal::is_tuple_v<ArgsTuple>>>
auto async_call (std::string_view name, ArgsTuple &&args, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)
 Call a remote procedure. More...
 
+template<typename CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename = std::enable_if_t<!internal::is_tuple_v<CallHandler>>>
auto async_call (std::string_view name, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
- - - + + +

Static Public Attributes

-static constexpr size_t kDefaultBufferReserveSize = 4096
 The default size reserved by the reception buffer.
 
+static constexpr size_t kDefaultBufferReserveSize = 4096
 The default size reserved by the reception buffer.
 

Detailed Description

-

template<typename Socket, template< class... > class Map = std::map>
-class packio::client< Socket, Map >

+

template<typename Rpc, typename Socket, template< class... > class Map = default_map>
+class packio::client< Rpc, Socket, Map >

The client class.

Template Parameters
+
RpcRPC protocol implementation
SocketSocket type to use for this client
MapContainer used to associate call IDs and handlers

Constructor & Destructor Documentation

- -

◆ client()

+ +

◆ client()

-template<typename Socket , template< class... > class Map = std::map>
+template<typename Rpc , typename Socket , template< class... > class Map = default_map>
- + - + @@ -204,21 +217,21 @@

Member Function Documentation

- -

◆ async_call()

+ +

◆ async_call()

-template<typename Socket , template< class... > class Map = std::map>
+template<typename Rpc , typename Socket , template< class... > class Map = default_map>
-template<typename Buffer = msgpack::sbuffer, CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename... Args>
+template<typename CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename ArgsTuple , typename = std::enable_if_t<internal::is_tuple_v<ArgsTuple>>>
packio::client< Socket, Map >::client packio::client< Rpc, Socket, Map >::client (socket_type socket_type  socket)
- + @@ -226,19 +239,19 @@

- + - - + + - + @@ -255,17 +268,6 @@

Call a remote procedure.

-
Template Parameters
-

auto packio::client< Socket, Map >::async_call auto packio::client< Rpc, Socket, Map >::async_call ( std::string_view  name, const std::tuple< Args... > & ArgsTuple &&  args,
CallHandler &&handler  PACKIO_DEFAULT_COMPLETION_TOKENexecutor_type, CallHandler && handler = typename net::default_completion_token< executor_type >::type(),
std::optional< std::reference_wrapper< id_type >> std::optional< std::reference_wrapper< id_type >>  call_id = std::nullopt 
- -
BufferBuffer used to serialize the arguments. Recommended:
    -
  • msgpack::sbuffer is an owning buffer
    -
  • -
  • msgpack::vrefbuffer is a non-owning buffer
  • -
-
- -
Parameters
@@ -278,21 +280,21 @@

-

◆ async_notify()

+ +

◆ async_notify()

-template<typename Socket , template< class... > class Map = std::map>
+template<typename Rpc , typename Socket , template< class... > class Map = default_map>
-template<typename Buffer = msgpack::sbuffer, NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename... Args>
+template<typename NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE, typename ArgsTuple , typename = std::enable_if_t<internal::is_tuple_v<ArgsTuple>>>

nameRemote procedure name to call
- + @@ -300,14 +302,14 @@

- + - - + + @@ -323,18 +325,7 @@

Send a notify request to the server with argument.

-

A notify request will call the remote procedure but does not expect a response

Template Parameters
-

auto packio::client< Socket, Map >::async_notify auto packio::client< Rpc, Socket, Map >::async_notify ( std::string_view  name, const std::tuple< Args... > & ArgsTuple &&  args,
NotifyHandler &&handler  PACKIO_DEFAULT_COMPLETION_TOKENexecutor_type NotifyHandler && handler = typename net::default_completion_token< executor_type >::type() 
- -
BufferBuffer used to serialize the arguments. Recommended:
    -
  • msgpack::sbuffer is an owning buffer
    -
  • -
  • msgpack::vrefbuffer is a non-owning buffer
  • -
-
- - -
Parameters
+

A notify request will call the remote procedure but does not expect a response

Parameters
@@ -345,19 +336,19 @@

-

◆ cancel() [1/2]

+ +

◆ cancel() [1/2]

-template<typename Socket , template< class... > class Map = std::map>
+template<typename Rpc , typename Socket , template< class... > class Map = default_map>

nameRemote procedure name to call
argsTuple of arguments to pass to the remote procedure
- + @@ -371,25 +362,25 @@

Cancel all pending calls.

-

The associated handlers will be called with error::cancelled

+

The associated handlers will be called with net::error::operation_aborted

- -

◆ cancel() [2/2]

+ +

◆ cancel() [2/2]

-template<typename Socket , template< class... > class Map = std::map>
+template<typename Rpc , typename Socket , template< class... > class Map = default_map>

void packio::client< Socket, Map >::cancel void packio::client< Rpc, Socket, Map >::cancel ( )
- + - + @@ -402,7 +393,7 @@

Cancel a pending call.

-

The associated handler will be called with error::cancelled

Parameters
+

The associated handler will be called with net::error::operation_aborted

Parameters

void packio::client< Socket, Map >::cancel void packio::client< Rpc, Socket, Map >::cancel (id_type id_type  id)
idThe call ID of the call to cancel
diff --git a/docs/classpackio_1_1completion__handler-members.html b/docs/classpackio_1_1completion__handler-members.html index 636b88b..d7312ee 100644 --- a/docs/classpackio_1_1completion__handler-members.html +++ b/docs/classpackio_1_1completion__handler-members.html @@ -68,21 +68,21 @@
-
packio::completion_handler Member List
+
packio::completion_handler< Rpc > Member List
-

This is the complete list of members for packio::completion_handler, including all inherited members.

+

This is the complete list of members for packio::completion_handler< Rpc >, including all inherited members.

- - - - - - - - - + + + + + + + + +
completion_handler(completion_handler &&other)packio::completion_handlerinline
operator()(T &&return_value)packio::completion_handlerinline
operator()()packio::completion_handlerinline
operator=(completion_handler &&other)packio::completion_handlerinline
set_error(T &&error_value)packio::completion_handlerinline
set_error()packio::completion_handlerinline
set_value(T &&return_value)packio::completion_handlerinline
set_value()packio::completion_handlerinline
~completion_handler()packio::completion_handlerinline
completion_handler(completion_handler &&other)packio::completion_handler< Rpc >inline
operator()(T &&return_value)packio::completion_handler< Rpc >inline
operator()()packio::completion_handler< Rpc >inline
operator=(completion_handler &&other)packio::completion_handler< Rpc >inline
set_error(T &&error_value)packio::completion_handler< Rpc >inline
set_error()packio::completion_handler< Rpc >inline
set_value(T &&return_value)packio::completion_handler< Rpc >inline
set_value()packio::completion_handler< Rpc >inline
~completion_handler()packio::completion_handler< Rpc >inline
diff --git a/docs/classpackio_1_1completion__handler.html b/docs/classpackio_1_1completion__handler.html index 4046c00..b356b0e 100644 --- a/docs/classpackio_1_1completion__handler.html +++ b/docs/classpackio_1_1completion__handler.html @@ -7,7 +7,7 @@ - packio: packio::completion_handler Class Reference + packio: packio::completion_handler< Rpc > Class Template Reference @@ -71,7 +71,7 @@ Public Member Functions | List of all members
-
packio::completion_handler Class Reference
+
packio::completion_handler< Rpc > Class Template Reference
@@ -82,61 +82,72 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + +

Public Member Functions

~completion_handler ()
 The destructor will notify an error if the completion_handler has not been used.
 
completion_handler (completion_handler &&other)
 Move constructor.
 
-completion_handleroperator= (completion_handler &&other)
 Move assignment operator.
 
template<typename T >
void set_value (T &&return_value)
 Notify successful completion of the procedure and set the return value. More...
 
-void set_value ()
 Notify successful completion of the procedure with no return value This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
void set_error (T &&error_value)
 Notify erroneous completion of the procedure with an associated error. More...
 
-void set_error ()
 Notify erroneous completion of the procedure without an error value This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
+
~completion_handler ()
 The destructor will notify an error if the completion_handler has not been used.
 
completion_handler (completion_handler &&other)
 Move constructor.
 
+completion_handleroperator= (completion_handler &&other)
 Move assignment operator.
 
template<typename T >
void set_value (T &&return_value)
 Notify successful completion of the procedure and set the return value. More...
 
+void set_value ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
void set_error (T &&error_value)
 Notify erroneous completion of the procedure with an associated error. More...
 
+void set_error ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
void operator() (T &&return_value)
 Same as set_value.
 
-void operator() ()
 Same as set_value.
 
void operator() (T &&return_value)
 Same as set_value.
 
+void operator() ()
 Same as set_value.
 

Detailed Description

-

The completion_handler class.

-

First argument of AsyncProcedure, the completion_handler is a callable used to notify the completion of an asynchronous procedure. You must only call set_value or set_error once.

+

template<typename Rpc>
+class packio::completion_handler< Rpc >

+ +

The completion_handler class.

+
Template Parameters
+ + +
RpcRPC protocol implementation
+
+
+

First argument of AsyncProcedure, the completion_handler is a callable used to notify the completion of an asynchronous procedure. You must only call set_value or set_error once.

Member Function Documentation

- -

◆ set_error()

+ +

◆ set_error()

+template<typename Rpc >
+
template<typename T >
- + @@ -160,19 +171,21 @@

-

◆ set_value()

+ +

◆ set_value()

+template<typename Rpc >
+
template<typename T >

void packio::completion_handler::set_error void packio::completion_handler< Rpc >::set_error ( T &&  error_value)
- + diff --git a/docs/classpackio_1_1dispatcher-members.html b/docs/classpackio_1_1dispatcher-members.html index 3d7a3c1..d54664b 100644 --- a/docs/classpackio_1_1dispatcher-members.html +++ b/docs/classpackio_1_1dispatcher-members.html @@ -68,23 +68,29 @@
-
packio::dispatcher< Map, Lockable > Member List
+
packio::dispatcher< Rpc, Map, Lockable > Member List
-

This is the complete list of members for packio::dispatcher< Map, Lockable >, including all inherited members.

+

This is the complete list of members for packio::dispatcher< Rpc, Map, Lockable >, including all inherited members.

void packio::completion_handler::set_value void packio::completion_handler< Rpc >::set_value ( T &&  return_value)
- - - - - - - - - - - + + + + + + + + + + + + + + + + +
add(std::string_view name, SyncProcedure &&fct)packio::dispatcher< Map, Lockable >inline
add_async(std::string_view name, AsyncProcedure &&fct)packio::dispatcher< Map, Lockable >inline
add_coro(std::string_view name, const Executor &executor, CoroProcedure &&coro)packio::dispatcher< Map, Lockable >inline
add_coro(std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)packio::dispatcher< Map, Lockable >inline
clear()packio::dispatcher< Map, Lockable >inline
function_ptr_type typedefpackio::dispatcher< Map, Lockable >
function_type typedefpackio::dispatcher< Map, Lockable >
has(const std::string &name) constpackio::dispatcher< Map, Lockable >inline
known() constpackio::dispatcher< Map, Lockable >inline
mutex_type typedefpackio::dispatcher< Map, Lockable >
remove(const std::string &name)packio::dispatcher< Map, Lockable >inline
add(std::string_view name, const std::array< std::string, N > &arguments_names, SyncProcedure &&fct)packio::dispatcher< Rpc, Map, Lockable >inline
add(std::string_view name, SyncProcedure &&fct)packio::dispatcher< Rpc, Map, Lockable >inline
add_async(std::string_view name, const std::array< std::string, N > &arguments_names, AsyncProcedure &&fct)packio::dispatcher< Rpc, Map, Lockable >inline
add_async(std::string_view name, AsyncProcedure &&fct)packio::dispatcher< Rpc, Map, Lockable >inline
add_coro(std::string_view name, const Executor &executor, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)packio::dispatcher< Rpc, Map, Lockable >inline
add_coro(std::string_view name, const Executor &executor, CoroProcedure &&coro)packio::dispatcher< Rpc, Map, Lockable >inline
add_coro(std::string_view name, ExecutionContext &ctx, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)packio::dispatcher< Rpc, Map, Lockable >inline
add_coro(std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)packio::dispatcher< Rpc, Map, Lockable >inline
args_type typedefpackio::dispatcher< Rpc, Map, Lockable >
clear()packio::dispatcher< Rpc, Map, Lockable >inline
function_ptr_type typedefpackio::dispatcher< Rpc, Map, Lockable >
function_type typedefpackio::dispatcher< Rpc, Map, Lockable >
has(const std::string &name) constpackio::dispatcher< Rpc, Map, Lockable >inline
known() constpackio::dispatcher< Rpc, Map, Lockable >inline
mutex_type typedefpackio::dispatcher< Rpc, Map, Lockable >
remove(const std::string &name)packio::dispatcher< Rpc, Map, Lockable >inline
rpc_type typedefpackio::dispatcher< Rpc, Map, Lockable >
diff --git a/docs/classpackio_1_1dispatcher.html b/docs/classpackio_1_1dispatcher.html index 20caf83..01bee0f 100644 --- a/docs/classpackio_1_1dispatcher.html +++ b/docs/classpackio_1_1dispatcher.html @@ -7,7 +7,7 @@ - packio: packio::dispatcher< Map, Lockable > Class Template Reference + packio: packio::dispatcher< Rpc, Map, Lockable > Class Template Reference @@ -72,7 +72,7 @@ Public Member Functions | List of all members
-
packio::dispatcher< Map, Lockable > Class Template Reference
+
packio::dispatcher< Rpc, Map, Lockable > Class Template Reference
@@ -83,83 +83,118 @@ - - - - - - - - - + + + + + + + + + + + + + + +

Public Types

-using mutex_type = Lockable
 The mutex type used to protect the procedure map.
 
-using function_type = internal::unique_function< void(completion_handler, const msgpack::object &)>
 The type of function stored in the dispatcher.
 
-using function_ptr_type = std::shared_ptr< function_type >
 A shared pointer to function_type.
 
+using rpc_type = Rpc
 The RPC protocol type.
 
+using mutex_type = Lockable
 The mutex type used to protect the procedure map.
 
+using args_type = decltype(typename rpc_type::request_type{}.args)
 The type of the arguments used by the RPC protocol.
 
+using function_type = internal::movable_function< void(completion_handler< rpc_type >, args_type &&args)>
 The type of function stored in the dispatcher.
 
+using function_ptr_type = std::shared_ptr< function_type >
 A shared pointer to function_type.
 
- - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + +

Public Member Functions

template<typename SyncProcedure >
bool add (std::string_view name, SyncProcedure &&fct)
 Add a synchronous procedure to the dispatcher. More...
 
template<typename AsyncProcedure >
bool add_async (std::string_view name, AsyncProcedure &&fct)
 Add an asynchronous procedure to the dispatcher. More...
 
template<typename Executor , typename CoroProcedure >
bool add_coro (std::string_view name, const Executor &executor, CoroProcedure &&coro)
 Add a coroutine to the dispatcher. More...
 
+
template<typename SyncProcedure , std::size_t N = internal::func_traits<SyncProcedure>::args_count>
bool add (std::string_view name, const std::array< std::string, N > &arguments_names, SyncProcedure &&fct)
 Add a synchronous procedure to the dispatcher. More...
 
+template<typename SyncProcedure >
bool add (std::string_view name, SyncProcedure &&fct)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename AsyncProcedure , std::size_t N = internal::func_traits<AsyncProcedure>::args_count - 1>
bool add_async (std::string_view name, const std::array< std::string, N > &arguments_names, AsyncProcedure &&fct)
 Add an asynchronous procedure to the dispatcher. More...
 
+template<typename AsyncProcedure >
bool add_async (std::string_view name, AsyncProcedure &&fct)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename Executor , typename CoroProcedure , std::size_t N = internal::func_traits<CoroProcedure>::args_count>
bool add_coro (std::string_view name, const Executor &executor, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)
 Add a coroutine to the dispatcher. More...
 
+template<typename Executor , typename CoroProcedure >
bool add_coro (std::string_view name, const Executor &executor, CoroProcedure &&coro)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
+template<typename ExecutionContext , typename CoroProcedure , std::size_t N = internal::func_traits<CoroProcedure>::args_count>
bool add_coro (std::string_view name, ExecutionContext &ctx, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename ExecutionContext , typename CoroProcedure >
bool add_coro (std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)
 Add a coroutine to the dispatcher This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool remove (const std::string &name)
 Remove a procedure from the dispatcher. More...
 
bool has (const std::string &name) const
 Check if a procedure is registered. More...
 
size_t clear ()
 Remove all procedures. More...
 
std::vector< std::string > known () const
 Get the name of all known procedures. More...
 
bool add_coro (std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool remove (const std::string &name)
 Remove a procedure from the dispatcher. More...
 
bool has (const std::string &name) const
 Check if a procedure is registered. More...
 
size_t clear ()
 Remove all procedures. More...
 
std::vector< std::string > known () const
 Get the name of all known procedures. More...
 

Detailed Description

-

template<template< class... > class Map = std::unordered_map, typename Lockable = std::mutex>
-class packio::dispatcher< Map, Lockable >

+

template<typename Rpc, template< class... > class Map = default_map, typename Lockable = default_mutex>
+class packio::dispatcher< Rpc, Map, Lockable >

The dispatcher class, used to store and dispatch procedures.

Template Parameters
+
RpcRPC protocol implementation
MapThe container used to associate procedures to their name
LockableThe lockable used to protect accesses to the procedure map

Member Function Documentation

- -

◆ add()

+ +

◆ add()

-template<template< class... > class Map = std::unordered_map, typename Lockable = std::mutex>
+template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
-template<typename SyncProcedure >
+template<typename SyncProcedure , std::size_t N = internal::func_traits<SyncProcedure>::args_count>
- + + + + + + + @@ -183,6 +218,7 @@

Parameters

bool packio::dispatcher< Map, Lockable >::add bool packio::dispatcher< Rpc, Map, Lockable >::add ( std::string_view  name,
const std::array< std::string, N > & arguments_names,
+
nameThe name of the procedure
arguments_namesThe name of the arguments (optional)
fctThe procedure itself
@@ -190,25 +226,31 @@

-

◆ add_async()

+ +

◆ add_async()

-template<template< class... > class Map = std::unordered_map, typename Lockable = std::mutex>
+template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
-template<typename AsyncProcedure >
+template<typename AsyncProcedure , std::size_t N = internal::func_traits<AsyncProcedure>::args_count - 1>
- + + + + + + + @@ -232,6 +274,7 @@

Parameters

bool packio::dispatcher< Map, Lockable >::add_async bool packio::dispatcher< Rpc, Map, Lockable >::add_async ( std::string_view  name,
const std::array< std::string, N > & arguments_names,
+
nameThe name of the procedure
arguments_namesThe name of the arguments (optional)
fctThe procedure itself
@@ -239,21 +282,21 @@

-

◆ add_coro()

+ +

◆ add_coro()

-template<template< class... > class Map = std::unordered_map, typename Lockable = std::mutex>
+template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
-template<typename Executor , typename CoroProcedure >
+template<typename Executor , typename CoroProcedure , std::size_t N = internal::func_traits<CoroProcedure>::args_count>
- + @@ -264,6 +307,12 @@

const Executor & 

+ + + + + + @@ -288,6 +337,7 @@

+
bool packio::dispatcher< Map, Lockable >::add_coro bool packio::dispatcher< Rpc, Map, Lockable >::add_coro ( std::string_view  name, executor,
const std::array< std::string, N > & arguments_names,
nameThe name of the procedure
executorThe executor used to execute the coroutine
arguments_namesThe name of the arguments (optional)
coroThe coroutine to use as procedure
@@ -295,19 +345,19 @@

-

◆ clear()

+ +

◆ clear()

-template<template< class... > class Map = std::unordered_map, typename Lockable = std::mutex>
+template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>
- + @@ -325,19 +375,19 @@

-

◆ has()

+ +

◆ has()

-template<template< class... > class Map = std::unordered_map, typename Lockable = std::mutex>
+template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>

size_t packio::dispatcher< Map, Lockable >::clear size_t packio::dispatcher< Rpc, Map, Lockable >::clear ( )
- + @@ -362,19 +412,19 @@

-

◆ known()

+ +

◆ known()

-template<template< class... > class Map = std::unordered_map, typename Lockable = std::mutex>
+template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>

bool packio::dispatcher< Map, Lockable >::has bool packio::dispatcher< Rpc, Map, Lockable >::has ( const std::string &  name)
- + @@ -392,19 +442,19 @@

-

◆ remove()

+ +

◆ remove()

-template<template< class... > class Map = std::unordered_map, typename Lockable = std::mutex>
+template<typename Rpc , template< class... > class Map = default_map, typename Lockable = default_mutex>

std::vector<std::string> packio::dispatcher< Map, Lockable >::known std::vector<std::string> packio::dispatcher< Rpc, Map, Lockable >::known ( ) const
- + diff --git a/docs/classpackio_1_1msgpack_1_1rpc-members.html b/docs/classpackio_1_1msgpack_1_1rpc-members.html new file mode 100644 index 0000000..38690d0 --- /dev/null +++ b/docs/classpackio_1_1msgpack_1_1rpc-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+
bool packio::dispatcher< Map, Lockable >::remove bool packio::dispatcher< Rpc, Map, Lockable >::remove ( const std::string &  name)
+ + + + + +
+
packio +
+
+ + + + + + + + +
+
+ + +
+ +
+ + + +
+
+
packio::msgpack::rpc Member List
+
+
+ +

This is the complete list of members for packio::msgpack::rpc, including all inherited members.

+ + +
id_type typedefpackio::msgpack::rpc
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1msgpack_1_1rpc.html b/docs/classpackio_1_1msgpack_1_1rpc.html new file mode 100644 index 0000000..ae1c9eb --- /dev/null +++ b/docs/classpackio_1_1msgpack_1_1rpc.html @@ -0,0 +1,109 @@ + + + + + + + + + packio: packio::msgpack::rpc Class Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack::rpc Class Reference
+
+
+ +

The msgpack RPC protocol implementation. + More...

+ +

#include <packio/msgpack/rpc.h>

+ + + + + + + + +

+Classes

struct  request
 The object representing a client request. More...
 
struct  response
 The object representing the response to a call. More...
 
+ + + + +

+Public Types

+using id_type = uint32_t
 Type of the call ID.
 
+

Detailed Description

+

The msgpack RPC protocol implementation.

+

The documentation for this class was generated from the following file: +
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1msgpack__rpc_1_1incremental__parser-members.html b/docs/classpackio_1_1msgpack__rpc_1_1incremental__parser-members.html new file mode 100644 index 0000000..b26069b --- /dev/null +++ b/docs/classpackio_1_1msgpack__rpc_1_1incremental__parser-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack_rpc::incremental_parser Member List
+
+
+ +

This is the complete list of members for packio::msgpack_rpc::incremental_parser, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1msgpack__rpc_1_1incremental__parser.html b/docs/classpackio_1_1msgpack__rpc_1_1incremental__parser.html new file mode 100644 index 0000000..30a5c1d --- /dev/null +++ b/docs/classpackio_1_1msgpack__rpc_1_1incremental__parser.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::msgpack_rpc::incremental_parser Class Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc::incremental_parser Class Reference
+
+
+ +

The incremental parser for msgpack-RPC objects. + More...

+ +

#include <packio/msgpack_rpc/rpc.h>

+

Detailed Description

+

The incremental parser for msgpack-RPC objects.

+

The documentation for this class was generated from the following file:
    +
  • packio/msgpack_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1msgpack__rpc_1_1internal_1_1incremental__parser-members.html b/docs/classpackio_1_1msgpack__rpc_1_1internal_1_1incremental__parser-members.html new file mode 100644 index 0000000..9d84fe8 --- /dev/null +++ b/docs/classpackio_1_1msgpack__rpc_1_1internal_1_1incremental__parser-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack_rpc::internal::incremental_parser Member List
+
+
+ +

This is the complete list of members for packio::msgpack_rpc::internal::incremental_parser, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1msgpack__rpc_1_1internal_1_1incremental__parser.html b/docs/classpackio_1_1msgpack__rpc_1_1internal_1_1incremental__parser.html new file mode 100644 index 0000000..5b087a2 --- /dev/null +++ b/docs/classpackio_1_1msgpack__rpc_1_1internal_1_1incremental__parser.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::msgpack_rpc::internal::incremental_parser Class Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc::internal::incremental_parser Class Reference
+
+
+ +

The incremental parser for msgpack-RPC objects. + More...

+ +

#include <packio/msgpack_rpc/rpc.h>

+

Detailed Description

+

The incremental parser for msgpack-RPC objects.

+

The documentation for this class was generated from the following file:
    +
  • packio/msgpack_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1msgpack__rpc_1_1rpc-members.html b/docs/classpackio_1_1msgpack__rpc_1_1rpc-members.html new file mode 100644 index 0000000..4f1eb47 --- /dev/null +++ b/docs/classpackio_1_1msgpack__rpc_1_1rpc-members.html @@ -0,0 +1,86 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack_rpc::rpc Member List
+
+ + + + + \ No newline at end of file diff --git a/docs/classpackio_1_1msgpack__rpc_1_1rpc.html b/docs/classpackio_1_1msgpack__rpc_1_1rpc.html new file mode 100644 index 0000000..ec2b422 --- /dev/null +++ b/docs/classpackio_1_1msgpack__rpc_1_1rpc.html @@ -0,0 +1,115 @@ + + + + + + + + + packio: packio::msgpack_rpc::rpc Class Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc::rpc Class Reference
+
+
+ +

The msgpack RPC protocol implementation. + More...

+ +

#include <packio/msgpack_rpc/rpc.h>

+ + + + + + + + + + + + + + + + + +

+Public Types

+using id_type = internal::id_type
 Type of the call ID.
 
+using native_type = internal::native_type
 The native type of the serialization library.
 
+using request_type = internal::request
 The type of the parsed request object.
 
+using response_type = internal::response
 The type of the parsed response object.
 
+using incremental_parser_type = internal::incremental_parser
 The incremental parser type.
 
+

Detailed Description

+

The msgpack RPC protocol implementation.

+

The documentation for this class was generated from the following file:
    +
  • packio/msgpack_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1nl__json__rpc_1_1incremental__parser-members.html b/docs/classpackio_1_1nl__json__rpc_1_1incremental__parser-members.html new file mode 100644 index 0000000..5796cd2 --- /dev/null +++ b/docs/classpackio_1_1nl__json__rpc_1_1incremental__parser-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nl_json_rpc::incremental_parser Member List
+
+
+ +

This is the complete list of members for packio::nl_json_rpc::incremental_parser, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1nl__json__rpc_1_1incremental__parser.html b/docs/classpackio_1_1nl__json__rpc_1_1incremental__parser.html new file mode 100644 index 0000000..5b334ed --- /dev/null +++ b/docs/classpackio_1_1nl__json__rpc_1_1incremental__parser.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nl_json_rpc::incremental_parser Class Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc::incremental_parser Class Reference
+
+
+ +

The incremental parser for JSON-RPC objects. + More...

+ +

#include <packio/nl_json_rpc/rpc.h>

+

Detailed Description

+

The incremental parser for JSON-RPC objects.

+

The documentation for this class was generated from the following file:
    +
  • packio/nl_json_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1nl__json__rpc_1_1internal_1_1incremental__parser-members.html b/docs/classpackio_1_1nl__json__rpc_1_1internal_1_1incremental__parser-members.html new file mode 100644 index 0000000..0a82780 --- /dev/null +++ b/docs/classpackio_1_1nl__json__rpc_1_1internal_1_1incremental__parser-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nl_json_rpc::internal::incremental_parser Member List
+
+
+ +

This is the complete list of members for packio::nl_json_rpc::internal::incremental_parser, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1nl__json__rpc_1_1internal_1_1incremental__parser.html b/docs/classpackio_1_1nl__json__rpc_1_1internal_1_1incremental__parser.html new file mode 100644 index 0000000..a018fa2 --- /dev/null +++ b/docs/classpackio_1_1nl__json__rpc_1_1internal_1_1incremental__parser.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nl_json_rpc::internal::incremental_parser Class Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc::internal::incremental_parser Class Reference
+
+
+ +

The incremental parser for JSON-RPC objects. + More...

+ +

#include <packio/nl_json_rpc/rpc.h>

+

Detailed Description

+

The incremental parser for JSON-RPC objects.

+

The documentation for this class was generated from the following file:
    +
  • packio/nl_json_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1nl__json__rpc_1_1rpc-members.html b/docs/classpackio_1_1nl__json__rpc_1_1rpc-members.html new file mode 100644 index 0000000..82fb943 --- /dev/null +++ b/docs/classpackio_1_1nl__json__rpc_1_1rpc-members.html @@ -0,0 +1,86 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nl_json_rpc::rpc Member List
+
+ + + + + \ No newline at end of file diff --git a/docs/classpackio_1_1nl__json__rpc_1_1rpc.html b/docs/classpackio_1_1nl__json__rpc_1_1rpc.html new file mode 100644 index 0000000..8165029 --- /dev/null +++ b/docs/classpackio_1_1nl__json__rpc_1_1rpc.html @@ -0,0 +1,115 @@ + + + + + + + + + packio: packio::nl_json_rpc::rpc Class Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc::rpc Class Reference
+
+
+ +

The JSON-RPC protocol implementation. + More...

+ +

#include <packio/nl_json_rpc/rpc.h>

+ + + + + + + + + + + + + + + + + +

+Public Types

+using id_type = internal::id_type
 Type of the call ID.
 
+using native_type = internal::native_type
 The native type of the serialization library.
 
+using request_type = internal::request
 The type of the parsed request object.
 
+using response_type = internal::response
 The type of the parsed response object.
 
+using incremental_parser_type = internal::incremental_parser
 The incremental parser type.
 
+

Detailed Description

+

The JSON-RPC protocol implementation.

+

The documentation for this class was generated from the following file:
    +
  • packio/nl_json_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1nlohmann__json_1_1rpc-members.html b/docs/classpackio_1_1nlohmann__json_1_1rpc-members.html new file mode 100644 index 0000000..9a6a718 --- /dev/null +++ b/docs/classpackio_1_1nlohmann__json_1_1rpc-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nlohmann_json::rpc Member List
+
+
+ +

This is the complete list of members for packio::nlohmann_json::rpc, including all inherited members.

+ + +
id_type typedefpackio::nlohmann_json::rpc
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1nlohmann__json_1_1rpc.html b/docs/classpackio_1_1nlohmann__json_1_1rpc.html new file mode 100644 index 0000000..ee183b7 --- /dev/null +++ b/docs/classpackio_1_1nlohmann__json_1_1rpc.html @@ -0,0 +1,109 @@ + + + + + + + + + packio: packio::nlohmann_json::rpc Class Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nlohmann_json::rpc Class Reference
+
+
+ +

The JSON-RPC protocol implementation. + More...

+ +

#include <packio/nlohmann_json/rpc.h>

+ + + + + + + + +

+Classes

struct  request
 The object representing a client request. More...
 
struct  response
 The object representing the response to a call. More...
 
+ + + + +

+Public Types

+using id_type = nlohmann::json
 Type of the call ID.
 
+

Detailed Description

+

The JSON-RPC protocol implementation.

+

The documentation for this class was generated from the following file:
    +
  • packio/nlohmann_json/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/classpackio_1_1server-members.html b/docs/classpackio_1_1server-members.html index bedbb8b..9ff14b2 100644 --- a/docs/classpackio_1_1server-members.html +++ b/docs/classpackio_1_1server-members.html @@ -68,26 +68,27 @@
-
packio::server< Acceptor, Dispatcher > Member List
+
packio::server< Rpc, Acceptor, Dispatcher > Member List
-

This is the complete list of members for packio::server< Acceptor, Dispatcher >, including all inherited members.

+

This is the complete list of members for packio::server< Rpc, Acceptor, Dispatcher >, including all inherited members.

- - - - - - - - - - - - - - + + + + + + + + + + + + + + +
acceptor()packio::server< Acceptor, Dispatcher >inline
acceptor() constpackio::server< Acceptor, Dispatcher >inline
acceptor_type typedefpackio::server< Acceptor, Dispatcher >
async_serve(ServeHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))packio::server< Acceptor, Dispatcher >inline
async_serve_forever()packio::server< Acceptor, Dispatcher >inline
dispatcher()packio::server< Acceptor, Dispatcher >inline
dispatcher() constpackio::server< Acceptor, Dispatcher >inline
dispatcher_type typedefpackio::server< Acceptor, Dispatcher >
executor_type typedefpackio::server< Acceptor, Dispatcher >
get_executor()packio::server< Acceptor, Dispatcher >inline
protocol_type typedefpackio::server< Acceptor, Dispatcher >
server(acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)packio::server< Acceptor, Dispatcher >inline
server(acceptor_type acceptor)packio::server< Acceptor, Dispatcher >inlineexplicit
socket_type typedefpackio::server< Acceptor, Dispatcher >
acceptor()packio::server< Rpc, Acceptor, Dispatcher >inline
acceptor() constpackio::server< Rpc, Acceptor, Dispatcher >inline
acceptor_type typedefpackio::server< Rpc, Acceptor, Dispatcher >
async_serve(ServeHandler &&handler=typename net::default_completion_token< executor_type >::type())packio::server< Rpc, Acceptor, Dispatcher >inline
async_serve_forever()packio::server< Rpc, Acceptor, Dispatcher >inline
dispatcher()packio::server< Rpc, Acceptor, Dispatcher >inline
dispatcher() constpackio::server< Rpc, Acceptor, Dispatcher >inline
dispatcher_type typedefpackio::server< Rpc, Acceptor, Dispatcher >
executor_type typedefpackio::server< Rpc, Acceptor, Dispatcher >
get_executor()packio::server< Rpc, Acceptor, Dispatcher >inline
protocol_type typedefpackio::server< Rpc, Acceptor, Dispatcher >
rpc_type typedefpackio::server< Rpc, Acceptor, Dispatcher >
server(acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)packio::server< Rpc, Acceptor, Dispatcher >inline
server(acceptor_type acceptor)packio::server< Rpc, Acceptor, Dispatcher >inlineexplicit
socket_type typedefpackio::server< Rpc, Acceptor, Dispatcher >
diff --git a/docs/classpackio_1_1server.html b/docs/classpackio_1_1server.html index 96a6798..3135271 100644 --- a/docs/classpackio_1_1server.html +++ b/docs/classpackio_1_1server.html @@ -7,7 +7,7 @@ - packio: packio::server< Acceptor, Dispatcher > Class Template Reference + packio: packio::server< Rpc, Acceptor, Dispatcher > Class Template Reference @@ -72,7 +72,7 @@ Public Member Functions | List of all members
-
packio::server< Acceptor, Dispatcher > Class Template Reference
+
packio::server< Rpc, Acceptor, Dispatcher > Class Template Reference
@@ -83,99 +83,104 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +

Public Types

-using acceptor_type = Acceptor
 The acceptor type.
 
-using protocol_type = typename Acceptor::protocol_type
 The protocol type.
 
-using dispatcher_type = Dispatcher
 The dispatcher type.
 
-using executor_type = typename acceptor_type::executor_type
 The executor type.
 
-using socket_type = std::decay_t< decltype(std::declval< acceptor_type >().accept())>
 The connection socket type.
 
+using rpc_type = Rpc
 The RPC protocol type.
 
+using acceptor_type = Acceptor
 The acceptor type.
 
+using protocol_type = typename Acceptor::protocol_type
 The protocol type.
 
+using dispatcher_type = Dispatcher
 The dispatcher type.
 
+using executor_type = typename acceptor_type::executor_type
 The executor type.
 
+using socket_type = std::decay_t< decltype(std::declval< acceptor_type >().accept())>
 The connection socket type.
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Member Functions

 server (acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)
 The constructor. More...
 
server (acceptor_type acceptor)
 Simplified constructor: will allocate a new dispatcher automatically This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
-acceptor_typeacceptor ()
 Get the underlying acceptor.
 
-const acceptor_typeacceptor () const
 Get the underlying acceptor, const.
 
-std::shared_ptr< dispatcher_typedispatcher ()
 Get the dispatcher.
 
-std::shared_ptr< const dispatcher_typedispatcher () const
 Get the dispatcher, const.
 
-executor_type get_executor ()
 Get the executor associated with the object.
 
template<PACKIO_COMPLETION_TOKEN_FOR(void(error_code, std::shared_ptr< session_type >)) ServeHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
auto async_serve (ServeHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 Accept one connection and initialize a session for it. More...
 
-void async_serve_forever ()
 Accept connections and automatically start the associated sessions forever.
 
 server (acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)
 The constructor. More...
 
server (acceptor_type acceptor)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
+acceptor_typeacceptor ()
 Get the underlying acceptor.
 
+const acceptor_typeacceptor () const
 Get the underlying acceptor, const.
 
+std::shared_ptr< dispatcher_typedispatcher ()
 Get the dispatcher.
 
+std::shared_ptr< const dispatcher_typedispatcher () const
 Get the dispatcher, const.
 
+executor_type get_executor ()
 Get the executor associated with the object.
 
template<typename ServeHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE>
auto async_serve (ServeHandler &&handler=typename net::default_completion_token< executor_type >::type())
 Accept one connection and initialize a session for it. More...
 
+void async_serve_forever ()
 Accept connections and automatically start the associated sessions forever.
 

Detailed Description

-

template<typename Acceptor, typename Dispatcher = dispatcher<>>
-class packio::server< Acceptor, Dispatcher >

+

template<typename Rpc, typename Acceptor, typename Dispatcher = dispatcher<Rpc>>
+class packio::server< Rpc, Acceptor, Dispatcher >

The server class.

Template Parameters
+
RpcRPC protocol implementation
AcceptorAcceptor type to use for this server
DispatcherDispatcher used to store and dispatch procedures. See dispatcher

Constructor & Destructor Documentation

- -

◆ server()

+ +

◆ server()

-template<typename Acceptor , typename Dispatcher = dispatcher<>>
+template<typename Rpc , typename Acceptor , typename Dispatcher = dispatcher<Rpc>>
- + - + - + @@ -203,24 +208,24 @@

Member Function Documentation

- -

◆ async_serve()

+ +

◆ async_serve()

-template<typename Acceptor , typename Dispatcher = dispatcher<>>
+template<typename Rpc , typename Acceptor , typename Dispatcher = dispatcher<Rpc>>
-template<PACKIO_COMPLETION_TOKEN_FOR(void(error_code, std::shared_ptr< session_type >)) ServeHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
+template<typename ServeHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE>
packio::server< Acceptor, Dispatcher >::server packio::server< Rpc, Acceptor, Dispatcher >::server (acceptor_type acceptor_type  acceptor,
std::shared_ptr< dispatcher_typestd::shared_ptr< dispatcher_type dispatcher 
- + - - + +
auto packio::server< Acceptor, Dispatcher >::async_serve auto packio::server< Rpc, Acceptor, Dispatcher >::async_serve (ServeHandler &&handler  PACKIO_DEFAULT_COMPLETION_TOKENexecutor_type)ServeHandler && handler = typename net::default_completion_token< executor_type >::type())
@@ -234,7 +239,7 @@

Parameters
- +
handlerHandler called when a connection is accepted. The handler is responsible for calling server_session::start. Must satisfy the traits::ServeHandler trait
handlerHandler called when a connection is accepted. The handler is responsible for calling server_session::start. Must satisfy the traits::ServeHandler trait
diff --git a/docs/classpackio_1_1server__session-members.html b/docs/classpackio_1_1server__session-members.html index 1811eeb..ae08351 100644 --- a/docs/classpackio_1_1server__session-members.html +++ b/docs/classpackio_1_1server__session-members.html @@ -68,22 +68,22 @@
-
packio::server_session< Socket, Dispatcher > Member List
+
packio::server_session< Rpc, Socket, Dispatcher > Member List
-

This is the complete list of members for packio::server_session< Socket, Dispatcher >, including all inherited members.

+

This is the complete list of members for packio::server_session< Rpc, Socket, Dispatcher >, including all inherited members.

- - - - - - - - - - + + + + + + + + + +
executor_type typedefpackio::server_session< Socket, Dispatcher >
get_buffer_reserve_size() const noexceptpackio::server_session< Socket, Dispatcher >inline
get_executor()packio::server_session< Socket, Dispatcher >inline
kDefaultBufferReserveSizepackio::server_session< Socket, Dispatcher >static
protocol_type typedefpackio::server_session< Socket, Dispatcher >
set_buffer_reserve_size(std::size_t size) noexceptpackio::server_session< Socket, Dispatcher >inline
socket()packio::server_session< Socket, Dispatcher >inline
socket() constpackio::server_session< Socket, Dispatcher >inline
socket_type typedefpackio::server_session< Socket, Dispatcher >
start()packio::server_session< Socket, Dispatcher >inline
executor_type typedefpackio::server_session< Rpc, Socket, Dispatcher >
get_buffer_reserve_size() const noexceptpackio::server_session< Rpc, Socket, Dispatcher >inline
get_executor()packio::server_session< Rpc, Socket, Dispatcher >inline
kDefaultBufferReserveSizepackio::server_session< Rpc, Socket, Dispatcher >static
protocol_type typedefpackio::server_session< Rpc, Socket, Dispatcher >
set_buffer_reserve_size(std::size_t size) noexceptpackio::server_session< Rpc, Socket, Dispatcher >inline
socket()packio::server_session< Rpc, Socket, Dispatcher >inline
socket() constpackio::server_session< Rpc, Socket, Dispatcher >inline
socket_type typedefpackio::server_session< Rpc, Socket, Dispatcher >
start()packio::server_session< Rpc, Socket, Dispatcher >inline
diff --git a/docs/classpackio_1_1server__session.html b/docs/classpackio_1_1server__session.html index cd122b8..220f6b2 100644 --- a/docs/classpackio_1_1server__session.html +++ b/docs/classpackio_1_1server__session.html @@ -7,7 +7,7 @@ - packio: packio::server_session< Socket, Dispatcher > Class Template Reference + packio: packio::server_session< Rpc, Socket, Dispatcher > Class Template Reference @@ -73,7 +73,7 @@ Static Public Attributes | List of all members
-
packio::server_session< Socket, Dispatcher > Class Template Reference
+
packio::server_session< Rpc, Socket, Dispatcher > Class Template Reference
@@ -84,56 +84,56 @@ - - - - - - - - - + + + + + + + + +

Public Types

-using socket_type = Socket
 The socket type.
 
-using protocol_type = typename socket_type::protocol_type
 The protocol type.
 
-using executor_type = typename socket_type::executor_type
 The executor type.
 
+using socket_type = Socket
 The socket type.
 
+using protocol_type = typename socket_type::protocol_type
 The protocol type.
 
+using executor_type = typename socket_type::executor_type
 The executor type.
 
- - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +

Public Member Functions

-socket_typesocket ()
 Get the underlying socket.
 
-const socket_typesocket () const
 Get the underlying socket, const.
 
-executor_type get_executor ()
 Get the executor associated with the object.
 
-void set_buffer_reserve_size (std::size_t size) noexcept
 Set the size reserved by the reception buffer.
 
-std::size_t get_buffer_reserve_size () const noexcept
 Get the size reserved by the reception buffer.
 
-void start ()
 Start the session.
 
+socket_typesocket ()
 Get the underlying socket.
 
+const socket_typesocket () const
 Get the underlying socket, const.
 
+executor_type get_executor ()
 Get the executor associated with the object.
 
+void set_buffer_reserve_size (std::size_t size) noexcept
 Set the size reserved by the reception buffer.
 
+std::size_t get_buffer_reserve_size () const noexcept
 Get the size reserved by the reception buffer.
 
+void start ()
 Start the session.
 
- - - + + +

Static Public Attributes

-static constexpr size_t kDefaultBufferReserveSize = 4096
 The default size reserved by the reception buffer.
 
+static constexpr size_t kDefaultBufferReserveSize = 4096
 The default size reserved by the reception buffer.
 

Detailed Description

-

template<typename Socket, typename Dispatcher>
-class packio::server_session< Socket, Dispatcher >

+

template<typename Rpc, typename Socket, typename Dispatcher>
+class packio::server_session< Rpc, Socket, Dispatcher >

The server_session class, created by the server.


The documentation for this class was generated from the following file:
    diff --git a/docs/client_8h.html b/docs/client_8h.html index 7a2a139..1bd001f 100644 --- a/docs/client_8h.html +++ b/docs/client_8h.html @@ -78,17 +78,14 @@
    #include <atomic>
    #include <chrono>
    #include <functional>
    -#include <map>
    #include <memory>
    #include <queue>
    #include <string_view>
    #include <type_traits>
    -#include <msgpack.hpp>
    -#include "error_code.h"
    #include "internal/config.h"
    #include "internal/manual_strand.h"
    -#include "internal/msgpack_rpc.h"
    -#include "internal/unique_function.h"
    +#include "internal/movable_function.h"
    +#include "internal/rpc.h"
    #include "internal/utils.h"
    #include "traits.h"
    @@ -96,7 +93,7 @@ - +

    Classes

    class  packio::client< Socket, Map >
    class  packio::client< Rpc, Socket, Map >
     The client class. More...
     
    @@ -107,10 +104,10 @@
    - - - - + + + +

    Functions

    template<typename Socket , template< class... > class Map = std::map>
    auto packio::make_client (Socket &&socket)
     Create a client from a socket. More...
     
    template<typename Rpc , typename Socket , template< class... > class Map = default_map>
    auto packio::make_client (Socket &&socket)
     Create a client from a socket. More...
     

    Detailed Description

    Class client

    diff --git a/docs/client_8h_source.html b/docs/client_8h_source.html index 56a66e5..d90a268 100644 --- a/docs/client_8h_source.html +++ b/docs/client_8h_source.html @@ -82,462 +82,434 @@
    11 #include <atomic>
    12 #include <chrono>
    13 #include <functional>
    -
    14 #include <map>
    -
    15 #include <memory>
    -
    16 #include <queue>
    -
    17 #include <string_view>
    -
    18 #include <type_traits>
    -
    19 
    -
    20 #include <msgpack.hpp>
    -
    21 
    -
    22 #include "error_code.h"
    -
    23 #include "internal/config.h"
    -
    24 #include "internal/manual_strand.h"
    -
    25 #include "internal/msgpack_rpc.h"
    -
    26 #include "internal/unique_function.h"
    -
    27 #include "internal/utils.h"
    -
    28 #include "traits.h"
    -
    29 
    -
    30 namespace packio {
    -
    31 
    -
    35 template <typename Socket, template <class...> class Map = std::map>
    -
    36 class client : public std::enable_shared_from_this<client<Socket, Map>> {
    -
    37 public:
    -
    38  using socket_type = Socket;
    -
    39  using protocol_type =
    -
    40  typename socket_type::protocol_type;
    -
    41  using executor_type =
    -
    42  typename socket_type::executor_type;
    -
    43  using std::enable_shared_from_this<client<Socket, Map>>::shared_from_this;
    -
    44 
    -
    46  static constexpr size_t kDefaultBufferReserveSize = 4096;
    -
    47 
    - -
    51  : socket_{std::move(socket)},
    -
    52  wstrand_{socket_.get_executor()},
    -
    53  call_strand_{socket_.get_executor()}
    -
    54  {
    -
    55  }
    -
    56 
    -
    58  socket_type& socket() noexcept { return socket_; }
    -
    60  const socket_type& socket() const noexcept { return socket_; }
    -
    61 
    -
    63  void set_buffer_reserve_size(std::size_t size) noexcept
    -
    64  {
    -
    65  buffer_reserve_size_ = size;
    -
    66  }
    -
    68  std::size_t get_buffer_reserve_size() const noexcept
    +
    14 #include <memory>
    +
    15 #include <queue>
    +
    16 #include <string_view>
    +
    17 #include <type_traits>
    +
    18 
    +
    19 #include "internal/config.h"
    +
    20 #include "internal/manual_strand.h"
    +
    21 #include "internal/movable_function.h"
    +
    22 #include "internal/rpc.h"
    +
    23 #include "internal/utils.h"
    +
    24 #include "traits.h"
    +
    25 
    +
    26 namespace packio {
    +
    27 
    +
    32 template <typename Rpc, typename Socket, template <class...> class Map = default_map>
    +
    33 class client : public std::enable_shared_from_this<client<Rpc, Socket, Map>> {
    +
    34 public:
    +
    36  using rpc_type = Rpc;
    +
    38  using id_type = typename rpc_type::id_type;
    +
    40  using response_type = typename rpc_type::response_type;
    +
    42  using socket_type = Socket;
    +
    44  using protocol_type = typename socket_type::protocol_type;
    +
    46  using executor_type = typename socket_type::executor_type;
    +
    47  using std::enable_shared_from_this<client<Rpc, Socket, Map>>::shared_from_this;
    +
    48 
    +
    50  static constexpr size_t kDefaultBufferReserveSize = 4096;
    +
    51 
    + +
    55  : socket_{std::move(socket)},
    +
    56  wstrand_{socket_.get_executor()},
    +
    57  call_strand_{socket_.get_executor()}
    +
    58  {
    +
    59  }
    +
    60 
    +
    62  socket_type& socket() noexcept { return socket_; }
    +
    63 
    +
    65  const socket_type& socket() const noexcept { return socket_; }
    +
    66 
    +
    68  void set_buffer_reserve_size(std::size_t size) noexcept
    69  {
    -
    70  return buffer_reserve_size_;
    +
    70  buffer_reserve_size_ = size;
    71  }
    -
    72 
    -
    74  executor_type get_executor() { return socket().get_executor(); }
    -
    75 
    -
    80  void cancel(id_type id)
    -
    81  {
    -
    82  net::dispatch(call_strand_, [self = shared_from_this(), id] {
    -
    83  auto ec = make_error_code(error::cancelled);
    -
    84  self->async_call_handler(
    -
    85  id, internal::make_msgpack_object(ec.message()), ec);
    -
    86  self->maybe_stop_reading();
    -
    87  });
    -
    88  }
    -
    89 
    -
    93  void cancel()
    -
    94  {
    -
    95  net::dispatch(call_strand_, [self = shared_from_this()] {
    -
    96  auto ec = make_error_code(error::cancelled);
    -
    97  while (!self->pending_.empty()) {
    -
    98  self->async_call_handler(
    -
    99  self->pending_.begin()->first,
    -
    100  internal::make_msgpack_object(ec.message()),
    -
    101  ec);
    -
    102  }
    -
    103  self->maybe_stop_reading();
    -
    104  });
    -
    105  }
    -
    106 
    -
    118  template <
    -
    119  typename Buffer = msgpack::sbuffer,
    -
    120  PACKIO_COMPLETION_TOKEN_FOR(void(error_code))
    -
    121  NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type),
    -
    122  typename... Args>
    - -
    124  std::string_view name,
    -
    125  const std::tuple<Args...>& args,
    -
    126  NotifyHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
    -
    127  {
    -
    128  return net::async_initiate<NotifyHandler, void(error_code)>(
    -
    129  initiate_async_notify<Buffer>(this), handler, name, args);
    -
    130  }
    -
    131 
    -
    134  template <
    -
    135  typename Buffer = msgpack::sbuffer,
    -
    136  PACKIO_COMPLETION_TOKEN_FOR(void(error_code))
    -
    137  NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type),
    -
    138  typename = std::enable_if_t<!internal::is_tuple_v<NotifyHandler>>>
    - -
    140  std::string_view name,
    -
    141  NotifyHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
    -
    142  {
    -
    143  return async_notify<Buffer>(
    -
    144  name, std::tuple{}, std::forward<NotifyHandler>(handler));
    -
    145  }
    -
    146 
    -
    157  template <
    -
    158  typename Buffer = msgpack::sbuffer,
    -
    159  PACKIO_COMPLETION_TOKEN_FOR(void(error_code, msgpack::object_handle))
    -
    160  CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type),
    -
    161  typename... Args>
    - -
    163  std::string_view name,
    -
    164  const std::tuple<Args...>& args,
    -
    165  CallHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type),
    -
    166  std::optional<std::reference_wrapper<id_type>> call_id = std::nullopt)
    -
    167  {
    -
    168  return net::async_initiate<CallHandler, void(error_code, msgpack::object_handle)>(
    -
    169  initiate_async_call<Buffer>(this), handler, name, args, call_id);
    -
    170  }
    -
    171 
    -
    174  template <
    -
    175  typename Buffer = msgpack::sbuffer,
    -
    176  PACKIO_COMPLETION_TOKEN_FOR(void(error_code, msgpack::object_handle))
    -
    177  CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type),
    -
    178  typename = std::enable_if_t<!internal::is_tuple_v<CallHandler>>>
    - -
    180  std::string_view name,
    -
    181  CallHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type),
    -
    182  std::optional<std::reference_wrapper<id_type>> call_id = std::nullopt)
    -
    183  {
    -
    184  return async_call<Buffer>(
    -
    185  name, std::tuple{}, std::forward<CallHandler>(handler), call_id);
    -
    186  }
    -
    187 
    -
    188 private:
    -
    189  using async_call_handler_type =
    -
    190  internal::unique_function<void(error_code, msgpack::object_handle)>;
    -
    191 
    -
    192  void maybe_stop_reading()
    -
    193  {
    -
    194  assert(call_strand_.running_in_this_thread());
    -
    195  if (reading_ && pending_.empty()) {
    -
    196  PACKIO_DEBUG("stop reading");
    -
    197  error_code ec;
    -
    198  socket_.cancel(ec);
    -
    199  if (ec) {
    -
    200  PACKIO_WARN("cancel failed: {}", ec.message());
    -
    201  }
    -
    202  }
    -
    203  }
    -
    204 
    -
    205  template <typename Buffer, typename WriteHandler>
    -
    206  void async_send(std::unique_ptr<Buffer> buffer_ptr, WriteHandler&& handler)
    -
    207  {
    -
    208  wstrand_.push([this,
    -
    209  self = shared_from_this(),
    -
    210  buffer_ptr = std::move(buffer_ptr),
    -
    211  handler = std::forward<WriteHandler>(handler)]() mutable {
    -
    212  using internal::buffer;
    -
    213 
    -
    214  internal::set_no_delay(socket_);
    +
    73  std::size_t get_buffer_reserve_size() const noexcept
    +
    74  {
    +
    75  return buffer_reserve_size_;
    +
    76  }
    +
    77 
    +
    79  executor_type get_executor() { return socket().get_executor(); }
    +
    80 
    +
    85  void cancel(id_type id)
    +
    86  {
    +
    87  net::dispatch(call_strand_, [self = shared_from_this(), id] {
    +
    88  auto ec = make_error_code(net::error::operation_aborted);
    +
    89  self->async_call_handler(id, ec, {});
    +
    90  });
    +
    91  }
    +
    92 
    +
    96  void cancel()
    +
    97  {
    +
    98  net::dispatch(call_strand_, [self = shared_from_this()] {
    +
    99  self->cancel_all_calls();
    +
    100  });
    +
    101  }
    +
    102 
    +
    111  template <
    +
    112  PACKIO_COMPLETION_TOKEN_FOR(void(error_code))
    +
    113  NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type),
    +
    114  typename ArgsTuple,
    +
    115  typename = std::enable_if_t<internal::is_tuple_v<ArgsTuple>>>
    + +
    117  std::string_view name,
    +
    118  ArgsTuple&& args,
    +
    119  NotifyHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
    +
    120  {
    +
    121  return net::async_initiate<NotifyHandler, void(error_code)>(
    +
    122  initiate_async_notify(this),
    +
    123  handler,
    +
    124  name,
    +
    125  std::forward<ArgsTuple>(args));
    +
    126  }
    +
    127 
    +
    129  template <
    +
    130  PACKIO_COMPLETION_TOKEN_FOR(void(error_code))
    +
    131  NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type),
    +
    132  typename = std::enable_if_t<!internal::is_tuple_v<NotifyHandler>>>
    + +
    134  std::string_view name,
    +
    135  NotifyHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
    +
    136  {
    +
    137  return async_notify(
    +
    138  name, std::tuple{}, std::forward<NotifyHandler>(handler));
    +
    139  }
    +
    140 
    +
    148  template <
    +
    149  PACKIO_COMPLETION_TOKEN_FOR(void(error_code, response_type))
    +
    150  CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type),
    +
    151  typename ArgsTuple,
    +
    152  typename = std::enable_if_t<internal::is_tuple_v<ArgsTuple>>>
    + +
    154  std::string_view name,
    +
    155  ArgsTuple&& args,
    +
    156  CallHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type),
    +
    157  std::optional<std::reference_wrapper<id_type>> call_id = std::nullopt)
    +
    158  {
    +
    159  return net::async_initiate<CallHandler, void(error_code, response_type)>(
    +
    160  initiate_async_call(this),
    +
    161  handler,
    +
    162  name,
    +
    163  std::forward<ArgsTuple>(args),
    +
    164  call_id);
    +
    165  }
    +
    166 
    +
    168  template <
    +
    169  PACKIO_COMPLETION_TOKEN_FOR(void(error_code, response_type))
    +
    170  CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type),
    +
    171  typename = std::enable_if_t<!internal::is_tuple_v<CallHandler>>>
    + +
    173  std::string_view name,
    +
    174  CallHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type),
    +
    175  std::optional<std::reference_wrapper<id_type>> call_id = std::nullopt)
    +
    176  {
    +
    177  return async_call(
    +
    178  name, std::tuple{}, std::forward<CallHandler>(handler), call_id);
    +
    179  }
    +
    180 
    +
    181 private:
    +
    182  using parser_type = typename rpc_type::incremental_parser_type;
    +
    183  using async_call_handler_type =
    +
    184  internal::movable_function<void(error_code, response_type)>;
    +
    185 
    +
    186  void cancel_all_calls()
    +
    187  {
    +
    188  assert(call_strand_.running_in_this_thread());
    +
    189  auto ec = make_error_code(net::error::operation_aborted);
    +
    190  while (!pending_.empty()) {
    +
    191  async_call_handler(pending_.begin()->first, ec, {});
    +
    192  }
    +
    193  }
    +
    194 
    +
    195  void maybe_stop_reading()
    +
    196  {
    +
    197  assert(call_strand_.running_in_this_thread());
    +
    198  if (reading_ && pending_.empty()) {
    +
    199  PACKIO_DEBUG("stop reading");
    +
    200  error_code ec;
    +
    201  socket_.cancel(ec);
    +
    202  if (ec) {
    +
    203  PACKIO_WARN("cancel failed: {}", ec.message());
    +
    204  }
    +
    205  }
    +
    206  }
    +
    207 
    +
    208  template <typename Buffer, typename WriteHandler>
    +
    209  void async_send(std::unique_ptr<Buffer>&& buffer_ptr, WriteHandler&& handler)
    +
    210  {
    +
    211  wstrand_.push([self = shared_from_this(),
    +
    212  buffer_ptr = std::move(buffer_ptr),
    +
    213  handler = std::forward<WriteHandler>(handler)]() mutable {
    +
    214  internal::set_no_delay(self->socket_);
    215 
    -
    216  auto buf = buffer(*buffer_ptr);
    +
    216  auto buf = rpc_type::buffer(*buffer_ptr);
    217  net::async_write(
    -
    218  socket_,
    +
    218  self->socket_,
    219  buf,
    -
    220  [self = std::move(self),
    +
    220  [self,
    221  buffer_ptr = std::move(buffer_ptr),
    222  handler = std::forward<WriteHandler>(handler)](
    223  error_code ec, size_t length) mutable {
    -
    224  self->wstrand_.next();
    +
    224  self->wstrand_.next();
    225  handler(ec, length);
    226  });
    227  });
    228  }
    229 
    -
    230  void async_read(std::unique_ptr<msgpack::unpacker> unpacker)
    +
    230  void async_read(parser_type&& parser)
    231  {
    -
    232  unpacker->reserve_buffer(buffer_reserve_size_);
    -
    233  auto buffer = net::buffer(
    -
    234  unpacker->buffer(), unpacker->buffer_capacity());
    -
    235 
    -
    236  assert(call_strand_.running_in_this_thread());
    -
    237  reading_ = true;
    -
    238  PACKIO_TRACE("reading ... {} call(s) pending", pending_.size());
    -
    239  socket_.async_read_some(
    -
    240  buffer,
    -
    241  net::bind_executor(
    -
    242  call_strand_,
    -
    243  [self = shared_from_this(), unpacker = std::move(unpacker)](
    -
    244  error_code ec, size_t length) mutable {
    -
    245  PACKIO_TRACE("read: {}", length);
    -
    246  unpacker->buffer_consumed(length);
    -
    247 
    -
    248  msgpack::object_handle response;
    -
    249  while (unpacker->next(response)) {
    -
    250  self->process_response(std::move(response), ec);
    -
    251  }
    -
    252 
    -
    253  // stop if there is an error or there is no more pending calls
    -
    254  assert(self->call_strand_.running_in_this_thread());
    +
    232  parser.reserve_buffer(buffer_reserve_size_);
    +
    233  auto buffer = net::buffer(parser.buffer(), parser.buffer_capacity());
    +
    234 
    +
    235  assert(call_strand_.running_in_this_thread());
    +
    236  reading_ = true;
    +
    237  PACKIO_TRACE("reading ... {} call(s) pending", pending_.size());
    +
    238  socket_.async_read_some(
    +
    239  buffer,
    +
    240  net::bind_executor(
    +
    241  call_strand_,
    +
    242  [self = shared_from_this(), parser = std::move(parser)](
    +
    243  error_code ec, size_t length) mutable {
    +
    244  // stop if there is an error or there is no more pending calls
    +
    245  assert(self->call_strand_.running_in_this_thread());
    +
    246 
    +
    247  if (ec) {
    +
    248  PACKIO_WARN("read error: {}", ec.message());
    +
    249  self->reading_ = false;
    +
    250 
    +
    251  // cancel all pending calls
    +
    252  self->cancel_all_calls();
    +
    253  return;
    +
    254  }
    255 
    -
    256  if (ec && ec != net::error::operation_aborted) {
    -
    257  PACKIO_WARN("read error: {}", ec.message());
    -
    258  self->reading_ = false;
    -
    259  return;
    -
    260  }
    -
    261 
    -
    262  if (self->pending_.empty()) {
    -
    263  PACKIO_TRACE("done reading, no more pending calls");
    -
    264  self->reading_ = false;
    -
    265  return;
    -
    266  }
    -
    267 
    -
    268  self->async_read(std::move(unpacker));
    -
    269  }));
    -
    270  }
    -
    271 
    -
    272  void process_response(msgpack::object_handle response, error_code ec)
    -
    273  {
    -
    274  if (!verify_reponse(response.get())) {
    -
    275  PACKIO_ERROR("received unexpected response");
    -
    276  return;
    -
    277  }
    -
    278 
    -
    279  const auto& call_response = response->via.array.ptr;
    -
    280  int id = call_response[1].as<int>();
    -
    281  msgpack::object err = call_response[2];
    -
    282  msgpack::object result = call_response[3];
    -
    283 
    -
    284  if (err.type != msgpack::type::NIL) {
    -
    285  ec = make_error_code(error::call_error);
    -
    286  async_call_handler(id, {err, std::move(response.zone())}, ec);
    -
    287  }
    -
    288  else {
    -
    289  ec = make_error_code(error::success);
    -
    290  async_call_handler(id, {result, std::move(response.zone())}, ec);
    -
    291  }
    -
    292  }
    +
    256  PACKIO_TRACE("read: {}", length);
    +
    257  parser.buffer_consumed(length);
    +
    258 
    +
    259  while (auto response = parser.get_response()) {
    +
    260  if (!response) {
    +
    261  PACKIO_ERROR("bad response");
    +
    262  continue;
    +
    263  }
    +
    264  self->async_call_handler(std::move(*response));
    +
    265  }
    +
    266 
    +
    267  if (self->pending_.empty()) {
    +
    268  PACKIO_TRACE("done reading, no more pending calls");
    +
    269  self->reading_ = false;
    +
    270  return;
    +
    271  }
    +
    272 
    +
    273  self->async_read(std::move(parser));
    +
    274  }));
    +
    275  }
    +
    276 
    +
    277  void async_call_handler(response_type&& response)
    +
    278  {
    +
    279  auto id = response.id;
    +
    280  return async_call_handler(id, {}, std::move(response));
    +
    281  }
    +
    282 
    +
    283  void async_call_handler(id_type id, error_code ec, response_type&& response)
    +
    284  {
    +
    285  net::dispatch(
    +
    286  call_strand_,
    +
    287  [ec,
    +
    288  id,
    +
    289  self = shared_from_this(),
    +
    290  response = std::move(response)]() mutable {
    +
    291  PACKIO_DEBUG(
    +
    292  "calling handler for id: {}", rpc_type::format_id(id));
    293 
    -
    294  void async_call_handler(id_type id, msgpack::object_handle result, error_code ec)
    -
    295  {
    -
    296  net::dispatch(
    -
    297  call_strand_, [this, ec, id, result = std::move(result)]() mutable {
    -
    298  PACKIO_DEBUG("calling handler for id: {}", id);
    -
    299 
    -
    300  assert(call_strand_.running_in_this_thread());
    -
    301  auto it = pending_.find(id);
    -
    302  if (it == pending_.end()) {
    -
    303  PACKIO_WARN("unexisting id");
    -
    304  return;
    -
    305  }
    -
    306 
    -
    307  auto handler = std::move(it->second);
    -
    308  pending_.erase(it);
    -
    309 
    -
    310  // handle the response asynchronously (post)
    -
    311  // to schedule the next read immediately
    -
    312  // this will allow parallel response handling
    -
    313  // in multi-threaded environments
    -
    314  net::post(
    -
    315  socket_.get_executor(),
    -
    316  [ec,
    -
    317  handler = std::move(handler),
    -
    318  result = std::move(result)]() mutable {
    -
    319  handler(ec, std::move(result));
    -
    320  });
    -
    321  });
    -
    322  }
    -
    323 
    -
    324  bool verify_reponse(const msgpack::object& response)
    -
    325  {
    -
    326  if (response.type != msgpack::type::ARRAY) {
    -
    327  PACKIO_ERROR("unexpected message type: {}", response.type);
    -
    328  return false;
    -
    329  }
    -
    330  if (response.via.array.size != 4) {
    -
    331  PACKIO_ERROR("unexpected message size: {}", response.via.array.size);
    -
    332  return false;
    -
    333  }
    -
    334  int type = response.via.array.ptr[0].as<int>();
    -
    335  if (type != static_cast<int>(msgpack_rpc_type::response)) {
    -
    336  PACKIO_ERROR("unexpected type: {}", type);
    -
    337  return false;
    -
    338  }
    -
    339  return true;
    -
    340  }
    -
    341 
    -
    342  template <typename Buffer>
    -
    343  class initiate_async_notify {
    -
    344  public:
    -
    345  using executor_type = typename client::executor_type;
    -
    346 
    -
    347  explicit initiate_async_notify(client* self) : self_(self) {}
    -
    348 
    -
    349  executor_type get_executor() const noexcept
    -
    350  {
    -
    351  return self_->get_executor();
    -
    352  }
    -
    353 
    -
    354  template <typename NotifyHandler, typename... Args>
    -
    355  void operator()(
    -
    356  NotifyHandler&& handler,
    -
    357  std::string_view name,
    -
    358  const std::tuple<Args...>& args) const
    -
    359  {
    -
    360  PACKIO_STATIC_ASSERT_TRAIT(NotifyHandler);
    -
    361  PACKIO_DEBUG("async_notify: {}", name);
    +
    294  assert(call_strand_.running_in_this_thread());
    +
    295  auto it = self->pending_.find(id);
    +
    296  if (it == self->pending_.end()) {
    +
    297  PACKIO_WARN("unexisting id: {}", rpc_type::format_id(id));
    +
    298  return;
    +
    299  }
    +
    300 
    +
    301  auto handler = std::move(it->second);
    +
    302  self->pending_.erase(it);
    +
    303  self->maybe_stop_reading();
    +
    304 
    +
    305  // handle the response asynchronously (post)
    +
    306  // to schedule the next read immediately
    +
    307  // this will allow parallel response handling
    +
    308  // in multi-threaded environments
    +
    309  net::post(
    +
    310  self->socket_.get_executor(),
    +
    311  [ec,
    +
    312  handler = std::move(handler),
    +
    313  response = std::move(response)]() mutable {
    +
    314  handler(ec, std::move(response));
    +
    315  });
    +
    316  });
    +
    317  }
    +
    318 
    +
    319  class initiate_async_notify {
    +
    320  public:
    +
    321  using executor_type = typename client::executor_type;
    +
    322 
    +
    323  explicit initiate_async_notify(client* self) : self_(self) {}
    +
    324 
    +
    325  executor_type get_executor() const noexcept
    +
    326  {
    +
    327  return self_->get_executor();
    +
    328  }
    +
    329 
    +
    330  template <typename NotifyHandler, typename ArgsTuple>
    +
    331  void operator()(
    +
    332  NotifyHandler&& handler,
    +
    333  std::string_view name,
    +
    334  ArgsTuple&& args) const
    +
    335  {
    +
    336  PACKIO_STATIC_ASSERT_TRAIT(NotifyHandler);
    +
    337  PACKIO_DEBUG("async_notify: {}", name);
    +
    338 
    +
    339  auto packer_buf = internal::to_unique_ptr(std::apply(
    +
    340  [&name](auto&&... args) {
    +
    341  return rpc_type::serialize_notification(
    +
    342  name, std::forward<decltype(args)>(args)...);
    +
    343  },
    +
    344  std::forward<ArgsTuple>(args))
    +
    345 
    +
    346  );
    +
    347  self_->async_send(
    +
    348  std::move(packer_buf),
    +
    349  [handler = std::forward<NotifyHandler>(handler)](
    +
    350  error_code ec, std::size_t length) mutable {
    +
    351  if (ec) {
    +
    352  PACKIO_WARN("write error: {}", ec.message());
    +
    353  }
    +
    354  else {
    +
    355  PACKIO_TRACE("write: {}", length);
    +
    356  (void)length;
    +
    357  }
    +
    358 
    +
    359  handler(ec);
    +
    360  });
    +
    361  }
    362 
    -
    363  auto packer_buf = std::make_unique<Buffer>();
    -
    364  msgpack::pack(
    -
    365  *packer_buf,
    -
    366  std::forward_as_tuple(
    -
    367  static_cast<int>(msgpack_rpc_type::notification), name, args));
    -
    368 
    -
    369  self_->async_send(
    -
    370  std::move(packer_buf),
    -
    371  [handler = std::forward<NotifyHandler>(handler)](
    -
    372  error_code ec, std::size_t length) mutable {
    -
    373  if (ec) {
    -
    374  PACKIO_WARN("write error: {}", ec.message());
    -
    375  }
    -
    376  else {
    -
    377  PACKIO_TRACE("write: {}", length);
    -
    378  (void)length;
    -
    379  }
    -
    380 
    -
    381  handler(ec);
    -
    382  });
    -
    383  }
    -
    384 
    -
    385  private:
    -
    386  client* self_;
    -
    387  };
    -
    388 
    -
    389  template <typename Buffer>
    -
    390  class initiate_async_call {
    -
    391  public:
    -
    392  using executor_type = typename client::executor_type;
    -
    393 
    -
    394  explicit initiate_async_call(client* self) : self_(self) {}
    -
    395 
    -
    396  executor_type get_executor() const noexcept
    -
    397  {
    -
    398  return self_->get_executor();
    -
    399  }
    -
    400 
    -
    401  template <typename CallHandler, typename... Args>
    -
    402  void operator()(
    -
    403  CallHandler&& handler,
    -
    404  std::string_view name,
    -
    405  const std::tuple<Args...>& args,
    -
    406  std::optional<std::reference_wrapper<id_type>> opt_call_id) const
    -
    407  {
    -
    408  PACKIO_STATIC_ASSERT_TRAIT(CallHandler);
    -
    409  PACKIO_DEBUG("async_call: {}", name);
    +
    363  private:
    +
    364  client* self_;
    +
    365  };
    +
    366 
    +
    367  class initiate_async_call {
    +
    368  public:
    +
    369  using executor_type = typename client::executor_type;
    +
    370 
    +
    371  explicit initiate_async_call(client* self) : self_(self) {}
    +
    372 
    +
    373  executor_type get_executor() const noexcept
    +
    374  {
    +
    375  return self_->get_executor();
    +
    376  }
    +
    377 
    +
    378  template <typename CallHandler, typename ArgsTuple>
    +
    379  void operator()(
    +
    380  CallHandler&& handler,
    +
    381  std::string_view name,
    +
    382  ArgsTuple&& args,
    +
    383  std::optional<std::reference_wrapper<id_type>> opt_call_id) const
    +
    384  {
    +
    385  PACKIO_STATIC_ASSERT_TTRAIT(CallHandler, rpc_type);
    +
    386  PACKIO_DEBUG("async_call: {}", name);
    +
    387 
    +
    388  id_type call_id = self_->id_.fetch_add(1, std::memory_order_acq_rel);
    +
    389  if (opt_call_id) {
    +
    390  opt_call_id->get() = call_id;
    +
    391  }
    +
    392 
    +
    393  auto packer_buf = internal::to_unique_ptr(std::apply(
    +
    394  [&name, &call_id](auto&&... args) {
    +
    395  return rpc_type::serialize_request(
    +
    396  call_id, name, std::forward<decltype(args)>(args)...);
    +
    397  },
    +
    398  std::forward<ArgsTuple>(args)));
    +
    399 
    +
    400  net::dispatch(
    +
    401  self_->call_strand_,
    +
    402  [self = self_->shared_from_this(),
    +
    403  call_id,
    +
    404  handler = std::forward<CallHandler>(handler),
    +
    405  packer_buf = std::move(packer_buf)]() mutable {
    +
    406  // we must emplace the id and handler before sending data
    +
    407  // otherwise we might drop a fast response
    +
    408  assert(self->call_strand_.running_in_this_thread());
    +
    409  self->pending_.try_emplace(call_id, std::move(handler));
    410 
    -
    411  id_type call_id = self_->id_.fetch_add(1, std::memory_order_acq_rel);
    -
    412  if (opt_call_id) {
    -
    413  opt_call_id->get() = call_id;
    -
    414  }
    -
    415 
    -
    416  auto packer_buf = std::make_unique<Buffer>();
    -
    417  msgpack::pack(
    -
    418  *packer_buf,
    -
    419  std::forward_as_tuple(
    -
    420  static_cast<int>(msgpack_rpc_type::request),
    -
    421  call_id,
    -
    422  name,
    -
    423  args));
    -
    424 
    -
    425  net::dispatch(
    -
    426  self_->call_strand_,
    -
    427  [self = self_->shared_from_this(),
    -
    428  call_id,
    -
    429  handler = std::forward<CallHandler>(handler),
    -
    430  packer_buf = std::move(packer_buf)]() mutable {
    -
    431  // we must emplace the id and handler before sending data
    -
    432  // otherwise we might drop a fast response
    -
    433  assert(self->call_strand_.running_in_this_thread());
    -
    434  self->pending_.try_emplace(call_id, std::move(handler));
    -
    435 
    -
    436  // if we are not reading, start the read operation
    -
    437  if (!self->reading_) {
    -
    438  PACKIO_DEBUG("start reading");
    -
    439  self->async_read(std::make_unique<msgpack::unpacker>());
    -
    440  }
    +
    411  // if we are not reading, start the read operation
    +
    412  if (!self->reading_) {
    +
    413  PACKIO_DEBUG("start reading");
    +
    414  self->async_read(parser_type{});
    +
    415  }
    +
    416 
    +
    417  // send the request buffer
    +
    418  self->async_send(
    +
    419  std::move(packer_buf),
    +
    420  [self = std::move(self), call_id](
    +
    421  error_code ec, std::size_t length) mutable {
    +
    422  if (ec) {
    +
    423  PACKIO_WARN("write error: {}", ec.message());
    +
    424  self->async_call_handler(call_id, ec, {});
    +
    425  }
    +
    426  else {
    +
    427  PACKIO_TRACE("write: {}", length);
    +
    428  (void)length;
    +
    429  }
    +
    430  });
    +
    431  });
    +
    432  }
    +
    433 
    +
    434  private:
    +
    435  client* self_;
    +
    436  };
    +
    437 
    +
    438  socket_type socket_;
    +
    439  std::size_t buffer_reserve_size_{kDefaultBufferReserveSize};
    +
    440  std::atomic<uint64_t> id_{0};
    441 
    -
    442  // send the request buffer
    -
    443  self->async_send(
    -
    444  std::move(packer_buf),
    -
    445  [self = std::move(self), call_id](
    -
    446  error_code ec, std::size_t length) mutable {
    -
    447  if (ec) {
    -
    448  PACKIO_WARN("write error: {}", ec.message());
    -
    449  self->async_call_handler(
    -
    450  call_id,
    -
    451  internal::make_msgpack_object(ec.message()),
    -
    452  ec);
    -
    453  }
    -
    454  else {
    -
    455  PACKIO_TRACE("write: {}", length);
    -
    456  (void)length;
    -
    457  }
    -
    458  });
    -
    459  });
    -
    460  }
    +
    442  internal::manual_strand<executor_type> wstrand_;
    +
    443 
    +
    444  net::strand<executor_type> call_strand_;
    +
    445  Map<id_type, async_call_handler_type> pending_;
    +
    446  bool reading_{false};
    +
    447 };
    +
    448 
    +
    453 template <typename Rpc, typename Socket, template <class...> class Map = default_map>
    +
    454 auto make_client(Socket&& socket)
    +
    455 {
    +
    456  return std::make_shared<client<Rpc, Socket, Map>>(
    +
    457  std::forward<Socket>(socket));
    +
    458 }
    +
    459 
    +
    460 } // packio
    461 
    -
    462  private:
    -
    463  client* self_;
    -
    464  };
    -
    465 
    -
    466  socket_type socket_;
    -
    467  std::size_t buffer_reserve_size_{kDefaultBufferReserveSize};
    -
    468  std::atomic<id_type> id_{0};
    -
    469 
    -
    470  internal::manual_strand<executor_type> wstrand_;
    -
    471 
    -
    472  net::strand<executor_type> call_strand_;
    -
    473  Map<id_type, async_call_handler_type> pending_;
    -
    474  bool reading_{false};
    -
    475 };
    -
    476 
    -
    480 template <typename Socket, template <class...> class Map = std::map>
    -
    481 auto make_client(Socket&& socket)
    -
    482 {
    -
    483  return std::make_shared<client<Socket, Map>>(std::forward<Socket>(socket));
    -
    484 }
    -
    485 
    -
    486 } // packio
    -
    487 
    -
    488 #endif // PACKIO_CLIENT_H
    +
    462 #endif // PACKIO_CLIENT_H
-
The client class.
Definition: client.h:36
-
auto async_notify(std::string_view name, const std::tuple< Args... > &args, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
Send a notify request to the server with argument.
Definition: client.h:123
-
void set_buffer_reserve_size(std::size_t size) noexcept
Set the size reserved by the reception buffer.
Definition: client.h:63
-
@ cancelled
The operation has been cancelled.
-
static constexpr size_t kDefaultBufferReserveSize
The default size reserved by the reception buffer.
Definition: client.h:46
-
auto make_client(Socket &&socket)
Create a client from a socket.
Definition: client.h:481
- -
auto async_call(std::string_view name, const std::tuple< Args... > &args, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)
Call a remote procedure.
Definition: client.h:162
-
uint32_t id_type
Type used to store call IDs.
Definition: msgpack_rpc.h:16
-
@ call_error
An error happened during the call.
-
socket_type & socket() noexcept
Get the underlying socket.
Definition: client.h:58
-
void cancel()
Cancel all pending calls.
Definition: client.h:93
-
typename socket_type::protocol_type protocol_type
The protocol type.
Definition: client.h:40
-
executor_type get_executor()
Get the executor associated with the object.
Definition: client.h:74
-
auto async_notify(std::string_view name, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
Send a notify request to the server with no argument This is an overloaded member function,...
Definition: client.h:139
- -
@ success
Success.
-
std::size_t get_buffer_reserve_size() const noexcept
Get the size reserved by the reception buffer.
Definition: client.h:68
-
Definition: as.h:16
-
Socket socket_type
The socket type.
Definition: client.h:38
-
auto async_call(std::string_view name, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)
Call a remote procedure This is an overloaded member function, provided for convenience....
Definition: client.h:179
-
const socket_type & socket() const noexcept
Get the underlying socket, const.
Definition: client.h:60
-
client(socket_type socket)
The constructor.
Definition: client.h:50
-
void cancel(id_type id)
Cancel a pending call.
Definition: client.h:80
-
typename socket_type::executor_type executor_type
The executor type.
Definition: client.h:42
+
Socket socket_type
The socket type.
Definition: client.h:42
+
::packio::client< rpc, Socket, Map > client
The client for msgpack-RPC.
Definition: msgpack_rpc.h:29
+
The client class.
Definition: client.h:33
+
const socket_type & socket() const noexcept
Get the underlying socket, const.
Definition: client.h:65
+
typename socket_type::executor_type executor_type
The executor type.
Definition: client.h:46
+
void set_buffer_reserve_size(std::size_t size) noexcept
Set the size reserved by the reception buffer.
Definition: client.h:68
+
auto async_call(std::string_view name, ArgsTuple &&args, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)
Call a remote procedure.
Definition: client.h:153
+
typename rpc_type::id_type id_type
The call ID type.
Definition: client.h:38
+
typename socket_type::protocol_type protocol_type
The protocol type.
Definition: client.h:44
+
auto async_call(std::string_view name, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: client.h:172
+
std::size_t get_buffer_reserve_size() const noexcept
Get the size reserved by the reception buffer.
Definition: client.h:73
+
Definition: arg.h:14
+
socket_type & socket() noexcept
Get the underlying socket.
Definition: client.h:62
+
auto async_notify(std::string_view name, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: client.h:133
+
static constexpr size_t kDefaultBufferReserveSize
The default size reserved by the reception buffer.
Definition: client.h:50
+
Rpc rpc_type
The RPC protocol type.
Definition: client.h:36
+
void cancel(id_type id)
Cancel a pending call.
Definition: client.h:85
+
auto async_notify(std::string_view name, ArgsTuple &&args, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())
Send a notify request to the server with argument.
Definition: client.h:116
+
void cancel()
Cancel all pending calls.
Definition: client.h:96
+
typename rpc_type::response_type response_type
The response of a RPC call.
Definition: client.h:40
+
executor_type get_executor()
Get the executor associated with the object.
Definition: client.h:79
+
auto make_client(Socket &&socket)
Create a client from a socket.
Definition: client.h:454
+
client(socket_type socket)
The constructor.
Definition: client.h:54
diff --git a/docs/config_8h_source.html b/docs/config_8h_source.html index ec54c65..4d9bff6 100644 --- a/docs/config_8h_source.html +++ b/docs/config_8h_source.html @@ -78,60 +78,83 @@
5 #ifndef PACKIO_CONFIG_H
6 #define PACKIO_CONFIG_H
7 
-
8 #if defined(PACKIO_STANDALONE_ASIO)
-
9 #include <asio.hpp>
-
10 #else // defined(PACKIO_STANDALONE_ASIO)
-
11 #include <boost/asio.hpp>
-
12 #endif // defined(PACKIO_STANDALONE_ASIO)
-
13 
-
14 namespace packio {
+
8 #include <unordered_map>
+
9 
+
10 #if defined(PACKIO_STANDALONE_ASIO)
+
11 #include <asio.hpp>
+
12 #else // defined(PACKIO_STANDALONE_ASIO)
+
13 #include <boost/asio.hpp>
+
14 #endif // defined(PACKIO_STANDALONE_ASIO)
15 
-
16 #if defined(PACKIO_STANDALONE_ASIO)
-
17 namespace net = ::asio;
-
18 #else // defined(PACKIO_STANDALONE_ASIO)
-
19 namespace net = ::boost::asio;
-
20 #endif // defined(PACKIO_STANDALONE_ASIO)
-
21 
-
22 #if defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(ASIO_HAS_CO_AWAIT)
-
23 #define PACKIO_HAS_CO_AWAIT 1
-
24 #endif // defined(ASIO_HAS_CO_AWAIT) || defined(ASIO_HAS_CO_AWAIT)
-
25 
-
26 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) || defined(ASIO_HAS_LOCAL_SOCKETS)
-
27 #define PACKIO_HAS_LOCAL_SOCKETS 1
-
28 #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) || defined(ASIO_HAS_LOCAL_SOCKETS)
-
29 
-
30 #if defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN)
-
31 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) \
-
32  BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(e)
-
33 #elif defined(ASIO_DEFAULT_COMPLETION_TOKEN)
-
34 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) ASIO_DEFAULT_COMPLETION_TOKEN(e)
-
35 #else // defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN)
-
36 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e)
-
37 #endif // defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN)
-
38 
-
39 #if defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
-
40 #define PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \
-
41  BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
-
42 #elif defined(ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
-
43 #define PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \
-
44  ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
-
45 #else // defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
-
46 #define PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
-
47 #endif // defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
-
48 
-
49 #if defined(BOOST_ASIO_COMPLETION_TOKEN_FOR)
-
50 #define PACKIO_COMPLETION_TOKEN_FOR(s) BOOST_ASIO_COMPLETION_TOKEN_FOR(s)
-
51 #elif defined(ASIO_COMPLETION_TOKEN_FOR)
-
52 #define PACKIO_COMPLETION_TOKEN_FOR(s) ASIO_COMPLETION_TOKEN_FOR(s)
-
53 #else // defined(BOOST_ASIO_COMPLETION_TOKEN_FOR)
-
54 #define PACKIO_COMPLETION_TOKEN_FOR(s) typename
-
55 #endif // defined (BOOST_ASIO_COMPLETION_TOKEN_FOR)
-
56 
-
57 } // packio
-
58 
-
59 #endif // PACKIO_CONFIG_H
+
16 #define PACKIO_HAS_MSGPACK __has_include(<msgpack.hpp>)
+
17 #define PACKIO_HAS_NLOHMANN_JSON __has_include(<nlohmann/json.hpp>)
+
18 
+
19 namespace packio {
+
20 
+
21 #if defined(PACKIO_STANDALONE_ASIO)
+
22 namespace net = ::asio;
+
23 using error_code = std::error_code;
+
24 using system_error = std::system_error;
+
25 using error_category = std::error_category;
+
26 #else // defined(PACKIO_STANDALONE_ASIO)
+
27 namespace net = ::boost::asio;
+
28 using error_code = boost::system::error_code;
+
29 using system_error = boost::system::system_error;
+
30 using error_category = boost::system::error_category;
+
31 #endif // defined(PACKIO_STANDALONE_ASIO)
+
32 
+
33 #if defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(ASIO_HAS_CO_AWAIT) \
+
34  || defined(PACKIO_DOCUMENTATION)
+
35 #define PACKIO_HAS_CO_AWAIT 1
+
36 #endif
+
37 
+
38 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) || defined(ASIO_HAS_LOCAL_SOCKETS) \
+
39  || defined(PACKIO_DOCUMENTATION)
+
40 #define PACKIO_HAS_LOCAL_SOCKETS 1
+
41 #endif
+
42 
+
43 #if defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN)
+
44 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) \
+
45  BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(e)
+
46 #elif defined(ASIO_DEFAULT_COMPLETION_TOKEN)
+
47 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) ASIO_DEFAULT_COMPLETION_TOKEN(e)
+
48 #elif defined(PACKIO_DOCUMENTATION)
+
49 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) \
+
50  = typename net::default_completion_token<e>::type()
+
51 #else
+
52 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e)
+
53 #endif // defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN)
+
54 
+
55 #if defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
+
56 #define PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \
+
57  BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
+
58 #elif defined(ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
+
59 #define PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \
+
60  ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
+
61 #elif defined(PACKIO_DOCUMENTATION)
+
62 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) \
+
63  = typename net::default_completion_token<e>::type
+
64 #else
+
65 #define PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
+
66 #endif // defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
+
67 
+
68 #if defined(BOOST_ASIO_COMPLETION_TOKEN_FOR)
+
69 #define PACKIO_COMPLETION_TOKEN_FOR(s) BOOST_ASIO_COMPLETION_TOKEN_FOR(s)
+
70 #elif defined(ASIO_COMPLETION_TOKEN_FOR)
+
71 #define PACKIO_COMPLETION_TOKEN_FOR(s) ASIO_COMPLETION_TOKEN_FOR(s)
+
72 #else
+
73 #define PACKIO_COMPLETION_TOKEN_FOR(s) typename
+
74 #endif // defined (BOOST_ASIO_COMPLETION_TOKEN_FOR)
+
75 
+
76 template <typename... Args>
+
77 using default_map = std::unordered_map<Args...>;
+
78 using default_mutex = std::mutex;
+
79 
+
80 } // packio
+
81 
+
82 #endif // PACKIO_CONFIG_H
-
Definition: as.h:16
+
Definition: arg.h:14
diff --git a/docs/dir_50fcca1c17f3c78147804e11bbf6347a.html b/docs/dir_50fcca1c17f3c78147804e11bbf6347a.html new file mode 100644 index 0000000..0844495 --- /dev/null +++ b/docs/dir_50fcca1c17f3c78147804e11bbf6347a.html @@ -0,0 +1,84 @@ + + + + + + + + + packio: packio/nlohmann_json Directory Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
nlohmann_json Directory Reference
+
+
+ + + + +

+Files

file  nlohmann_json.h [code]
 
+
+ + + + \ No newline at end of file diff --git a/docs/dir_7f2d0a2a0928023e758bb1e0e178d043.html b/docs/dir_7f2d0a2a0928023e758bb1e0e178d043.html index 973e938..0367621 100644 --- a/docs/dir_7f2d0a2a0928023e758bb1e0e178d043.html +++ b/docs/dir_7f2d0a2a0928023e758bb1e0e178d043.html @@ -77,14 +77,12 @@

- + - - diff --git a/docs/dir_8134e42d2d88ca9108b35520ddf78bb9.html b/docs/dir_8134e42d2d88ca9108b35520ddf78bb9.html new file mode 100644 index 0000000..9b8fc3b --- /dev/null +++ b/docs/dir_8134e42d2d88ca9108b35520ddf78bb9.html @@ -0,0 +1,84 @@ + + + + + + + + + packio: packio/msgpack Directory Reference + + + + + + + + + +
+ +
+

Files

file  as.h [code]
file  arg.h [code]
 
file  client.h [code]
 
file  dispatcher.h [code]
 
file  error_code.h [code]
 
file  handler.h [code]
 
file  packio.h [code]
+ + + + + +
+
packio +
+
+ + + + + + + + +
+
+ + +
+ +
+ + + +
+
+
msgpack Directory Reference
+
+
+ + + + +

+Files

file  msgpack.h [code]
 
+
+ + + + \ No newline at end of file diff --git a/docs/dir_8b84d8fff14d06fd8cd883713d64b14f.html b/docs/dir_8b84d8fff14d06fd8cd883713d64b14f.html new file mode 100644 index 0000000..832f276 --- /dev/null +++ b/docs/dir_8b84d8fff14d06fd8cd883713d64b14f.html @@ -0,0 +1,84 @@ + + + + + + + + + packio: packio/msgpack_rpc Directory Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
msgpack_rpc Directory Reference
+
+
+ + + + +

+Files

file  msgpack_rpc.h [code]
 
+
+ + + + \ No newline at end of file diff --git a/docs/dir_8bc3569cffbe0d399ceab2d58a606072.html b/docs/dir_8bc3569cffbe0d399ceab2d58a606072.html new file mode 100644 index 0000000..3b24396 --- /dev/null +++ b/docs/dir_8bc3569cffbe0d399ceab2d58a606072.html @@ -0,0 +1,84 @@ + + + + + + + + + packio: packio/nl_json_rpc Directory Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
nl_json_rpc Directory Reference
+
+
+ + + + +

+Files

file  nl_json_rpc.h [code]
 
+
+ + + + \ No newline at end of file diff --git a/docs/dir_d7eb85775561ce766e8a532a122e1c82.html b/docs/dir_d7eb85775561ce766e8a532a122e1c82.html index fe7f6ad..f27b954 100644 --- a/docs/dir_d7eb85775561ce766e8a532a122e1c82.html +++ b/docs/dir_d7eb85775561ce766e8a532a122e1c82.html @@ -71,12 +71,6 @@
internal Directory Reference
- - - - -

-Files

file  msgpack_rpc.h [code]
 
diff --git a/docs/dispatcher_8h.html b/docs/dispatcher_8h.html index 38ea067..5b4b421 100644 --- a/docs/dispatcher_8h.html +++ b/docs/dispatcher_8h.html @@ -80,11 +80,10 @@ #include <optional>
#include <string_view>
#include <tuple>
-#include <msgpack.hpp>
-#include "error_code.h"
#include "handler.h"
#include "internal/config.h"
-#include "internal/unique_function.h"
+#include "internal/movable_function.h"
+#include "internal/rpc.h"
#include "internal/utils.h"
#include "traits.h"
@@ -92,7 +91,7 @@ - +

Classes

class  packio::dispatcher< Map, Lockable >
class  packio::dispatcher< Rpc, Map, Lockable >
 The dispatcher class, used to store and dispatch procedures. More...
 
diff --git a/docs/dispatcher_8h_source.html b/docs/dispatcher_8h_source.html index b540c42..3d0a455 100644 --- a/docs/dispatcher_8h_source.html +++ b/docs/dispatcher_8h_source.html @@ -86,254 +86,317 @@
15 #include <string_view>
16 #include <tuple>
17 
-
18 #include <msgpack.hpp>
-
19 
-
20 #include "error_code.h"
-
21 #include "handler.h"
-
22 #include "internal/config.h"
-
23 #include "internal/unique_function.h"
-
24 #include "internal/utils.h"
-
25 #include "traits.h"
+
18 #include "handler.h"
+
19 #include "internal/config.h"
+
20 #include "internal/movable_function.h"
+
21 #include "internal/rpc.h"
+
22 #include "internal/utils.h"
+
23 #include "traits.h"
+
24 
+
25 namespace packio {
26 
-
27 namespace packio {
-
28 
-
32 template <template <class...> class Map = std::unordered_map, typename Lockable = std::mutex>
-
33 class dispatcher {
-
34 public:
-
36  using mutex_type = Lockable;
-
38  using function_type =
-
39  internal::unique_function<void(completion_handler, const msgpack::object&)>;
-
41  using function_ptr_type = std::shared_ptr<function_type>;
-
42 
-
46  template <typename SyncProcedure>
-
47  bool add(std::string_view name, SyncProcedure&& fct)
-
48  {
-
49  PACKIO_STATIC_ASSERT_TRAIT(SyncProcedure);
-
50  std::unique_lock lock{map_mutex_};
-
51  return function_map_
-
52  .emplace(name, wrap_sync(std::forward<SyncProcedure>(fct)))
-
53  .second;
-
54  }
-
55 
-
59  template <typename AsyncProcedure>
-
60  bool add_async(std::string_view name, AsyncProcedure&& fct)
-
61  {
-
62  PACKIO_STATIC_ASSERT_TRAIT(AsyncProcedure);
-
63  std::unique_lock lock{map_mutex_};
-
64  return function_map_
-
65  .emplace(name, wrap_async(std::forward<AsyncProcedure>(fct)))
-
66  .second;
-
67  }
-
68 
-
69 #if defined(PACKIO_HAS_CO_AWAIT) || defined(PACKIO_DOCUMENTATION)
-
70  template <typename Executor, typename CoroProcedure>
-
75  bool add_coro(std::string_view name, const Executor& executor, CoroProcedure&& coro)
-
76  {
-
77  PACKIO_STATIC_ASSERT_TRAIT(CoroProcedure);
-
78  std::unique_lock lock{map_mutex_};
-
79  return function_map_
-
80  .emplace(name, wrap_coro(executor, std::forward<CoroProcedure>(coro)))
-
81  .second;
-
82  }
-
83 
-
86  template <typename ExecutionContext, typename CoroProcedure>
-
87  bool add_coro(std::string_view name, ExecutionContext& ctx, CoroProcedure&& coro)
-
88  {
-
89  return add_coro(
-
90  name, ctx.get_executor(), std::forward<CoroProcedure>(coro));
-
91  }
-
92 #endif // defined(PACKIO_HAS_CO_AWAIT) || defined(PACKIO_DOCUMENTATION)
-
93 
-
97  bool remove(const std::string& name)
-
98  {
-
99  std::unique_lock lock{map_mutex_};
-
100  return function_map_.erase(name);
-
101  }
-
102 
-
106  bool has(const std::string& name) const
-
107  {
-
108  std::unique_lock lock{map_mutex_};
-
109  return function_map_.find(name) != function_map_.end();
-
110  }
-
111 
-
114  size_t clear()
-
115  {
-
116  std::unique_lock lock{map_mutex_};
-
117  size_t size = function_map_.size();
-
118  function_map_.clear();
-
119  return size;
-
120  }
-
121 
-
124  std::vector<std::string> known() const
-
125  {
-
126  std::unique_lock lock{map_mutex_};
-
127  std::vector<std::string> names;
-
128  names.reserve(function_map_.size());
-
129  std::transform(
-
130  function_map_.begin(),
-
131  function_map_.end(),
-
132  std::back_inserter(names),
-
133  [](const typename decltype(function_map_)::value_type& pair) {
-
134  return pair.first;
-
135  });
-
136  return names;
+
31 template <typename Rpc, template <class...> class Map = default_map, typename Lockable = default_mutex>
+
32 class dispatcher {
+
33 public:
+
35  using rpc_type = Rpc;
+
37  using mutex_type = Lockable;
+
39  using args_type = decltype(typename rpc_type::request_type{}.args);
+
41  using function_type = internal::movable_function<
+ +
44  using function_ptr_type = std::shared_ptr<function_type>;
+
45 
+
50  template <
+
51  typename SyncProcedure,
+
52  std::size_t N = internal::func_traits<SyncProcedure>::args_count>
+
53  bool add(
+
54  std::string_view name,
+
55  const std::array<std::string, N>& arguments_names,
+
56  SyncProcedure&& fct)
+
57  {
+
58  PACKIO_STATIC_ASSERT_TRAIT(SyncProcedure);
+
59  std::unique_lock lock{map_mutex_};
+
60  return function_map_
+
61  .emplace(
+
62  name,
+
63  std::make_shared<function_type>(wrap_sync(
+
64  std::forward<SyncProcedure>(fct), arguments_names)))
+
65  .second;
+
66  }
+
67 
+
69  template <typename SyncProcedure>
+
70  bool add(std::string_view name, SyncProcedure&& fct)
+
71  {
+
72  return add<SyncProcedure, 0>(name, {}, std::forward<SyncProcedure>(fct));
+
73  }
+
74 
+
79  template <
+
80  typename AsyncProcedure,
+
81  std::size_t N = internal::func_traits<AsyncProcedure>::args_count - 1>
+
82  bool add_async(
+
83  std::string_view name,
+
84  const std::array<std::string, N>& arguments_names,
+
85  AsyncProcedure&& fct)
+
86  {
+
87  PACKIO_STATIC_ASSERT_TTRAIT(AsyncProcedure, rpc_type);
+
88  std::unique_lock lock{map_mutex_};
+
89  return function_map_
+
90  .emplace(
+
91  name,
+
92  std::make_shared<function_type>(wrap_async(
+
93  std::forward<AsyncProcedure>(fct), arguments_names)))
+
94  .second;
+
95  }
+
96 
+
98  template <typename AsyncProcedure>
+
99  bool add_async(std::string_view name, AsyncProcedure&& fct)
+
100  {
+
101  return add_async<AsyncProcedure, 0>(
+
102  name, {}, std::forward<AsyncProcedure>(fct));
+
103  }
+
104 
+
105 #if defined(PACKIO_HAS_CO_AWAIT)
+
106  template <
+
112  typename Executor,
+
113  typename CoroProcedure,
+
114  std::size_t N = internal::func_traits<CoroProcedure>::args_count>
+
115  bool add_coro(
+
116  std::string_view name,
+
117  const Executor& executor,
+
118  const std::array<std::string, N>& arguments_names,
+
119  CoroProcedure&& coro)
+
120  {
+
121  PACKIO_STATIC_ASSERT_TRAIT(CoroProcedure);
+
122  std::unique_lock lock{map_mutex_};
+
123  return function_map_
+
124  .emplace(
+
125  name,
+
126  std::make_shared<function_type>(wrap_coro(
+
127  executor, std::forward<CoroProcedure>(coro), arguments_names)))
+
128  .second;
+
129  }
+
130 
+
132  template <typename Executor, typename CoroProcedure>
+
133  bool add_coro(std::string_view name, const Executor& executor, CoroProcedure&& coro)
+
134  {
+
135  return add_coro<Executor, CoroProcedure, 0>(
+
136  name, executor, {}, std::forward<CoroProcedure>(coro));
137  }
138 
-
139  function_ptr_type get(const std::string& name) const
-
140  {
-
141  std::unique_lock lock{map_mutex_};
-
142  auto it = function_map_.find(name);
-
143  if (it == function_map_.end()) {
-
144  return {};
-
145  }
-
146  else {
-
147  return it->second;
-
148  }
-
149  }
-
150 
-
151 private:
-
152  using map_type = Map<std::string, function_ptr_type>;
-
153 
-
154  template <typename F>
-
155  function_ptr_type wrap_sync(F&& fct)
-
156  {
-
157  using value_args =
-
158  internal::decay_tuple_t<typename internal::func_traits<F>::args_type>;
-
159  using result_type = typename internal::func_traits<F>::result_type;
-
160 
-
161  return std::make_shared<function_type>(
-
162  [fct = std::forward<F>(fct)](
-
163  completion_handler handler, const msgpack::object& args) mutable {
-
164  if (args.via.array.size != std::tuple_size_v<value_args>) {
-
165  // keep this check otherwise msgpack unpacker
-
166  // may silently drop arguments
-
167  PACKIO_DEBUG("incompatible argument count");
-
168  handler.set_error("Incompatible arguments");
-
169  return;
-
170  }
-
171 
-
172  try {
-
173  if constexpr (std::is_void_v<result_type>) {
-
174  std::apply(fct, args.as<value_args>());
-
175  handler();
-
176  }
-
177  else {
-
178  handler(std::apply(fct, args.as<value_args>()));
-
179  }
-
180  }
-
181  catch (msgpack::type_error&) {
-
182  PACKIO_DEBUG("incompatible arguments");
-
183  handler.set_error("Incompatible arguments");
-
184  }
-
185  });
-
186  }
-
187 
-
188  template <typename F>
-
189  function_ptr_type wrap_async(F&& fct)
-
190  {
-
191  using args = typename internal::func_traits<F>::args_type;
-
192  using value_args = internal::decay_tuple_t<internal::shift_tuple_t<args>>;
+
140  template <
+
141  typename ExecutionContext,
+
142  typename CoroProcedure,
+
143  std::size_t N = internal::func_traits<CoroProcedure>::args_count>
+
144  bool add_coro(
+
145  std::string_view name,
+
146  ExecutionContext& ctx,
+
147  const std::array<std::string, N>& arguments_names,
+
148  CoroProcedure&& coro)
+
149  {
+
150  return add_coro<decltype(ctx.get_executor()), CoroProcedure, N>(
+
151  name,
+
152  ctx.get_executor(),
+
153  arguments_names,
+
154  std::forward<CoroProcedure>(coro));
+
155  }
+
156 
+
158  template <typename ExecutionContext, typename CoroProcedure>
+
159  bool add_coro(std::string_view name, ExecutionContext& ctx, CoroProcedure&& coro)
+
160  {
+
161  return add_coro<ExecutionContext, CoroProcedure, 0>(
+
162  name, ctx, {}, std::forward<CoroProcedure>(coro));
+
163  }
+
164 #endif // defined(PACKIO_HAS_CO_AWAIT)
+
165 
+
169  bool remove(const std::string& name)
+
170  {
+
171  std::unique_lock lock{map_mutex_};
+
172  return function_map_.erase(name);
+
173  }
+
174 
+
178  bool has(const std::string& name) const
+
179  {
+
180  std::unique_lock lock{map_mutex_};
+
181  return function_map_.find(name) != function_map_.end();
+
182  }
+
183 
+
186  size_t clear()
+
187  {
+
188  std::unique_lock lock{map_mutex_};
+
189  size_t size = function_map_.size();
+
190  function_map_.clear();
+
191  return size;
+
192  }
193 
-
194  return std::make_shared<function_type>(
-
195  [fct = std::forward<F>(fct)](
-
196  completion_handler handler, const msgpack::object& args) mutable {
-
197  if (args.via.array.size != std::tuple_size_v<value_args>) {
-
198  // keep this check otherwise msgpack unpacker
-
199  // may silently drop arguments
-
200  PACKIO_DEBUG("incompatible argument count");
-
201  handler.set_error("Incompatible arguments");
-
202  return;
-
203  }
-
204 
-
205  try {
-
206  std::apply(
-
207  [&](auto&&... args) {
-
208  fct(std::move(handler),
-
209  std::forward<decltype(args)>(args)...);
-
210  },
-
211  args.as<value_args>());
-
212  }
-
213  catch (msgpack::type_error&) {
-
214  PACKIO_DEBUG("incompatible arguments");
-
215  handler.set_error("Incompatible arguments");
-
216  }
-
217  });
-
218  }
-
219 
-
220 #if defined(PACKIO_HAS_CO_AWAIT) || defined(PACKIO_DOCUMENTATION)
-
221  template <typename E, typename C>
-
222  function_ptr_type wrap_coro(const E& executor, C&& coro)
-
223  {
-
224  using value_args =
-
225  internal::decay_tuple_t<typename internal::func_traits<C>::args_type>;
-
226  using result_type =
-
227  typename internal::func_traits<C>::result_type::value_type;
-
228 
-
229  return std::make_shared<function_type>(
-
230  [executor, coro = std::forward<C>(coro)](
-
231  completion_handler handler, const msgpack::object& args) mutable {
-
232  if (args.via.array.size != std::tuple_size_v<value_args>) {
-
233  // keep this check otherwise msgpack unpacker
-
234  // may silently drop arguments
-
235  PACKIO_DEBUG("incompatible argument count");
-
236  handler.set_error("Incompatible arguments");
-
237  return;
-
238  }
-
239 
-
240  net::co_spawn(
-
241  executor,
-
242  [args = args.as<value_args>(),
-
243  handler = std::move(handler),
-
244  coro = std::forward<C>(
-
245  coro)]() mutable -> net::awaitable<void> {
-
246  try {
-
247  if constexpr (std::is_void_v<result_type>) {
-
248  co_await std::apply(coro, args);
-
249  handler();
-
250  }
-
251  else {
-
252  handler(co_await std::apply(coro, args));
-
253  }
-
254  }
-
255  catch (msgpack::type_error&) {
-
256  PACKIO_DEBUG("incompatible arguments");
-
257  handler.set_error("Incompatible arguments");
-
258  }
-
259  },
-
260  [](std::exception_ptr exc) {
-
261  if (exc) {
-
262  std::rethrow_exception(exc);
-
263  }
-
264  });
-
265  });
-
266  }
-
267 #endif // defined(PACKIO_HAS_CO_AWAIT) || defined(PACKIO_DOCUMENTATION)
-
268 
-
269  mutable mutex_type map_mutex_;
-
270  map_type function_map_;
-
271 };
-
272 
-
273 } // packio
-
274 
-
275 #endif // PACKIO_DISPATCHER_H
+
196  std::vector<std::string> known() const
+
197  {
+
198  std::unique_lock lock{map_mutex_};
+
199  std::vector<std::string> names;
+
200  names.reserve(function_map_.size());
+
201  std::transform(
+
202  function_map_.begin(),
+
203  function_map_.end(),
+
204  std::back_inserter(names),
+
205  [](const typename decltype(function_map_)::value_type& pair) {
+
206  return pair.first;
+
207  });
+
208  return names;
+
209  }
+
210 
+
211  function_ptr_type get(const std::string& name) const
+
212  {
+
213  std::unique_lock lock{map_mutex_};
+
214  auto it = function_map_.find(name);
+
215  if (it == function_map_.end()) {
+
216  return {};
+
217  }
+
218  else {
+
219  return it->second;
+
220  }
+
221  }
+
222 
+
223 private:
+
224  using function_map_type = Map<std::string, function_ptr_type>;
+
225 
+
226  template <typename TArgs, std::size_t NNamedArgs>
+
227  static void static_assert_arguments_name_and_count()
+
228  {
+
229  static_assert(
+
230  NNamedArgs == 0 || std::tuple_size_v<TArgs> == NNamedArgs,
+
231  "incompatible arguments count and names");
+
232  }
+
233 
+
234  template <typename F, std::size_t N>
+
235  auto wrap_sync(F&& fct, const std::array<std::string, N>& args_names)
+
236  {
+
237  using value_args =
+
238  internal::decay_tuple_t<typename internal::func_traits<F>::args_type>;
+
239  using result_type = typename internal::func_traits<F>::result_type;
+
240  static_assert_arguments_name_and_count<value_args, N>();
+
241 
+
242  return
+
243  [fct = std::forward<F>(fct), args_names](
+
244  completion_handler<rpc_type> handler, args_type&& args) mutable {
+
245  auto typed_args = rpc_type::template extract_args<value_args>(
+
246  std::move(args), args_names);
+
247  if (!typed_args) {
+
248  PACKIO_DEBUG("incompatible arguments");
+
249  handler.set_error("Incompatible arguments");
+
250  return;
+
251  }
+
252 
+
253  if constexpr (std::is_void_v<result_type>) {
+
254  std::apply(fct, std::move(*typed_args));
+
255  handler();
+
256  }
+
257  else {
+
258  handler(std::apply(fct, std::move(*typed_args)));
+
259  }
+
260  };
+
261  }
+
262 
+
263  template <typename F, std::size_t N>
+
264  auto wrap_async(F&& fct, const std::array<std::string, N>& args_names)
+
265  {
+
266  using args = typename internal::func_traits<F>::args_type;
+
267  using value_args = internal::decay_tuple_t<internal::shift_tuple_t<args>>;
+
268  static_assert_arguments_name_and_count<value_args, N>();
+
269 
+
270  return
+
271  [fct = std::forward<F>(fct), args_names](
+
272  completion_handler<rpc_type> handler, args_type&& args) mutable {
+
273  auto typed_args = rpc_type::template extract_args<value_args>(
+
274  std::move(args), args_names);
+
275  if (!typed_args) {
+
276  PACKIO_DEBUG("incompatible arguments");
+
277  handler.set_error("Incompatible arguments");
+
278  return;
+
279  }
+
280 
+
281  std::apply(
+
282  [&](auto&&... args) {
+
283  fct(std::move(handler),
+
284  std::forward<decltype(args)>(args)...);
+
285  },
+
286  std::move(*typed_args));
+
287  };
+
288  }
+
289 
+
290 #if defined(PACKIO_HAS_CO_AWAIT)
+
291  template <typename E, typename C, std::size_t N>
+
292  auto wrap_coro(
+
293  const E& executor,
+
294  C&& coro,
+
295  const std::array<std::string, N>& args_names)
+
296  {
+
297  using value_args =
+
298  internal::decay_tuple_t<typename internal::func_traits<C>::args_type>;
+
299  using result_type =
+
300  typename internal::func_traits<C>::result_type::value_type;
+
301  static_assert_arguments_name_and_count<value_args, N>();
+
302 
+
303  return [executor, coro = std::forward<C>(coro), args_names](
+
304  completion_handler<rpc_type> handler,
+
305  args_type&& args) mutable {
+
306  auto typed_args = rpc_type::template extract_args<value_args>(
+
307  std::move(args), args_names);
+
308  if (!typed_args) {
+
309  PACKIO_DEBUG("incompatible arguments");
+
310  handler.set_error("Incompatible arguments");
+
311  return;
+
312  }
+
313 
+
314  net::co_spawn(
+
315  executor,
+
316  [typed_args = std::move(*typed_args),
+
317  handler = std::move(handler),
+
318  coro = std::forward<C>(coro)]() mutable -> net::awaitable<void> {
+
319  if constexpr (std::is_void_v<result_type>) {
+
320  co_await std::apply(coro, std::move(typed_args));
+
321  handler();
+
322  }
+
323  else {
+
324  handler(co_await std::apply(coro, std::move(typed_args)));
+
325  }
+
326  },
+
327  [](std::exception_ptr exc) {
+
328  if (exc) {
+
329  std::rethrow_exception(exc);
+
330  }
+
331  });
+
332  };
+
333  }
+
334 #endif // defined(PACKIO_HAS_CO_AWAIT)
+
335 
+
336  mutable mutex_type map_mutex_;
+
337  function_map_type function_map_;
+
338 };
+
339 
+
340 } // packio
+
341 
+
342 #endif // PACKIO_DISPATCHER_H
-
std::shared_ptr< function_type > function_ptr_type
A shared pointer to function_type.
Definition: dispatcher.h:41
-
bool has(const std::string &name) const
Check if a procedure is registered.
Definition: dispatcher.h:106
+
internal::movable_function< void(completion_handler< rpc_type >, args_type &&args)> function_type
The type of function stored in the dispatcher.
Definition: dispatcher.h:42
+
bool has(const std::string &name) const
Check if a procedure is registered.
Definition: dispatcher.h:178
+
Rpc rpc_type
The RPC protocol type.
Definition: dispatcher.h:35
-
std::vector< std::string > known() const
Get the name of all known procedures.
Definition: dispatcher.h:124
-
The dispatcher class, used to store and dispatch procedures.
Definition: dispatcher.h:33
+
bool add_coro(std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: dispatcher.h:159
+
The dispatcher class, used to store and dispatch procedures.
Definition: dispatcher.h:32
The completion_handler class.
Definition: handler.h:27
- -
bool add_coro(std::string_view name, const Executor &executor, CoroProcedure &&coro)
Add a coroutine to the dispatcher.
Definition: dispatcher.h:75
-
Definition: as.h:16
-
bool add_coro(std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)
Add a coroutine to the dispatcher This is an overloaded member function, provided for convenience....
Definition: dispatcher.h:87
-
size_t clear()
Remove all procedures.
Definition: dispatcher.h:114
-
bool remove(const std::string &name)
Remove a procedure from the dispatcher.
Definition: dispatcher.h:97
-
bool add(std::string_view name, SyncProcedure &&fct)
Add a synchronous procedure to the dispatcher.
Definition: dispatcher.h:47
-
internal::unique_function< void(completion_handler, const msgpack::object &)> function_type
The type of function stored in the dispatcher.
Definition: dispatcher.h:39
-
Lockable mutex_type
The mutex type used to protect the procedure map.
Definition: dispatcher.h:36
+
bool add(std::string_view name, const std::array< std::string, N > &arguments_names, SyncProcedure &&fct)
Add a synchronous procedure to the dispatcher.
Definition: dispatcher.h:53
+
bool add_coro(std::string_view name, ExecutionContext &ctx, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: dispatcher.h:144
+
bool add(std::string_view name, SyncProcedure &&fct)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: dispatcher.h:70
+
std::shared_ptr< function_type > function_ptr_type
A shared pointer to function_type.
Definition: dispatcher.h:44
+
Definition: arg.h:14
+
bool add_async(std::string_view name, AsyncProcedure &&fct)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: dispatcher.h:99
+
bool add_coro(std::string_view name, const Executor &executor, CoroProcedure &&coro)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: dispatcher.h:133
+
bool add_coro(std::string_view name, const Executor &executor, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)
Add a coroutine to the dispatcher.
Definition: dispatcher.h:115
+
size_t clear()
Remove all procedures.
Definition: dispatcher.h:186
+
bool remove(const std::string &name)
Remove a procedure from the dispatcher.
Definition: dispatcher.h:169
+
decltype(typename rpc_type::request_type{}.args) args_type
The type of the arguments used by the RPC protocol.
Definition: dispatcher.h:39
+
Lockable mutex_type
The mutex type used to protect the procedure map.
Definition: dispatcher.h:37
-
bool add_async(std::string_view name, AsyncProcedure &&fct)
Add an asynchronous procedure to the dispatcher.
Definition: dispatcher.h:60
+
bool add_async(std::string_view name, const std::array< std::string, N > &arguments_names, AsyncProcedure &&fct)
Add an asynchronous procedure to the dispatcher.
Definition: dispatcher.h:82
+
std::vector< std::string > known() const
Get the name of all known procedures.
Definition: dispatcher.h:196
diff --git a/docs/files.html b/docs/files.html index 9df8842..afbb458 100644 --- a/docs/files.html +++ b/docs/files.html @@ -74,18 +74,24 @@ - - + + - - - - - - - - - + + + + + + + + + + + + + + +
 config.h
 log.h
 manual_strand.h
 msgpack_rpc.h
 unique_function.h
 movable_function.h
 rpc.h
 utils.h
 as.h
 client.h
 dispatcher.h
 error_code.h
 handler.h
 packio.h
 server.h
 server_session.h
 traits.h
  msgpack_rpc
 msgpack_rpc.h
 rpc.h
  nl_json_rpc
 incremental_buffers.h
 nl_json_rpc.h
 rpc.h
 arg.h
 client.h
 dispatcher.h
 handler.h
 packio.h
 server.h
 server_session.h
 traits.h
diff --git a/docs/functions.html b/docs/functions.html index 521aab8..f53f04d 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -67,176 +67,222 @@

- a -

- c -

- d -

- e -

- f -

- g -

- h -

+ + +

- i -

- k -

- m -

+ + +

- n -

- o -

- p -

- r -

- s -

+ + +

- z -

- ~ -

diff --git a/docs/functions_func.html b/docs/functions_func.html index 866373b..9f027dc 100644 --- a/docs/functions_func.html +++ b/docs/functions_func.html @@ -67,126 +67,126 @@

- a -

- c -

- d -

- g -

- h -

- k -

- o -

- r -

- s -

- ~ -

diff --git a/docs/functions_type.html b/docs/functions_type.html index cbedfc5..7235d0c 100644 --- a/docs/functions_type.html +++ b/docs/functions_type.html @@ -65,34 +65,64 @@
 
diff --git a/docs/functions_vars.html b/docs/functions_vars.html index 0034fbf..eb81602 100644 --- a/docs/functions_vars.html +++ b/docs/functions_vars.html @@ -65,8 +65,12 @@ diff --git a/docs/handler_8h.html b/docs/handler_8h.html index 2d9431a..9ee672a 100644 --- a/docs/handler_8h.html +++ b/docs/handler_8h.html @@ -75,16 +75,15 @@
#include <functional>
-#include <msgpack.hpp>
-#include "error_code.h"
#include "internal/config.h"
+#include "internal/rpc.h"
#include "internal/utils.h"

Go to the source code of this file.

- +

Classes

class  packio::completion_handler
class  packio::completion_handler< Rpc >
 The completion_handler class. More...
 
diff --git a/docs/handler_8h_source.html b/docs/handler_8h_source.html index b6e7886..b25b36c 100644 --- a/docs/handler_8h_source.html +++ b/docs/handler_8h_source.html @@ -81,105 +81,105 @@
10 
11 #include <functional>
12 
-
13 #include <msgpack.hpp>
-
14 
-
15 #include "error_code.h"
-
16 #include "internal/config.h"
-
17 #include "internal/utils.h"
+
13 #include "internal/config.h"
+
14 #include "internal/rpc.h"
+
15 #include "internal/utils.h"
+
16 
+
17 namespace packio {
18 
-
19 namespace packio {
-
20 
+
26 template <typename Rpc>
28 public:
-
29  using function_type = std::function<void(error_code, msgpack::object_handle)>;
-
30 
-
31  template <typename F>
-
32  completion_handler(F&& handler) : handler_{std::forward<F>(handler)}
-
33  {
-
34  }
-
35 
- -
38  {
-
39  if (handler_) {
-
40  set_error("Call finished with no result");
-
41  }
-
42  }
-
43 
-
44  completion_handler(const completion_handler&) = delete;
-
45  completion_handler& operator=(const completion_handler&) = delete;
-
46 
- -
49  : handler_{std::move(other.handler_)}
-
50  {
-
51  other.handler_ = nullptr;
-
52  }
-
53 
- -
56  {
-
57  if (handler_) {
-
58  set_error("Call finished with no result");
-
59  }
-
60  handler_ = std::move(other.handler_);
-
61  other.handler_ = nullptr;
-
62  return *this;
-
63  }
-
64 
-
67  template <typename T>
-
68  void set_value(T&& return_value)
-
69  {
-
70  complete(
- -
72  internal::make_msgpack_object(std::forward<T>(return_value)));
-
73  }
-
74 
-
77  void set_value() { complete(error::success, {}); }
-
78 
-
81  template <typename T>
-
82  void set_error(T&& error_value)
-
83  {
-
84  complete(
- -
86  internal::make_msgpack_object(std::forward<T>(error_value)));
+
29  using id_type = typename Rpc::id_type;
+
30  using response_buffer_type = decltype(
+
31  Rpc::serialize_response(std::declval<id_type>()));
+
32  using function_type = std::function<void(response_buffer_type&&)>;
+
33 
+
34  template <typename F>
+
35  completion_handler(const id_type& id, F&& handler)
+
36  : id_(id), handler_(std::forward<F>(handler))
+
37  {
+
38  }
+
39 
+ +
42  {
+
43  if (handler_) {
+
44  set_error("Call finished with no result");
+
45  }
+
46  }
+
47 
+
48  completion_handler(const completion_handler&) = delete;
+
49  completion_handler& operator=(const completion_handler&) = delete;
+
50 
+ +
53  : id_(other.id_), handler_(std::move(other.handler_))
+
54  {
+
55  other.handler_ = nullptr;
+
56  }
+
57 
+ +
60  {
+
61  if (handler_) {
+
62  set_error("Call finished with no result");
+
63  }
+
64  id_ = other.id_;
+
65  handler_ = std::move(other.handler_);
+
66  other.handler_ = nullptr;
+
67  return *this;
+
68  }
+
69 
+
72  template <typename T>
+
73  void set_value(T&& return_value)
+
74  {
+
75  complete(Rpc::serialize_response(id_, std::forward<T>(return_value)));
+
76  }
+
77 
+
79  void set_value() { complete(Rpc::serialize_response(id_)); }
+
80 
+
83  template <typename T>
+
84  void set_error(T&& error_value)
+
85  {
+
86  complete(Rpc::serialize_error_response(id_, std::forward<T>(error_value)));
87  }
88 
-
91  void set_error() { complete(error::error_during_call, {}); }
-
92 
-
94  template <typename T>
-
95  void operator()(T&& return_value)
-
96  {
-
97  set_value(std::forward<T>(return_value));
-
98  }
-
99 
-
101  void operator()() { set_value(); }
-
102 
-
103 private:
-
104  void complete(error err, msgpack::object_handle result)
-
105  {
-
106  handler_(make_error_code(err), std::move(result));
-
107  handler_ = nullptr;
-
108  }
-
109 
-
110  function_type handler_;
-
111 };
-
112 } // packio
-
113 
-
114 #endif // PACKIO_HANDLER_H
+
90  void set_error()
+
91  {
+
92  complete(Rpc::serialize_error_response(id_, "Unknown error"));
+
93  }
+
94 
+
96  template <typename T>
+
97  void operator()(T&& return_value)
+
98  {
+
99  set_value(std::forward<T>(return_value));
+
100  }
+
101 
+
103  void operator()() { set_value(); }
+
104 
+
105 private:
+
106  void complete(response_buffer_type&& buffer)
+
107  {
+
108  handler_(std::move(buffer));
+
109  handler_ = nullptr;
+
110  }
+
111 
+
112  id_type id_;
+
113  function_type handler_;
+
114 };
+
115 } // packio
+
116 
+
117 #endif // PACKIO_HANDLER_H
-
completion_handler & operator=(completion_handler &&other)
Move assignment operator.
Definition: handler.h:55
-
void operator()()
Same as set_value.
Definition: handler.h:101
-
void set_value()
Notify successful completion of the procedure with no return value This is an overloaded member funct...
Definition: handler.h:77
+
void set_value(T &&return_value)
Notify successful completion of the procedure and set the return value.
Definition: handler.h:73
+
~completion_handler()
The destructor will notify an error if the completion_handler has not been used.
Definition: handler.h:41
+
void operator()()
Same as set_value.
Definition: handler.h:103
+
void set_error()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: handler.h:90
The completion_handler class.
Definition: handler.h:27
- -
~completion_handler()
The destructor will notify an error if the completion_handler has not been used.
Definition: handler.h:37
-
completion_handler(completion_handler &&other)
Move constructor.
Definition: handler.h:48
-
@ success
Success.
-
@ error_during_call
An error happened during the call, server-side error.
-
Definition: as.h:16
-
void set_value(T &&return_value)
Notify successful completion of the procedure and set the return value.
Definition: handler.h:68
-
void set_error()
Notify erroneous completion of the procedure without an error value This is an overloaded member func...
Definition: handler.h:91
-
void set_error(T &&error_value)
Notify erroneous completion of the procedure with an associated error.
Definition: handler.h:82
-
void operator()(T &&return_value)
Same as set_value.
Definition: handler.h:95
-
error
The error codes enumeration.
Definition: error_code.h:28
+
void set_value()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: handler.h:79
+
void set_error(T &&error_value)
Notify erroneous completion of the procedure with an associated error.
Definition: handler.h:84
+
Definition: arg.h:14
+
void operator()(T &&return_value)
Same as set_value.
Definition: handler.h:97
+
completion_handler & operator=(completion_handler &&other)
Move assignment operator.
Definition: handler.h:59
+
completion_handler(completion_handler &&other)
Move constructor.
Definition: handler.h:52
diff --git a/docs/incremental__buffers_8h_source.html b/docs/incremental__buffers_8h_source.html new file mode 100644 index 0000000..16713cc --- /dev/null +++ b/docs/incremental__buffers_8h_source.html @@ -0,0 +1,244 @@ + + + + + + + + + packio: packio/nl_json_rpc/incremental_buffers.h Source File + + + + + + + + + +
+ +
+
+ + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + + +
+
+
incremental_buffers.h
+
+
+
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_NL_JSON_RPC_INCREMENTAL_BUFFERS_H
+
6 #define PACKIO_NL_JSON_RPC_INCREMENTAL_BUFFERS_H
+
7 
+
8 #include <cassert>
+
9 #include <deque>
+
10 #include <optional>
+
11 #include <string>
+
12 
+
13 namespace packio {
+
14 namespace nl_json_rpc {
+
15 
+
16 class incremental_buffers {
+
17 public:
+
18  std::size_t available_buffers() const
+
19  { //
+
20  return serialized_objects_.size();
+
21  }
+
22 
+
23  std::optional<std::string> get_parsed_buffer()
+
24  {
+
25  if (serialized_objects_.empty()) {
+
26  return std::nullopt;
+
27  }
+
28 
+
29  auto buffer = std::move(serialized_objects_.front());
+
30  serialized_objects_.pop_front();
+
31  return buffer;
+
32  }
+
33 
+
34  void feed(std::string_view data)
+
35  {
+
36  reserve_in_place_buffer(data.size());
+
37  std::copy(begin(data), end(data), in_place_buffer());
+
38  in_place_buffer_consumed(data.size());
+
39  }
+
40 
+
41  char* in_place_buffer()
+
42  { //
+
43  return raw_buffer_.data() + buffer_.size();
+
44  }
+
45 
+
46  std::size_t in_place_buffer_capacity() const
+
47  { //
+
48  return raw_buffer_.size() - buffer_.size();
+
49  }
+
50 
+
51  void in_place_buffer_consumed(std::size_t bytes)
+
52  {
+
53  if (bytes == 0) {
+
54  return;
+
55  }
+
56  incremental_parse(bytes);
+
57  }
+
58 
+
59  void reserve_in_place_buffer(std::size_t bytes)
+
60  {
+
61  if (in_place_buffer_capacity() >= bytes) {
+
62  return;
+
63  }
+
64  raw_buffer_.resize(buffer_.size() + bytes);
+
65  }
+
66 
+
67 private:
+
68  void incremental_parse(std::size_t bytes)
+
69  {
+
70  if (buffer_.empty()) {
+
71  std::string_view new_data{in_place_buffer(), bytes};
+
72  auto first_pos = new_data.find_first_of("{[");
+
73  if (first_pos == std::string::npos) {
+
74  return;
+
75  }
+
76 
+
77  initialize(new_data[first_pos]);
+
78  }
+
79 
+
80  std::size_t token_pos = buffer_.size();
+
81  buffer_ = std::string_view{raw_buffer_.data(), buffer_.size() + bytes};
+
82 
+
83  while (true) {
+
84  token_pos = buffer_.find_first_of(tokens_, token_pos + 1);
+
85  if (token_pos == std::string::npos) {
+
86  break;
+
87  }
+
88 
+
89  char token = buffer_[token_pos];
+
90  if (token == '"' && !is_escaped(token_pos)) {
+
91  in_string_ = !in_string_;
+
92  continue;
+
93  }
+
94 
+
95  if (in_string_) {
+
96  continue;
+
97  }
+
98 
+
99  if (token == last_char_) {
+
100  if (--depth_ == 0) {
+
101  // found objet, store the interesting part of the buffer
+
102  std::size_t buffer_size = token_pos + 1;
+
103  std::string new_raw_buffer = raw_buffer_.substr(buffer_size);
+
104  raw_buffer_.resize(buffer_size);
+
105  serialized_objects_.push_back(std::move(raw_buffer_));
+
106  // then clear the buffer and re-feed the rest
+
107  std::size_t bytes_left = buffer_.size() - buffer_size;
+
108  raw_buffer_ = std::move(new_raw_buffer);
+
109  buffer_ = std::string_view{raw_buffer_.data(), bytes_left};
+
110  token_pos -= buffer_size;
+
111  }
+
112  }
+
113  else {
+
114  assert(token == first_char_);
+
115  ++depth_;
+
116  }
+
117  }
+
118  }
+
119 
+
120  bool is_escaped(std::size_t pos)
+
121  {
+
122  bool escaped = false;
+
123  while (pos-- > 0u) {
+
124  if (buffer_[pos] == '\\') {
+
125  escaped = !escaped;
+
126  }
+
127  else {
+
128  break;
+
129  }
+
130  }
+
131  return escaped;
+
132  }
+
133 
+
134  void initialize(char first_char)
+
135  {
+
136  first_char_ = first_char;
+
137  if (first_char_ == '{') {
+
138  last_char_ = '}';
+
139  tokens_ = "{}\"";
+
140  }
+
141  else {
+
142  assert(first_char_ == '[');
+
143  last_char_ = ']';
+
144  tokens_ = "[]\"";
+
145  }
+
146  depth_ = 1;
+
147  in_string_ = false;
+
148  }
+
149 
+
150  bool in_string_;
+
151  int depth_;
+
152  char first_char_;
+
153  char last_char_;
+
154  const char* tokens_;
+
155 
+
156  std::string_view buffer_;
+
157  std::string raw_buffer_;
+
158 
+
159  std::deque<std::string> serialized_objects_;
+
160 };
+
161 
+
162 } // nl_json_rpc
+
163 } // packio
+
164 
+
165 #endif // PACKIO_NL_JSON_RPC_INCREMENTAL_BUFFERS_H
+
+
Definition: arg.h:14
+ + + + \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 3a26513..867cfa8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -7,7 +7,7 @@ - packio: Header-only | msgpack-RPC | asio | coroutines + packio: Header-only | JSON-RPC | msgpack-RPC | asio | coroutines @@ -64,83 +64,84 @@
-
Header-only | msgpack-RPC | asio | coroutines
+
Header-only | JSON-RPC | msgpack-RPC | asio | coroutines
-

This library requires C++17 and is designed as an extension to boost.asio. It will let you build asynchronous servers or client for msgpack-RPC.

+

This library requires C++17 and is designed as an extension to boost.asio. It will let you build asynchronous servers or client for JSON-RPC or msgpack-RPC.

The project is hosted on GitHub and available on Conan Center. Documentation is available on GitHub Pages.

Primer

#include <iostream>
#include <packio/packio.h>
+
using packio::arg;
+ + + + +
int main(int, char**)
{
+
using namespace packio::arg_literals;
+
// Declare a server and a client, sharing the same io_context
packio::net::io_context io;
packio::net::ip::tcp::endpoint bind_ep{
packio::net::ip::make_address("127.0.0.1"), 0};
-
auto server = packio::make_server(packio::net::ip::tcp::acceptor{io, bind_ep});
-
auto client = packio::make_client(packio::net::ip::tcp::socket{io});
-
-
// Declare a synchronous callback
-
server->dispatcher()->add("add", [](int a, int b) { return a + b; });
-
// Declare an asynchronous callback
-
server->dispatcher()->add_async(
-
"multiply", [&io](packio::completion_handler complete, int a, int b) {
+
auto server = make_server(packio::net::ip::tcp::acceptor{io, bind_ep});
+
auto client = make_client(packio::net::ip::tcp::socket{io});
+
+
// Declare a synchronous callback with named arguments
+
server->dispatcher()->add(
+
"add", {"a", "b"}, [](int a, int b) { return a + b; });
+
// Declare an asynchronous callback with named arguments
+
server->dispatcher()->add_async(
+
"multiply", {"a", "b"}, [&io](completion_handler complete, int a, int b) {
// Call the completion handler later
packio::net::post(
io, [a, b, complete = std::move(complete)]() mutable {
complete(a * b);
});
});
-
// Declare a coroutine
-
server->dispatcher()->add_coro(
+
// Declare a coroutine with unnamed arguments
+
server->dispatcher()->add_coro(
"pow", io, [](int a, int b) -> packio::net::awaitable<int> {
co_return std::pow(a, b);
});
// Connect the client
-
client->socket().connect(server->acceptor().local_endpoint());
+
client->socket().connect(server->acceptor().local_endpoint());
// Accept connections
-
server->async_serve_forever();
+
server->async_serve_forever();
// Run the io_context
std::thread thread{[&] { io.run(); }};
-
// Make an asynchronous call
+
// Make an asynchronous call with named arguments
std::promise<int> add1_result, multiply_result;
-
client->async_call(
+
client->async_call(
"add",
-
std::tuple{42, 24},
-
[&](packio::error_code, msgpack::object_handle r) {
-
add1_result.set_value(r->as<int>());
+
std::tuple{arg("a") = 42, arg("b") = 24},
+
[&](packio::error_code, const rpc::response_type& r) {
+
add1_result.set_value(r.result.get<int>());
});
std::cout << "42 + 24 = " << add1_result.get_future().get() << std::endl;
-
// Use auto result type conversion
-
std::promise<int> add2_result;
-
client->async_call(
-
"add",
-
std::tuple{11, 32},
-
packio::as<int>([&](packio::error_code, std::optional<int> r) {
-
add2_result.set_value(*r);
-
}));
-
std::cout << "11 + 32 = " << add2_result.get_future().get() << std::endl;
-
-
// Use packio::net::use_future
-
std::future<msgpack::object_handle> add_future = client->async_call(
-
"multiply", std::tuple{12, 23}, packio::net::use_future);
-
std::cout << "12 * 23 = " << add_future.get()->as<int>() << std::endl;
+
// Use packio::net::use_future with named arguments and literals
+
auto add_future = client->async_call(
+
"multiply",
+
std::tuple{"a"_arg = 12, "b"_arg = 23},
+
packio::net::use_future);
+
std::cout << "12 * 23 = " << add_future.get().result.get<int>() << std::endl;
// Spawn the coroutine and wait for its completion
std::promise<int> pow_result;
packio::net::co_spawn(
io,
[&]() -> packio::net::awaitable<void> {
-
// Call using an awaitable
-
msgpack::object_handle res = co_await client->async_call(
+
// Call using an awaitable and positional arguments
+
auto res = co_await client->async_call(
"pow", std::tuple{2, 8}, packio::net::use_awaitable);
-
pow_result.set_value(res->as<int>());
+
pow_result.set_value(res.result.get<int>());
},
packio::net::detached);
std::cout << "2 ** 8 = " << pow_result.get_future().get() << std::endl;
@@ -154,10 +155,12 @@

Primer

  • C++17 or C++20
  • msgpack >= 3.2.1
  • +
  • nlohmann_json >= 3.9.1
  • boost.asio >= 1.70.0 or asio >= 1.13.0
+

Older version of msgpack and nlohmann_json are probably compatible but they are not tested on the CI.

Standalone or boost asio

-

By default, packio uses boost.asio. It is also compatible with standalone asio. To use the standalone version, the preprocessor macro PACKIO_STANDALONE_ASIO=1 must be defined. If you are using the conan package, you must also use the option standalone_asio=True.

+

By default, packio uses boost.asio. It is also compatible with standalone asio. To use the standalone version, the preprocessor macro PACKIO_STANDALONE_ASIO=1 must be defined. If you are using the conan package, you can use the option standalone_asio=True.

Tested compilers

  • gcc-7
  • @@ -176,13 +179,14 @@

    Tested compilers

    Install with conan

    conan install packio/x.x.x

    Coroutines

    -

    packio is compatible with C++20 coroutines:

      +

      packio is compatible with C++20 coroutines:

      +
      • calls can use the packio::asio::use_awaitable completion token
      • coroutines can be registered in the server
      -

      Coroutines are tested for the following compilers:

        -
      • clang-9 with libc++
      • -
      • Visual Studio 2019 Version 16
      • +

        Coroutines are tested for the following compilers:

        +
          +
        • clang-10 with libc++

        Bonus

        Let's compute fibonacci's numbers recursively using packio and coroutines on a single thread.

        @@ -190,6 +194,9 @@

        Bonus

        #include <packio/packio.h>
        + + +
        int main(int argc, char** argv)
        {
        if (argc < 2) {
        @@ -201,34 +208,32 @@

        Bonus

        packio::net::io_context io;
        packio::net::ip::tcp::endpoint bind_ep{
        packio::net::ip::make_address("127.0.0.1"), 0};
        -
        auto server = packio::make_server(packio::net::ip::tcp::acceptor{io, bind_ep});
        -
        auto client = packio::make_client(packio::net::use_awaitable_t<>::as_default_on(
        +
        auto server = make_server(packio::net::ip::tcp::acceptor{io, bind_ep});
        +
        auto client = make_client(packio::net::use_awaitable_t<>::as_default_on(
        packio::net::ip::tcp::socket{io}));
        -
        server->dispatcher()->add_coro(
        +
        server->dispatcher()->add_coro(
        "fibonacci", io, [&](int n) -> packio::net::awaitable<int> {
        if (n <= 1) {
        co_return n;
        }
        -
        auto r1 = co_await client->async_call("fibonacci", std::tuple{n - 1});
        -
        auto r2 = co_await client->async_call("fibonacci", std::tuple{n - 2});
        +
        auto r1 = co_await client->async_call("fibonacci", std::tuple{n - 1});
        +
        auto r2 = co_await client->async_call("fibonacci", std::tuple{n - 2});
        -
        co_return r1->as<int>() + r2->as<int>();
        +
        co_return r1.result.as<int>() + r2.result.as<int>();
        });
        -
        client->socket().connect(server->acceptor().local_endpoint());
        -
        server->async_serve_forever();
        +
        client->socket().connect(server->acceptor().local_endpoint());
        +
        server->async_serve_forever();
        int result = 0;
        -
        client->async_call(
        -
        "fibonacci",
        -
        std::tuple{n},
        -
        packio::as<int>([&](packio::error_code, std::optional<int> r) {
        -
        result = *r;
        +
        client->async_call(
        +
        "fibonacci", std::tuple{n}, [&](packio::error_code, auto r) {
        +
        result = r.result.template as<int>();
        io.stop();
        -
        }));
        +
        });
        io.run();
        @@ -238,10 +243,18 @@

        Bonus

        }
-
auto make_client(Socket &&socket)
Create a client from a socket.
Definition: client.h:481
-
The completion_handler class.
Definition: handler.h:27
-
auto make_server(Acceptor &&acceptor)
Create a server from an acceptor.
Definition: server.h:149
+
::packio::client< rpc, Socket, Map > client
The client for msgpack-RPC.
Definition: msgpack_rpc.h:29
+
completion_handler< rpc > completion_handler
The completion_handler for JSON-RPC.
Definition: nl_json_rpc.h:23
+
The JSON-RPC protocol implementation.
Definition: rpc.h:174
+
auto make_client(Socket &&socket)
The make_client function for JSON-RPC.
Definition: nl_json_rpc.h:35
+
completion_handler< rpc > completion_handler
The completion_handler for msgpack-RPC.
Definition: msgpack_rpc.h:21
+
auto make_client(Socket &&socket)
The make_client function for msgpack-RPC.
Definition: msgpack_rpc.h:33
+
::packio::server< rpc, Acceptor, Dispatcher > server
The server for msgpack-RPC.
Definition: msgpack_rpc.h:40
+
auto make_server(Acceptor &&acceptor)
The make_server function for msgpack-RPC.
Definition: msgpack_rpc.h:44
+
auto make_server(Acceptor &&acceptor)
The make_server function for JSON-RPC.
Definition: nl_json_rpc.h:46
+
auto make_server(Acceptor &&acceptor)
Create a server from an acceptor.
Definition: server.h:150
+
auto make_client(Socket &&socket)
Create a client from a socket.
Definition: client.h:454
diff --git a/docs/internal_2rpc_8h_source.html b/docs/internal_2rpc_8h_source.html new file mode 100644 index 0000000..75f4130 --- /dev/null +++ b/docs/internal_2rpc_8h_source.html @@ -0,0 +1,96 @@ + + + + + + + + + packio: packio/internal/rpc.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
rpc.h
+
+
+
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_RPC_H
+
6 #define PACKIO_RPC_H
+
7 
+
8 #include <optional>
+
9 #include <string>
+
10 
+
11 namespace packio {
+
12 
+
13 enum class call_type { request = 0, notification = 1 };
+
14 
+
15 } // packio
+
16 
+
17 #endif // PACKIO_RPC_H
+
+
Definition: arg.h:14
+ + + + \ No newline at end of file diff --git a/docs/manual__strand_8h_source.html b/docs/manual__strand_8h_source.html index 23c52a6..2b15e34 100644 --- a/docs/manual__strand_8h_source.html +++ b/docs/manual__strand_8h_source.html @@ -81,7 +81,7 @@
8 #include <queue>
9 
10 #include "config.h"
-
11 #include "unique_function.h"
+
11 #include "movable_function.h"
12 
13 namespace packio {
14 namespace internal {
@@ -89,7 +89,7 @@
16 template <typename Executor>
17 class manual_strand {
18 public:
-
19  using function_type = unique_function<void()>;
+
19  using function_type = movable_function<void()>;
20 
21  manual_strand(const Executor& executor) : strand_{executor} {}
22 
@@ -133,7 +133,7 @@
60 
61 #endif // PACKIO_MANUAL_STRAND_H
-
Definition: as.h:16
+
Definition: arg.h:14
diff --git a/docs/menudata.js b/docs/menudata.js index dd38dbc..7a1c208 100644 --- a/docs/menudata.js +++ b/docs/menudata.js @@ -22,6 +22,12 @@ for the JavaScript code in this file */ var menudata={children:[ {text:"Main Page",url:"index.html"}, +{text:"Namespaces",url:"namespaces.html",children:[ +{text:"Namespace List",url:"namespaces.html"}, +{text:"Namespace Members",url:"namespacemembers.html",children:[ +{text:"All",url:"namespacemembers.html"}, +{text:"Functions",url:"namespacemembers_func.html"}, +{text:"Typedefs",url:"namespacemembers_type.html"}]}]}, {text:"Classes",url:"annotated.html",children:[ {text:"Class List",url:"annotated.html"}, {text:"Class Index",url:"classes.html"}, @@ -34,12 +40,15 @@ var menudata={children:[ {text:"f",url:"functions.html#index_f"}, {text:"g",url:"functions.html#index_g"}, {text:"h",url:"functions.html#index_h"}, +{text:"i",url:"functions.html#index_i"}, {text:"k",url:"functions.html#index_k"}, {text:"m",url:"functions.html#index_m"}, +{text:"n",url:"functions.html#index_n"}, {text:"o",url:"functions.html#index_o"}, {text:"p",url:"functions.html#index_p"}, {text:"r",url:"functions.html#index_r"}, {text:"s",url:"functions.html#index_s"}, +{text:"z",url:"functions.html#index_z"}, {text:"~",url:"functions.html#index__7E"}]}, {text:"Functions",url:"functions_func.html",children:[ {text:"a",url:"functions_func.html#index_a"}, diff --git a/docs/movable__function_8h_source.html b/docs/movable__function_8h_source.html new file mode 100644 index 0000000..0158530 --- /dev/null +++ b/docs/movable__function_8h_source.html @@ -0,0 +1,174 @@ + + + + + + + + + packio: packio/internal/movable_function.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
movable_function.h
+
+
+
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_UNIQUE_FUNCTION_H
+
6 #define PACKIO_UNIQUE_FUNCTION_H
+
7 
+
8 #include <functional>
+
9 #include <type_traits>
+
10 #include <utility>
+
11 
+
12 namespace packio {
+
13 namespace internal {
+
14 
+
15 template <typename T>
+
16 class movable_function : public std::function<T> {
+
17  template <typename Fn, typename En = void>
+
18  struct wrapper {
+
19  };
+
20 
+
21  // specialization for CopyConstructible Fn
+
22  template <typename Fn>
+
23  struct wrapper<Fn, std::enable_if_t<std::is_copy_constructible<Fn>::value>> {
+
24  Fn fn;
+
25 
+
26  template <typename... Args>
+
27  auto operator()(Args&&... args)
+
28  {
+
29  return fn(std::forward<Args>(args)...);
+
30  }
+
31  };
+
32 
+
33  // specialization for MoveConstructible-only Fn
+
34  template <typename Fn>
+
35  struct wrapper<
+
36  Fn,
+
37  std::enable_if_t<
+
38  !std::is_copy_constructible<Fn>::value
+
39  && std::is_move_constructible<Fn>::value>> {
+
40  Fn fn;
+
41 
+
42  wrapper(Fn&& fn) : fn(std::forward<Fn>(fn)) {}
+
43 
+
44  wrapper(wrapper&&) = default;
+
45  wrapper& operator=(wrapper&&) = default;
+
46 
+
47  // these two functions are instantiated by std::function and are never called
+
48  wrapper(const wrapper& rhs) : fn(const_cast<Fn&&>(rhs.fn))
+
49  {
+
50  // hack to initialize fn for non-DefaultContructible types
+
51  std::abort();
+
52  }
+
53  wrapper& operator=(wrapper&) { std::abort(); }
+
54 
+
55  template <typename... Args>
+
56  auto operator()(Args&&... args)
+
57  {
+
58  return fn(std::forward<Args>(args)...);
+
59  }
+
60  };
+
61 
+
62  using base = std::function<T>;
+
63 
+
64 public:
+
65  movable_function() noexcept = default;
+
66  movable_function(std::nullptr_t) noexcept : base(nullptr) {}
+
67 
+
68  template <typename Fn>
+
69  movable_function(Fn&& f) : base(wrapper<Fn>{std::forward<Fn>(f)})
+
70  {
+
71  }
+
72 
+
73  movable_function(movable_function&&) = default;
+
74  movable_function& operator=(movable_function&&) = default;
+
75 
+
76  movable_function& operator=(std::nullptr_t)
+
77  {
+
78  base::operator=(nullptr);
+
79  return *this;
+
80  }
+
81 
+
82  template <typename Fn>
+
83  movable_function& operator=(Fn&& f)
+
84  {
+
85  base::operator=(wrapper<Fn>{std::forward<Fn>(f)});
+
86  return *this;
+
87  }
+
88 
+
89  using base::operator();
+
90 };
+
91 
+
92 } // internal
+
93 } // packio
+
94 
+
95 #endif // PACKIO_UNIQUE_FUNCTION_H
+
+
Definition: arg.h:14
+ + + + \ No newline at end of file diff --git a/docs/msgpack_2rpc_8h_source.html b/docs/msgpack_2rpc_8h_source.html new file mode 100644 index 0000000..f88fc9d --- /dev/null +++ b/docs/msgpack_2rpc_8h_source.html @@ -0,0 +1,400 @@ + + + + + + + + + packio: packio/msgpack/rpc.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
rpc.h
+
+
+
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_MSGPACK_RPC_H
+
6 #define PACKIO_MSGPACK_RPC_H
+
7 
+
8 #include <msgpack.hpp>
+
9 
+
10 #include "../arg.h"
+
11 #include "../internal/config.h"
+
12 #include "../internal/log.h"
+
13 #include "../internal/rpc.h"
+
14 
+
15 namespace packio::msgpack {
+
16 
+
17 enum class msgpack_rpc_type { request = 0, response = 1, notification = 2 };
+
18 
+
19 template <typename... Args>
+
20 constexpr bool positional_args_v = (!is_arg_v<Args> && ...);
+
21 
+
23 class rpc {
+
24  using buffer_type = ::msgpack::sbuffer;
+
25 
+
26 public:
+
28  using id_type = uint32_t;
+
29 
+
31  struct request {
+
32  call_type type;
+
33  id_type id;
+
34  std::string method;
+
35  ::msgpack::object args;
+
36 
+
37  std::unique_ptr<::msgpack::zone> zone;
+
38  };
+
39 
+
41  struct response {
+
42  id_type id;
+
43  ::msgpack::object result;
+
44  ::msgpack::object error;
+
45 
+
46  std::unique_ptr<::msgpack::zone> zone;
+
47  };
+
48 
+
49  class incremental_parser {
+
50  public:
+
51  incremental_parser()
+
52  : unpacker_{std::make_unique<::msgpack::unpacker>()}
+
53  {
+
54  }
+
55 
+
56  std::optional<request> get_request()
+
57  {
+
58  try_parse_object();
+
59  if (!parsed_) {
+
60  return std::nullopt;
+
61  }
+
62  auto object = std::move(*parsed_);
+
63  parsed_.reset();
+
64  return parse_request(std::move(object));
+
65  }
+
66 
+
67  std::optional<response> get_response()
+
68  {
+
69  try_parse_object();
+
70  if (!parsed_) {
+
71  return std::nullopt;
+
72  }
+
73  auto object = std::move(*parsed_);
+
74  parsed_.reset();
+
75  return parse_response(std::move(object));
+
76  }
+
77 
+
78  char* buffer() const
+
79  { //
+
80  return unpacker_->buffer();
+
81  }
+
82 
+
83  std::size_t buffer_capacity() const
+
84  {
+
85  return unpacker_->buffer_capacity();
+
86  }
+
87 
+
88  void buffer_consumed(std::size_t bytes)
+
89  {
+
90  unpacker_->buffer_consumed(bytes);
+
91  }
+
92 
+
93  void reserve_buffer(std::size_t bytes)
+
94  {
+
95  unpacker_->reserve_buffer(bytes);
+
96  }
+
97 
+
98  private:
+
99  void try_parse_object()
+
100  {
+
101  if (parsed_) {
+
102  return;
+
103  }
+
104  ::msgpack::object_handle object;
+
105  if (unpacker_->next(object)) {
+
106  parsed_ = std::move(object);
+
107  }
+
108  }
+
109 
+
110  std::optional<::msgpack::object_handle> parsed_;
+
111  std::unique_ptr<::msgpack::unpacker> unpacker_;
+
112  };
+
113 
+
114  static std::string format_id(const id_type& id)
+
115  {
+
116  return std::to_string(id);
+
117  }
+
118 
+
119  template <typename... Args>
+
120  static auto serialize_notification(std::string_view method, Args&&... args)
+
121  -> std::enable_if_t<positional_args_v<Args...>, buffer_type>
+
122  {
+
123  buffer_type buffer;
+
124  ::msgpack::pack(
+
125  buffer,
+
126  std::forward_as_tuple(
+
127  static_cast<int>(msgpack_rpc_type::notification),
+
128  method,
+
129  std::forward_as_tuple(std::forward<Args>(args)...)));
+
130  return buffer;
+
131  }
+
132 
+
133  template <typename... Args>
+
134  static auto serialize_notification(std::string_view, Args&&...)
+
135  -> std::enable_if_t<!positional_args_v<Args...>, buffer_type>
+
136  {
+
137  static_assert(
+
138  positional_args_v<Args...>,
+
139  "msgpack-RPC does not support named arguments");
+
140  }
+
141 
+
142  template <typename... Args>
+
143  static auto serialize_request(id_type id, std::string_view method, Args&&... args)
+
144  -> std::enable_if_t<positional_args_v<Args...>, buffer_type>
+
145  {
+
146  buffer_type buffer;
+
147  ::msgpack::pack(
+
148  buffer,
+
149  std::forward_as_tuple(
+
150  static_cast<int>(msgpack_rpc_type::request),
+
151  id,
+
152  method,
+
153  std::forward_as_tuple(std::forward<Args>(args)...)));
+
154  return buffer;
+
155  }
+
156 
+
157  template <typename... Args>
+
158  static auto serialize_request(id_type, std::string_view, Args&&...)
+
159  -> std::enable_if_t<!positional_args_v<Args...>, buffer_type>
+
160  {
+
161  static_assert(
+
162  positional_args_v<Args...>,
+
163  "msgpack-RPC does not support named arguments");
+
164  }
+
165 
+
166  template <typename... Args>
+
167  static buffer_type serialize_response(response response)
+
168  {
+
169  buffer_type buffer;
+
170  ::msgpack::pack(
+
171  buffer,
+
172  std::forward_as_tuple(
+
173  static_cast<int>(msgpack_rpc_type::response),
+
174  response.id,
+
175  response.error,
+
176  response.result));
+
177  return buffer;
+
178  }
+
179 
+
180  static net::const_buffer buffer(const buffer_type& buf)
+
181  {
+
182  return net::const_buffer(buf.data(), buf.size());
+
183  }
+
184 
+
185  template <typename T, typename NamesContainer>
+
186  static std::optional<T> extract_args(
+
187  const ::msgpack::object& args,
+
188  const NamesContainer&)
+
189  {
+
190  if (args.type != ::msgpack::type::ARRAY) {
+
191  PACKIO_ERROR("arguments is not an array");
+
192  return std::nullopt;
+
193  }
+
194 
+
195  if (args.via.array.size != std::tuple_size_v<T>) {
+
196  // keep this check otherwise msgpack unpacker
+
197  // may silently drop arguments
+
198  return std::nullopt;
+
199  }
+
200 
+
201  try {
+
202  return args.as<T>();
+
203  }
+
204  catch (::msgpack::type_error&) {
+
205  return std::nullopt;
+
206  }
+
207  }
+
208 
+
209  static response make_response(id_type id)
+
210  {
+
211  return make_response(id, ::msgpack::object{});
+
212  }
+
213 
+
214  template <typename T>
+
215  static response make_response(id_type id, T&& value)
+
216  {
+
217  response resp;
+
218  resp.id = id;
+
219  resp.zone = std::make_unique<::msgpack::zone>();
+
220  resp.result = ::msgpack::object(std::forward<T>(value), *resp.zone);
+
221  return resp;
+
222  }
+
223 
+
224  template <typename T>
+
225  static response make_error_response(id_type id, T&& value)
+
226  {
+
227  response resp;
+
228  resp.id = id;
+
229  resp.zone = std::make_unique<::msgpack::zone>();
+
230  resp.error = ::msgpack::object(std::forward<T>(value), *resp.zone);
+
231  return resp;
+
232  }
+
233 
+
234 private:
+
235  static std::optional<response> parse_response(::msgpack::object_handle&& res)
+
236  {
+
237  if (res->type != ::msgpack::type::ARRAY) {
+
238  PACKIO_ERROR("unexpected message type: {}", res->type);
+
239  return std::nullopt;
+
240  }
+
241  if (res->via.array.size != 4) {
+
242  PACKIO_ERROR("unexpected message size: {}", res->via.array.size);
+
243  return std::nullopt;
+
244  }
+
245  int type = res->via.array.ptr[0].as<int>();
+
246  if (type != static_cast<int>(msgpack_rpc_type::response)) {
+
247  PACKIO_ERROR("unexpected type: {}", type);
+
248  return std::nullopt;
+
249  }
+
250 
+
251  response parsed;
+
252  parsed.zone = std::move(res.zone());
+
253  const auto& array = res->via.array.ptr;
+
254 
+
255  parsed.id = array[1].as<id_type>();
+
256  if (array[2].type != ::msgpack::type::NIL) {
+
257  parsed.error = array[2];
+
258  }
+
259  else {
+
260  parsed.result = array[3];
+
261  }
+
262  return parsed;
+
263  }
+
264 
+
265  static std::optional<request> parse_request(::msgpack::object_handle&& req)
+
266  {
+
267  if (req->type != ::msgpack::type::ARRAY || req->via.array.size < 3) {
+
268  PACKIO_ERROR("unexpected message type: {}", req->type);
+
269  return std::nullopt;
+
270  }
+
271 
+
272  request parsed;
+
273  parsed.zone = std::move(req.zone());
+
274  const auto& array = req->via.array.ptr;
+
275  auto array_size = req->via.array.size;
+
276  ;
+
277 
+
278  try {
+
279  int idx = 0;
+
280  msgpack_rpc_type type = static_cast<msgpack_rpc_type>(
+
281  array[idx++].as<int>());
+
282 
+
283  std::size_t expected_size;
+
284  switch (type) {
+
285  case msgpack_rpc_type::request:
+
286  parsed.id = array[idx++].as<id_type>();
+
287  expected_size = 4;
+
288  parsed.type = call_type::request;
+
289  break;
+
290  case msgpack_rpc_type::notification:
+
291  expected_size = 3;
+
292  parsed.type = call_type::notification;
+
293  break;
+
294  default:
+
295  PACKIO_ERROR("unexpected type: {}", type);
+
296  return std::nullopt;
+
297  }
+
298 
+
299  if (array_size != expected_size) {
+
300  PACKIO_ERROR("unexpected message size: {}", array_size);
+
301  return std::nullopt;
+
302  }
+
303 
+
304  parsed.method = array[idx++].as<std::string>();
+
305  parsed.args = array[idx++];
+
306 
+
307  return parsed;
+
308  }
+
309  catch (::msgpack::type_error& exc) {
+
310  PACKIO_ERROR("unexpected message content: {}", exc.what());
+
311  (void)exc;
+
312  return std::nullopt;
+
313  }
+
314  }
+
315 };
+
316 
+
317 } // packio::msgpack
+
318 
+
319 #endif // PACKIO_MSGPACK_RPC_H
+
+
The object representing a client request.
Definition: rpc.h:31
+ +
The object representing the response to a call.
Definition: rpc.h:41
+
uint32_t id_type
Type of the call ID.
Definition: rpc.h:28
+
The msgpack RPC protocol implementation.
Definition: rpc.h:23
+
std::unique_ptr<::msgpack::zone > zone
Msgpack zone storing error and result.
Definition: rpc.h:46
+
std::unique_ptr<::msgpack::zone > zone
Msgpack zone storing the args.
Definition: rpc.h:37
+ + + + \ No newline at end of file diff --git a/docs/msgpack_8h.html b/docs/msgpack_8h.html new file mode 100644 index 0000000..9bd7c04 --- /dev/null +++ b/docs/msgpack_8h.html @@ -0,0 +1,122 @@ + + + + + + + + + packio: packio/msgpack/msgpack.h File Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
msgpack.h File Reference
+
+
+
#include "../client.h"
+#include "../server.h"
+#include "rpc.h"
+
+

Go to the source code of this file.

+ + + + + + +

+Namespaces

 packio::msgpack
 
 packio
 
+ + + + + + + + + + + + +

+Typedefs

template<typename Socket , template< class... > class Map = default_map>
using packio::msgpack::client = ::packio::client< rpc, Socket, Map >
 The msgpack client class. More...
 
template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
using packio::msgpack::server = ::packio::server< rpc, Acceptor, Dispatcher >
 The msgpack server class. More...
 
using packio::msgpack::completion_handler = completion_handler< rpc >
 The completion_handler class. More...
 
+ + + + + + + + + +

+Functions

template<typename Socket , template< class... > class Map = default_map>
auto packio::msgpack::make_client (Socket &&socket)
 Create a msgpack client from a socket. More...
 
template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
auto packio::msgpack::make_server (Acceptor &&acceptor)
 Create a msgpack server from an acceptor. More...
 
+

Detailed Description

+

Typedefs and functions to use the msgpack-RPC protocol

+
+ + + + \ No newline at end of file diff --git a/docs/msgpack_8h_source.html b/docs/msgpack_8h_source.html new file mode 100644 index 0000000..3d433a9 --- /dev/null +++ b/docs/msgpack_8h_source.html @@ -0,0 +1,124 @@ + + + + + + + + + packio: packio/msgpack/msgpack.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
msgpack.h
+
+
+Go to the documentation of this file.
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_MSGPACK_MSGPACK_H
+
6 #define PACKIO_MSGPACK_MSGPACK_H
+
7 
+
10 
+
11 #include "../client.h"
+
12 #include "../server.h"
+
13 #include "rpc.h"
+
14 
+
17 namespace packio {
+
18 namespace msgpack {
+
19 
+
23 template <typename Socket, template <class...> class Map = default_map>
+ +
25 
+
29 template <typename Socket, template <class...> class Map = default_map>
+
30 auto make_client(Socket&& socket)
+
31 {
+
32  return std::make_shared<client<Socket, Map>>(std::forward<Socket>(socket));
+
33 }
+
34 
+
38 template <typename Acceptor, typename Dispatcher = dispatcher<rpc>>
+ +
40 
+
44 template <typename Acceptor, typename Dispatcher = dispatcher<rpc>>
+
45 auto make_server(Acceptor&& acceptor)
+
46 {
+
47  return std::make_shared<server<Acceptor, Dispatcher>>(
+
48  std::forward<Acceptor>(acceptor));
+
49 }
+
50 
+ +
58 
+
59 } // msgpack
+
60 } // packio
+
61 
+
62 #endif // PACKIO_MSGPACK_MSGPACK_H
+
+
completion_handler< rpc > completion_handler
The completion_handler class.
Definition: msgpack.h:57
+
auto make_server(Acceptor &&acceptor)
Create a msgpack server from an acceptor.
Definition: msgpack.h:45
+
The client class.
Definition: client.h:34
+
auto make_client(Socket &&socket)
Create a msgpack client from a socket.
Definition: msgpack.h:30
+
The server class.
Definition: server.h:27
+
Definition: arg.h:14
+ + + + \ No newline at end of file diff --git a/docs/msgpack__rpc_2rpc_8h_source.html b/docs/msgpack__rpc_2rpc_8h_source.html new file mode 100644 index 0000000..f29c14f --- /dev/null +++ b/docs/msgpack__rpc_2rpc_8h_source.html @@ -0,0 +1,400 @@ + + + + + + + + + packio: packio/msgpack_rpc/rpc.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
rpc.h
+
+
+
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_MSGPACK_RPC_RPC_H
+
6 #define PACKIO_MSGPACK_RPC_RPC_H
+
7 
+
8 #include <msgpack.hpp>
+
9 
+
10 #include "../arg.h"
+
11 #include "../internal/config.h"
+
12 #include "../internal/log.h"
+
13 #include "../internal/rpc.h"
+
14 
+
15 namespace packio {
+
16 namespace msgpack_rpc {
+
17 namespace internal {
+
18 
+
19 template <typename... Args>
+
20 constexpr bool positional_args_v = (!is_arg_v<Args> && ...);
+
21 
+
22 enum class msgpack_rpc_type { request = 0, response = 1, notification = 2 };
+
23 
+
24 using id_type = uint32_t;
+
25 using native_type = ::msgpack::object;
+
26 
+
28 struct request {
+
29  call_type type;
+
30  id_type id;
+
31  std::string method;
+
32  native_type args;
+
33 
+
34  std::unique_ptr<::msgpack::zone> zone;
+
35 };
+
36 
+
38 struct response {
+
39  id_type id;
+
40  native_type result;
+
41  native_type error;
+
42 
+
43  std::unique_ptr<::msgpack::zone> zone;
+
44 };
+
45 
+ +
48 public:
+
49  incremental_parser() : unpacker_{std::make_unique<::msgpack::unpacker>()} {}
+
50 
+
51  std::optional<request> get_request()
+
52  {
+
53  try_parse_object();
+
54  if (!parsed_) {
+
55  return std::nullopt;
+
56  }
+
57  auto object = std::move(*parsed_);
+
58  parsed_.reset();
+
59  return parse_request(std::move(object));
+
60  }
+
61 
+
62  std::optional<response> get_response()
+
63  {
+
64  try_parse_object();
+
65  if (!parsed_) {
+
66  return std::nullopt;
+
67  }
+
68  auto object = std::move(*parsed_);
+
69  parsed_.reset();
+
70  return parse_response(std::move(object));
+
71  }
+
72 
+
73  char* buffer() const
+
74  { //
+
75  return unpacker_->buffer();
+
76  }
+
77 
+
78  std::size_t buffer_capacity() const { return unpacker_->buffer_capacity(); }
+
79 
+
80  void buffer_consumed(std::size_t bytes)
+
81  {
+
82  unpacker_->buffer_consumed(bytes);
+
83  }
+
84 
+
85  void reserve_buffer(std::size_t bytes) { unpacker_->reserve_buffer(bytes); }
+
86 
+
87 private:
+
88  void try_parse_object()
+
89  {
+
90  if (parsed_) {
+
91  return;
+
92  }
+
93  ::msgpack::object_handle object;
+
94  if (unpacker_->next(object)) {
+
95  parsed_ = std::move(object);
+
96  }
+
97  }
+
98 
+
99  static std::optional<response> parse_response(::msgpack::object_handle&& res)
+
100  {
+
101  if (res->type != ::msgpack::type::ARRAY) {
+
102  PACKIO_ERROR("unexpected message type: {}", res->type);
+
103  return std::nullopt;
+
104  }
+
105  if (res->via.array.size != 4) {
+
106  PACKIO_ERROR("unexpected message size: {}", res->via.array.size);
+
107  return std::nullopt;
+
108  }
+
109  int type = res->via.array.ptr[0].as<int>();
+
110  if (type != static_cast<int>(msgpack_rpc_type::response)) {
+
111  PACKIO_ERROR("unexpected type: {}", type);
+
112  return std::nullopt;
+
113  }
+
114 
+
115  std::optional<response> parsed{std::in_place};
+
116  parsed->zone = std::move(res.zone());
+
117  const auto& array = res->via.array.ptr;
+
118 
+
119  parsed->id = array[1].as<id_type>();
+
120  if (array[2].type != ::msgpack::type::NIL) {
+
121  parsed->error = array[2];
+
122  }
+
123  else {
+
124  parsed->result = array[3];
+
125  }
+
126  return parsed;
+
127  }
+
128 
+
129  static std::optional<request> parse_request(::msgpack::object_handle&& req)
+
130  {
+
131  if (req->type != ::msgpack::type::ARRAY || req->via.array.size < 3) {
+
132  PACKIO_ERROR("unexpected message type: {}", req->type);
+
133  return std::nullopt;
+
134  }
+
135 
+
136  std::optional<request> parsed{std::in_place};
+
137  parsed->zone = std::move(req.zone());
+
138  const auto& array = req->via.array.ptr;
+
139  auto array_size = req->via.array.size;
+
140  ;
+
141 
+
142  try {
+
143  int idx = 0;
+
144  msgpack_rpc_type type = static_cast<msgpack_rpc_type>(
+
145  array[idx++].as<int>());
+
146 
+
147  std::size_t expected_size;
+
148  switch (type) {
+
149  case msgpack_rpc_type::request:
+
150  parsed->id = array[idx++].as<id_type>();
+
151  expected_size = 4;
+
152  parsed->type = call_type::request;
+
153  break;
+
154  case msgpack_rpc_type::notification:
+
155  expected_size = 3;
+
156  parsed->type = call_type::notification;
+
157  break;
+
158  default:
+
159  PACKIO_ERROR("unexpected type: {}", type);
+
160  return std::nullopt;
+
161  }
+
162 
+
163  if (array_size != expected_size) {
+
164  PACKIO_ERROR("unexpected message size: {}", array_size);
+
165  return std::nullopt;
+
166  }
+
167 
+
168  parsed->method = array[idx++].as<std::string>();
+
169  parsed->args = array[idx++];
+
170 
+
171  return parsed;
+
172  }
+
173  catch (::msgpack::type_error& exc) {
+
174  PACKIO_ERROR("unexpected message content: {}", exc.what());
+
175  (void)exc;
+
176  return std::nullopt;
+
177  }
+
178  }
+
179 
+
180  std::optional<::msgpack::object_handle> parsed_;
+
181  std::unique_ptr<::msgpack::unpacker> unpacker_;
+
182 };
+
183 
+
184 } // internal
+
185 
+
187 class rpc {
+
188 public:
+
190  using id_type = internal::id_type;
+
191 
+
193  using native_type = internal::native_type;
+
194 
+ +
197 
+ +
200 
+ +
203 
+
204  static std::string format_id(const id_type& id)
+
205  {
+
206  return std::to_string(id);
+
207  }
+
208 
+
209  template <typename... Args>
+
210  static auto serialize_notification(std::string_view method, Args&&... args)
+
211  -> std::enable_if_t<internal::positional_args_v<Args...>, ::msgpack::sbuffer>
+
212  {
+
213  ::msgpack::sbuffer buffer;
+
214  ::msgpack::pack(
+
215  buffer,
+
216  std::forward_as_tuple(
+
217  static_cast<int>(internal::msgpack_rpc_type::notification),
+
218  method,
+
219  std::forward_as_tuple(std::forward<Args>(args)...)));
+
220  return buffer;
+
221  }
+
222 
+
223  template <typename... Args>
+
224  static auto serialize_notification(std::string_view, Args&&...)
+
225  -> std::enable_if_t<!internal::positional_args_v<Args...>, ::msgpack::sbuffer>
+
226  {
+
227  static_assert(
+
228  internal::positional_args_v<Args...>,
+
229  "msgpack-RPC does not support named arguments");
+
230  }
+
231 
+
232  template <typename... Args>
+
233  static auto serialize_request(id_type id, std::string_view method, Args&&... args)
+
234  -> std::enable_if_t<internal::positional_args_v<Args...>, ::msgpack::sbuffer>
+
235  {
+
236  ::msgpack::sbuffer buffer;
+
237  ::msgpack::pack(
+
238  buffer,
+
239  std::forward_as_tuple(
+
240  static_cast<int>(internal::msgpack_rpc_type::request),
+
241  id,
+
242  method,
+
243  std::forward_as_tuple(std::forward<Args>(args)...)));
+
244  return buffer;
+
245  }
+
246 
+
247  template <typename... Args>
+
248  static auto serialize_request(id_type, std::string_view, Args&&...)
+
249  -> std::enable_if_t<!internal::positional_args_v<Args...>, ::msgpack::sbuffer>
+
250  {
+
251  static_assert(
+
252  internal::positional_args_v<Args...>,
+
253  "msgpack-RPC does not support named arguments");
+
254  }
+
255 
+
256  static ::msgpack::sbuffer serialize_response(id_type id)
+
257  {
+
258  return serialize_response(id, ::msgpack::object{});
+
259  }
+
260 
+
261  template <typename T>
+
262  static ::msgpack::sbuffer serialize_response(id_type id, T&& value)
+
263  {
+
264  ::msgpack::sbuffer buffer;
+
265  ::msgpack::pack(
+
266  buffer,
+
267  std::forward_as_tuple(
+
268  static_cast<int>(internal::msgpack_rpc_type::response),
+
269  id,
+
270  ::msgpack::object{},
+
271  std::forward<T>(value)));
+
272  return buffer;
+
273  }
+
274 
+
275  template <typename T>
+
276  static ::msgpack::sbuffer serialize_error_response(id_type id, T&& value)
+
277  {
+
278  ::msgpack::sbuffer buffer;
+
279  ::msgpack::pack(
+
280  buffer,
+
281  std::forward_as_tuple(
+
282  static_cast<int>(internal::msgpack_rpc_type::response),
+
283  id,
+
284  std::forward<T>(value),
+
285  ::msgpack::object{}));
+
286  return buffer;
+
287  }
+
288 
+
289  static net::const_buffer buffer(const ::msgpack::sbuffer& buf)
+
290  {
+
291  return net::const_buffer(buf.data(), buf.size());
+
292  }
+
293 
+
294  template <typename T, typename NamesContainer>
+
295  static std::optional<T> extract_args(
+
296  const ::msgpack::object& args,
+
297  const NamesContainer&)
+
298  {
+
299  if (args.type != ::msgpack::type::ARRAY) {
+
300  PACKIO_ERROR("arguments is not an array");
+
301  return std::nullopt;
+
302  }
+
303 
+
304  if (args.via.array.size != std::tuple_size_v<T>) {
+
305  // keep this check otherwise msgpack unpacker
+
306  // may silently drop arguments
+
307  return std::nullopt;
+
308  }
+
309 
+
310  try {
+
311  return args.as<T>();
+
312  }
+
313  catch (::msgpack::type_error&) {
+
314  return std::nullopt;
+
315  }
+
316  }
+
317 };
+
318 
+
319 } // msgpack_rpc
+
320 } // packio
+
321 
+
322 #endif // PACKIO_MSGPACK_RPC_RPC_H
+
+
internal::native_type native_type
The native type of the serialization library.
Definition: rpc.h:193
+
std::unique_ptr<::msgpack::zone > zone
Msgpack zone storing error and result.
Definition: rpc.h:43
+
The msgpack RPC protocol implementation.
Definition: rpc.h:187
+
The incremental parser for msgpack-RPC objects.
Definition: rpc.h:47
+
Definition: arg.h:14
+
The object representing a client request.
Definition: rpc.h:28
+
std::unique_ptr<::msgpack::zone > zone
Msgpack zone storing the args.
Definition: rpc.h:34
+
The object representing the response to a call.
Definition: rpc.h:38
+
internal::id_type id_type
Type of the call ID.
Definition: rpc.h:190
+ + + + \ No newline at end of file diff --git a/docs/msgpack__rpc_8h.html b/docs/msgpack__rpc_8h.html index db84d93..bb98374 100644 --- a/docs/msgpack__rpc_8h.html +++ b/docs/msgpack__rpc_8h.html @@ -7,7 +7,7 @@ - packio: packio/internal/msgpack_rpc.h File Reference + packio: packio/msgpack_rpc/msgpack_rpc.h File Reference @@ -63,35 +63,68 @@
msgpack_rpc.h File Reference
-
#include <cstdint>
+
#include "../client.h"
+#include "../server.h"
+#include "rpc.h"

Go to the source code of this file.

+ +

Namespaces

 packio::msgpack_rpc
 
 packio
 
- - - + + + + + + + + + + + + + + + +

Typedefs

-using packio::id_type = uint32_t
 Type used to store call IDs.
 
+using packio::msgpack_rpc::completion_handler = completion_handler< rpc >
 The completion_handler for msgpack-RPC.
 
+template<template< class... > class Map = default_map, typename Lockable = default_mutex>
using packio::msgpack_rpc::dispatcher = dispatcher< rpc, Map, Lockable >
 The dispatcher for msgpack-RPC.
 
+template<typename Socket , template< class... > class Map = default_map>
using packio::msgpack_rpc::client = ::packio::client< rpc, Socket, Map >
 The client for msgpack-RPC.
 
+template<typename Acceptor , typename Dispatcher = dispatcher<>>
using packio::msgpack_rpc::server = ::packio::server< rpc, Acceptor, Dispatcher >
 The server for msgpack-RPC.
 
+ + + + + + + + +

+Functions

+template<typename Socket , template< class... > class Map = default_map>
auto packio::msgpack_rpc::make_client (Socket &&socket)
 The make_client function for msgpack-RPC.
 
+template<typename Acceptor , typename Dispatcher = dispatcher<>>
auto packio::msgpack_rpc::make_server (Acceptor &&acceptor)
 The make_server function for msgpack-RPC.
 

Detailed Description

-

msgpack-RPC related types and values

+

Typedefs and functions to use the msgpack-RPC protocol

diff --git a/docs/msgpack__rpc_8h_source.html b/docs/msgpack__rpc_8h_source.html index fb3f1e6..009c1fb 100644 --- a/docs/msgpack__rpc_8h_source.html +++ b/docs/msgpack__rpc_8h_source.html @@ -7,7 +7,7 @@ - packio: packio/internal/msgpack_rpc.h Source File + packio: packio/msgpack_rpc/msgpack_rpc.h Source File @@ -63,7 +63,7 @@
@@ -75,24 +75,53 @@
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4 
-
5 #ifndef PACKIO_MSGPACK_RPC_H
-
6 #define PACKIO_MSGPACK_RPC_H
+
5 #ifndef PACKIO_MSGPACK_RPC_MSGPACK_RPC_H
+
6 #define PACKIO_MSGPACK_RPC_MSGPACK_RPC_H
7 
10 
-
11 #include <cstdint>
-
12 
-
13 namespace packio {
+
11 #include "../client.h"
+
12 #include "../server.h"
+
13 #include "rpc.h"
14 
-
16 using id_type = uint32_t;
-
17 
-
18 enum class msgpack_rpc_type { request = 0, response = 1, notification = 2 };
+
17 namespace packio {
+
18 namespace msgpack_rpc {
19 
-
20 } // packio
-
21 
-
22 #endif // PACKIO_MSGPACK_RPC_H
+ +
22 
+
24 template <template <class...> class Map = default_map, typename Lockable = default_mutex>
+ +
26 
+
28 template <typename Socket, template <class...> class Map = default_map>
+ +
30 
+
32 template <typename Socket, template <class...> class Map = default_map>
+
33 auto make_client(Socket&& socket)
+
34 {
+
35  return std::make_shared<client<Socket, Map>>(std::forward<Socket>(socket));
+
36 }
+
37 
+
39 template <typename Acceptor, typename Dispatcher = dispatcher<>>
+ +
41 
+
43 template <typename Acceptor, typename Dispatcher = dispatcher<>>
+
44 auto make_server(Acceptor&& acceptor)
+
45 {
+
46  return std::make_shared<server<Acceptor, Dispatcher>>(
+
47  std::forward<Acceptor>(acceptor));
+
48 }
+
49 
+
50 } // msgpack_rpc
+
51 } // packio
+
52 
+
53 #endif // PACKIO_MSGPACK_RPC_MSGPACK_RPC_H
-
uint32_t id_type
Type used to store call IDs.
Definition: msgpack_rpc.h:16
-
Definition: as.h:16
+
The client class.
Definition: client.h:33
+
The server class.
Definition: server.h:27
+
completion_handler< rpc > completion_handler
The completion_handler for msgpack-RPC.
Definition: msgpack_rpc.h:21
+
dispatcher< rpc, Map, Lockable > dispatcher
The dispatcher for msgpack-RPC.
Definition: msgpack_rpc.h:25
+
Definition: arg.h:14
+
auto make_client(Socket &&socket)
The make_client function for msgpack-RPC.
Definition: msgpack_rpc.h:33
+
auto make_server(Acceptor &&acceptor)
The make_server function for msgpack-RPC.
Definition: msgpack_rpc.h:44
diff --git a/docs/namespacemembers.html b/docs/namespacemembers.html index 5bcb0a3..2445b31 100644 --- a/docs/namespacemembers.html +++ b/docs/namespacemembers.html @@ -64,20 +64,31 @@
Here is a list of all documented namespace members with links to the namespaces they belong to:
diff --git a/docs/namespacemembers_func.html b/docs/namespacemembers_func.html index 215d650..8acc8ca 100644 --- a/docs/namespacemembers_func.html +++ b/docs/namespacemembers_func.html @@ -64,14 +64,15 @@
 
diff --git a/docs/namespacemembers_type.html b/docs/namespacemembers_type.html index 9eb433f..af89042 100644 --- a/docs/namespacemembers_type.html +++ b/docs/namespacemembers_type.html @@ -64,8 +64,21 @@ diff --git a/docs/namespacepackio.html b/docs/namespacepackio.html index 15953f8..d39b748 100644 --- a/docs/namespacepackio.html +++ b/docs/namespacepackio.html @@ -64,15 +64,21 @@
packio Namespace Reference
+ + + + + +

+Namespaces

 msgpack_rpc
 
 nl_json_rpc
 
@@ -91,174 +97,27 @@

Classes

class  client
 The server_session class, created by the server. More...
 
- - - - -

-Typedefs

-using id_type = uint32_t
 Type used to store call IDs.
 
- - - - -

-Enumerations

enum  error {
-  error::success = 0, -error::error_during_call, -error::unknown_procedure, -error::cancelled, -
-  error::call_error, -error::bad_result_type -
- }
 The error codes enumeration. More...
 
- - - - - - - - - - - - - - - - + + + + + + + +

Functions

template<typename Result , typename AsCallHandler >
auto as (AsCallHandler &&handler, std::enable_if_t<!std::is_void_v< Result >, void * >=nullptr)
 Function used to wrap a typed call handler. More...
 
template<typename Result , typename AsVoidCallHandler >
auto as (AsVoidCallHandler &&handler, std::enable_if_t< std::is_void_v< Result >, void * >=nullptr)
 Function used to wrap a call handler that expects a void result. More...
 
template<typename Socket , template< class... > class Map = std::map>
auto make_client (Socket &&socket)
 Create a client from a socket. More...
 
template<typename Acceptor , typename Dispatcher = dispatcher<>>
auto make_server (Acceptor &&acceptor)
 Create a server from an acceptor. More...
 
template<typename Rpc , typename Socket , template< class... > class Map = default_map>
auto make_client (Socket &&socket)
 Create a client from a socket. More...
 
template<typename Rpc , typename Acceptor , typename Dispatcher = dispatcher<Rpc>>
auto make_server (Acceptor &&acceptor)
 Create a server from an acceptor. More...
 

Detailed Description

The packio namespace

-

Enumeration Type Documentation

- -

◆ error

- -
-
- - - - - -
- - - - -
enum packio::error
-
-strong
-
- -

The error codes enumeration.

- - - - - - - -
Enumerator
success 

Success.

-
error_during_call 

An error happened during the call, server-side error.

-
unknown_procedure 

The procedure name is unknown, server-side error.

-
cancelled 

The operation has been cancelled.

-
call_error 

An error happened during the call.

-
bad_result_type 

The result type is not as expected.

-
- -
-
-

Function Documentation

- -

◆ as() [1/2]

- -
-
-
-template<typename Result , typename AsCallHandler >
- - - - - - - - - - - - - - - - - - -
auto packio::as (AsCallHandler && handler,
std::enable_if_t<!std::is_void_v< Result >, void * >  = nullptr 
)
-
- -

Function used to wrap a typed call handler.

-

This function is used to provide a call handler that expects a specific return type. If the procedure call succeeds but the returned type is not what is expected, the handler will be called with error::bad_result_type. The optional given as second argument will have a value only if the error code is error::success.

-
Template Parameters
- - -
ResultThe expected return type for the procedure
-
-
-
Parameters
- - -
handlerCall handler to wrap. Must satisfy traits::AsCallHandler
-
-
- -
-
- -

◆ as() [2/2]

- -
-
-
-template<typename Result , typename AsVoidCallHandler >
- - - - - - - - - - - - - - - - - - -
auto packio::as (AsVoidCallHandler && handler,
std::enable_if_t< std::is_void_v< Result >, void * >  = nullptr 
)
-
- -

Function used to wrap a call handler that expects a void result.

-

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The only point of this wrapper is to verify that the remote procedure returned void. If the remote procedure returns any other type, this wrapper will set the error code to error::bad_result_type.

- -
-
- -

◆ make_client()

+

Function Documentation

+ +

◆ make_client()

-template<typename Socket , template< class... > class Map = std::map>
+template<typename Rpc , typename Socket , template< class... > class Map = default_map>
@@ -273,6 +132,7 @@

Template Parameters

auto packio::make_client
+
RpcRPC protocol implementation
SocketSocket type to use for this client
MapContainer used to associate call IDs and handlers
@@ -281,13 +141,13 @@

-

◆ make_server()

+ +

◆ make_server()

-template<typename Acceptor , typename Dispatcher = dispatcher<>>
+template<typename Rpc , typename Acceptor , typename Dispatcher = dispatcher<Rpc>>
@@ -302,6 +162,7 @@

Template Parameters

auto packio::make_server
+
RpcRPC protocol implementation
AcceptorAcceptor type to use for this server
DispatcherDispatcher used to store and dispatch procedures. See dispatcher
diff --git a/docs/namespacepackio_1_1msgpack.html b/docs/namespacepackio_1_1msgpack.html new file mode 100644 index 0000000..1794ef4 --- /dev/null +++ b/docs/namespacepackio_1_1msgpack.html @@ -0,0 +1,243 @@ + + + + + + + + + packio: packio::msgpack Namespace Reference + + + + + + + + + + +
+ +
+
packio::msgpack Namespace Reference
+
+
+ + + + + +

+Classes

class  rpc
 The msgpack RPC protocol implementation. More...
 
+ + + + + + + + + + + + +

+Typedefs

template<typename Socket , template< class... > class Map = default_map>
using client = ::packio::client< rpc, Socket, Map >
 The msgpack client class. More...
 
template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
using server = ::packio::server< rpc, Acceptor, Dispatcher >
 The msgpack server class. More...
 
using completion_handler = completion_handler< rpc >
 The completion_handler class. More...
 
+ + + + + + + + + +

+Functions

template<typename Socket , template< class... > class Map = default_map>
auto make_client (Socket &&socket)
 Create a msgpack client from a socket. More...
 
template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
auto make_server (Acceptor &&acceptor)
 Create a msgpack server from an acceptor. More...
 
+

Detailed Description

+

The packio::msgpack namespace contains the msgpack-RPC implementation

+

Typedef Documentation

+ +

◆ client

+ +
+
+
+template<typename Socket , template< class... > class Map = default_map>
+ + + + +
using packio::msgpack::client = typedef ::packio::client<rpc, Socket, Map>
+
+ +

The msgpack client class.

+
Template Parameters
+ + + +
SocketSocket type to use for this client
MapContainer used to associate call IDs and handlers
+
+
+ +
+
+ +

◆ completion_handler

+ +
+
+ +

The completion_handler class.

+

First argument of AsyncProcedure, the completion_handler is a callable used to notify the completion of an asynchronous procedure. You must only call set_value or set_error once.

+ +
+
+ +

◆ server

+ +
+
+
+template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
+ + + + +
using packio::msgpack::server = typedef ::packio::server<rpc, Acceptor, Dispatcher>
+
+ +

The msgpack server class.

+
Template Parameters
+ + + +
AcceptorAcceptor type to use for this server
DispatcherDispatcher used to store and dispatch procedures. See dispatcher
+
+
+ +
+
+

Function Documentation

+ +

◆ make_client()

+ +
+
+
+template<typename Socket , template< class... > class Map = default_map>
+ + + + + + + + +
auto packio::msgpack::make_client (Socket && socket)
+
+ +

Create a msgpack client from a socket.

+
Template Parameters
+ + + +
SocketSocket type to use for this client
MapContainer used to associate call IDs and handlers
+
+
+ +
+
+ +

◆ make_server()

+ +
+
+
+template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
+ + + + + + + + +
auto packio::msgpack::make_server (Acceptor && acceptor)
+
+ +

Create a msgpack server from an acceptor.

+
Template Parameters
+ + + +
AcceptorAcceptor type to use for this server
DispatcherDispatcher used to store and dispatch procedures. See dispatcher
+
+
+ +
+
+
+ + + + \ No newline at end of file diff --git a/docs/namespacepackio_1_1msgpack__rpc.html b/docs/namespacepackio_1_1msgpack__rpc.html new file mode 100644 index 0000000..30cbf4e --- /dev/null +++ b/docs/namespacepackio_1_1msgpack__rpc.html @@ -0,0 +1,126 @@ + + + + + + + + + packio: packio::msgpack_rpc Namespace Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc Namespace Reference
+
+
+ + + + + +

+Classes

class  rpc
 The msgpack RPC protocol implementation. More...
 
+ + + + + + + + + + + + + + + + +

+Typedefs

+using completion_handler = completion_handler< rpc >
 The completion_handler for msgpack-RPC.
 
+template<template< class... > class Map = default_map, typename Lockable = default_mutex>
using dispatcher = dispatcher< rpc, Map, Lockable >
 The dispatcher for msgpack-RPC.
 
+template<typename Socket , template< class... > class Map = default_map>
using client = ::packio::client< rpc, Socket, Map >
 The client for msgpack-RPC.
 
+template<typename Acceptor , typename Dispatcher = dispatcher<>>
using server = ::packio::server< rpc, Acceptor, Dispatcher >
 The server for msgpack-RPC.
 
+ + + + + + + + + +

+Functions

+template<typename Socket , template< class... > class Map = default_map>
auto make_client (Socket &&socket)
 The make_client function for msgpack-RPC.
 
+template<typename Acceptor , typename Dispatcher = dispatcher<>>
auto make_server (Acceptor &&acceptor)
 The make_server function for msgpack-RPC.
 
+

Detailed Description

+

The packio::msgpack_rpc namespace contains the msgpack-RPC implementation

+
+ + + + \ No newline at end of file diff --git a/docs/namespacepackio_1_1nl__json__rpc.html b/docs/namespacepackio_1_1nl__json__rpc.html new file mode 100644 index 0000000..ef19a93 --- /dev/null +++ b/docs/namespacepackio_1_1nl__json__rpc.html @@ -0,0 +1,126 @@ + + + + + + + + + packio: packio::nl_json_rpc Namespace Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc Namespace Reference
+
+
+ + + + + +

+Classes

class  rpc
 The JSON-RPC protocol implementation. More...
 
+ + + + + + + + + + + + + + + + +

+Typedefs

+using completion_handler = completion_handler< rpc >
 The completion_handler for JSON-RPC.
 
+template<template< class... > class Map = default_map, typename Lockable = default_mutex>
using dispatcher = dispatcher< rpc, Map, Lockable >
 The dispatcher for JSON-RPC.
 
+template<typename Socket , template< class... > class Map = default_map>
using client = ::packio::client< rpc, Socket, Map >
 The client for JSON-RPC.
 
+template<typename Acceptor , typename Dispatcher = dispatcher<>>
using server = ::packio::server< rpc, Acceptor, Dispatcher >
 The server for JSON-RPC.
 
+ + + + + + + + + +

+Functions

+template<typename Socket , template< class... > class Map = default_map>
auto make_client (Socket &&socket)
 The make_client function for JSON-RPC.
 
+template<typename Acceptor , typename Dispatcher = dispatcher<>>
auto make_server (Acceptor &&acceptor)
 The make_server function for JSON-RPC.
 
+

Detailed Description

+

The packio::nl_json_rpc namespace contains the JSON-RPC implementation based on the nlohmann::json library

+
+ + + + \ No newline at end of file diff --git a/docs/namespacepackio_1_1nlohmann__json.html b/docs/namespacepackio_1_1nlohmann__json.html new file mode 100644 index 0000000..dc3f4e3 --- /dev/null +++ b/docs/namespacepackio_1_1nlohmann__json.html @@ -0,0 +1,243 @@ + + + + + + + + + packio: packio::nlohmann_json Namespace Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nlohmann_json Namespace Reference
+
+
+ + + + + +

+Classes

class  rpc
 The JSON-RPC protocol implementation. More...
 
+ + + + + + + + + + + + +

+Typedefs

template<typename Socket , template< class... > class Map = default_map>
using client = ::packio::client< rpc, Socket, Map >
 The msgpack client class. More...
 
template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
using server = ::packio::server< rpc, Acceptor, Dispatcher >
 The msgpack server class. More...
 
using completion_handler = completion_handler< rpc >
 The completion_handler class. More...
 
+ + + + + + + + + +

+Functions

template<typename Socket , template< class... > class Map = default_map>
auto make_client (Socket &&socket)
 Create a msgpack client from a socket. More...
 
template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
auto make_server (Acceptor &&acceptor)
 Create a msgpack server from an acceptor. More...
 
+

Detailed Description

+

The packio::nlohmann_json namespace contains the JSON-RPC implementation based on the nlohmann::json library

+

Typedef Documentation

+ +

◆ client

+ +
+
+
+template<typename Socket , template< class... > class Map = default_map>
+ + + + +
using packio::nlohmann_json::client = typedef ::packio::client<rpc, Socket, Map>
+
+ +

The msgpack client class.

+
Template Parameters
+ + + +
SocketSocket type to use for this client
MapContainer used to associate call IDs and handlers
+
+
+ +
+
+ +

◆ completion_handler

+ +
+
+ +

The completion_handler class.

+

First argument of AsyncProcedure, the completion_handler is a callable used to notify the completion of an asynchronous procedure. You must only call set_value or set_error once.

+ +
+
+ +

◆ server

+ +
+
+
+template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
+ + + + +
using packio::nlohmann_json::server = typedef ::packio::server<rpc, Acceptor, Dispatcher>
+
+ +

The msgpack server class.

+
Template Parameters
+ + + +
AcceptorAcceptor type to use for this server
DispatcherDispatcher used to store and dispatch procedures. See dispatcher
+
+
+ +
+
+

Function Documentation

+ +

◆ make_client()

+ +
+
+
+template<typename Socket , template< class... > class Map = default_map>
+ + + + + + + + +
auto packio::nlohmann_json::make_client (Socket && socket)
+
+ +

Create a msgpack client from a socket.

+
Template Parameters
+ + + +
SocketSocket type to use for this client
MapContainer used to associate call IDs and handlers
+
+
+ +
+
+ +

◆ make_server()

+ +
+
+
+template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
+ + + + + + + + +
auto packio::nlohmann_json::make_server (Acceptor && acceptor)
+
+ +

Create a msgpack server from an acceptor.

+
Template Parameters
+ + + +
AcceptorAcceptor type to use for this server
DispatcherDispatcher used to store and dispatch procedures. See dispatcher
+
+
+ +
+
+
+ + + + \ No newline at end of file diff --git a/docs/namespaces.html b/docs/namespaces.html new file mode 100644 index 0000000..dd5f002 --- /dev/null +++ b/docs/namespaces.html @@ -0,0 +1,81 @@ + + + + + + + + + packio: Namespace List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
Namespace List
+
+
+
Here is a list of all documented namespaces with brief descriptions:
+
[detail level 12]
+ + + +
 Npackio
 Nmsgpack_rpc
 Nnl_json_rpc
+
+
+ + + + \ No newline at end of file diff --git a/docs/nl__json__rpc_2rpc_8h_source.html b/docs/nl__json__rpc_2rpc_8h_source.html new file mode 100644 index 0000000..ac22b6b --- /dev/null +++ b/docs/nl__json__rpc_2rpc_8h_source.html @@ -0,0 +1,452 @@ + + + + + + + + + packio: packio/nl_json_rpc/rpc.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
rpc.h
+
+
+
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_NL_JSON_RPC_RPC_H
+
6 #define PACKIO_NL_JSON_RPC_RPC_H
+
7 
+
8 #include <deque>
+
9 
+
10 #include <nlohmann/json.hpp>
+
11 
+
12 #include "../arg.h"
+
13 #include "../internal/config.h"
+
14 #include "../internal/log.h"
+
15 #include "../internal/rpc.h"
+
16 #include "incremental_buffers.h"
+
17 
+
18 namespace packio {
+
19 namespace nl_json_rpc {
+
20 namespace internal {
+
21 
+
22 template <typename... Args>
+
23 constexpr bool positional_args_v = (!is_arg_v<Args> && ...);
+
24 
+
25 template <typename... Args>
+
26 constexpr bool named_args_v = sizeof...(Args) > 0 && (is_arg_v<Args> && ...);
+
27 
+
28 using id_type = nlohmann::json;
+
29 using native_type = nlohmann::json;
+
30 
+
32 struct request {
+
33  call_type type;
+
34  internal::id_type id;
+
35  std::string method;
+
36  native_type args;
+
37 };
+
38 
+
40 struct response {
+
41  id_type id;
+
42  native_type result;
+
43  native_type error;
+
44 };
+
45 
+ +
48 public:
+
49  std::optional<request> get_request()
+
50  {
+
51  try_parse_object();
+
52  if (!parsed_) {
+
53  return std::nullopt;
+
54  }
+
55  auto object = std::move(*parsed_);
+
56  parsed_.reset();
+
57  return parse_request(std::move(object));
+
58  }
+
59 
+
60  std::optional<response> get_response()
+
61  {
+
62  try_parse_object();
+
63  if (!parsed_) {
+
64  return std::nullopt;
+
65  }
+
66  auto object = std::move(*parsed_);
+
67  parsed_.reset();
+
68  return parse_response(std::move(object));
+
69  }
+
70 
+
71  char* buffer()
+
72  { //
+
73  return incremental_buffers_.in_place_buffer();
+
74  }
+
75 
+
76  std::size_t buffer_capacity() const
+
77  { //
+
78  return incremental_buffers_.in_place_buffer_capacity();
+
79  }
+
80 
+
81  void buffer_consumed(std::size_t bytes)
+
82  { //
+
83  incremental_buffers_.in_place_buffer_consumed(bytes);
+
84  }
+
85 
+
86  void reserve_buffer(std::size_t bytes)
+
87  { //
+
88  incremental_buffers_.reserve_in_place_buffer(bytes);
+
89  }
+
90 
+
91 private:
+
92  void try_parse_object()
+
93  {
+
94  if (parsed_) {
+
95  return;
+
96  }
+
97  auto buffer = incremental_buffers_.get_parsed_buffer();
+
98  if (buffer) {
+
99  parsed_ = nlohmann::json::parse(*buffer);
+
100  }
+
101  }
+
102 
+
103  static std::optional<response> parse_response(nlohmann::json&& res)
+
104  {
+
105  auto id_it = res.find("id");
+
106  auto result_it = res.find("result");
+
107  auto error_it = res.find("error");
+
108 
+
109  if (id_it == end(res)) {
+
110  PACKIO_ERROR("missing id field");
+
111  return std::nullopt;
+
112  }
+
113  if (result_it == end(res) && error_it == end(res)) {
+
114  PACKIO_ERROR("missing error and result field");
+
115  return std::nullopt;
+
116  }
+
117 
+
118  std::optional<response> parsed{std::in_place};
+
119  parsed->id = std::move(*id_it);
+
120  if (error_it != end(res)) {
+
121  parsed->error = std::move(*error_it);
+
122  }
+
123  if (result_it != end(res)) {
+
124  parsed->result = std::move(*result_it);
+
125  }
+
126  return parsed;
+
127  }
+
128 
+
129  static std::optional<request> parse_request(nlohmann::json&& req)
+
130  {
+
131  auto id_it = req.find("id");
+
132  auto method_it = req.find("method");
+
133  auto params_it = req.find("params");
+
134 
+
135  if (method_it == end(req)) {
+
136  PACKIO_ERROR("missing method field");
+
137  return std::nullopt;
+
138  }
+
139  if (!method_it->is_string()) {
+
140  PACKIO_ERROR("method field is not a string");
+
141  return std::nullopt;
+
142  }
+
143 
+
144  std::optional<request> parsed{std::in_place};
+
145  parsed->method = method_it->get<std::string>();
+
146  if (params_it == end(req) || params_it->is_null()) {
+
147  parsed->args = nlohmann::json::array();
+
148  }
+
149  else if (!params_it->is_array() && !params_it->is_object()) {
+
150  PACKIO_ERROR("non-structured arguments are not supported");
+
151  return std::nullopt;
+
152  }
+
153  else {
+
154  parsed->args = std::move(*params_it);
+
155  }
+
156 
+
157  if (id_it == end(req) || id_it->is_null()) {
+
158  parsed->type = call_type::notification;
+
159  }
+
160  else {
+
161  parsed->type = call_type::request;
+
162  parsed->id = std::move(*id_it);
+
163  }
+
164  return parsed;
+
165  }
+
166 
+
167  std::optional<nlohmann::json> parsed_;
+
168  incremental_buffers incremental_buffers_;
+
169 };
+
170 
+
171 } // internal
+
172 
+
174 class rpc {
+
175 public:
+
177  using id_type = internal::id_type;
+
178 
+
180  using native_type = internal::native_type;
+
181 
+ +
184 
+ +
187 
+ +
190 
+
191  static std::string format_id(const id_type& id)
+
192  { //
+
193  return id.dump();
+
194  }
+
195 
+
196  template <typename... Args>
+
197  static auto serialize_notification(std::string_view method, Args&&... args)
+
198  -> std::enable_if_t<internal::positional_args_v<Args...>, std::string>
+
199  {
+
200  return nlohmann::json({
+
201  {"jsonrpc", "2.0"},
+
202  {"method", method},
+
203  {"params",
+
204  nlohmann::json::array({nlohmann::json(
+
205  std::forward<Args>(args))...})},
+
206  })
+
207  .dump();
+
208  }
+
209 
+
210  template <typename... Args>
+
211  static auto serialize_notification(std::string_view method, Args&&... args)
+
212  -> std::enable_if_t<internal::named_args_v<Args...>, std::string>
+
213  {
+
214  return nlohmann::json({
+
215  {"jsonrpc", "2.0"},
+
216  {"method", method},
+
217  {"params", {{args.name, args.value}...}},
+
218  })
+
219  .dump();
+
220  }
+
221 
+
222  template <typename... Args>
+
223  static auto serialize_notification(std::string_view, Args&&...) -> std::enable_if_t<
+
224  !internal::positional_args_v<Args...> && !internal::named_args_v<Args...>,
+
225  std::string>
+
226  {
+
227  static_assert(
+
228  internal::positional_args_v<Args...> || internal::named_args_v<Args...>,
+
229  "JSON-RPC does not support mixed named and unnamed arguments");
+
230  }
+
231 
+
232  template <typename... Args>
+
233  static auto serialize_request(
+
234  const id_type& id,
+
235  std::string_view method,
+
236  Args&&... args)
+
237  -> std::enable_if_t<internal::positional_args_v<Args...>, std::string>
+
238  {
+
239  return nlohmann::json({
+
240  {"jsonrpc", "2.0"},
+
241  {"method", method},
+
242  {"params",
+
243  nlohmann::json::array({nlohmann::json(
+
244  std::forward<Args>(args))...})},
+
245  {"id", id},
+
246  })
+
247  .dump();
+
248  }
+
249 
+
250  template <typename... Args>
+
251  static auto serialize_request(
+
252  const id_type& id,
+
253  std::string_view method,
+
254  Args&&... args)
+
255  -> std::enable_if_t<internal::named_args_v<Args...>, std::string>
+
256  {
+
257  return nlohmann::json({
+
258  {"jsonrpc", "2.0"},
+
259  {"method", method},
+
260  {"params", {{args.name, args.value}...}},
+
261  {"id", id},
+
262  })
+
263  .dump();
+
264  }
+
265 
+
266  template <typename... Args>
+
267  static auto serialize_request(const id_type&, std::string_view, Args&&...)
+
268  -> std::enable_if_t<
+
269  !internal::positional_args_v<Args...> && !internal::named_args_v<Args...>,
+
270  std::string>
+
271  {
+
272  static_assert(
+
273  internal::positional_args_v<Args...> || internal::named_args_v<Args...>,
+
274  "JSON-RPC does not support mixed named and unnamed arguments");
+
275  }
+
276 
+
277  static std::string serialize_response(const id_type& id)
+
278  {
+
279  return serialize_response(id, nlohmann::json{});
+
280  }
+
281 
+
282  template <typename T>
+
283  static std::string serialize_response(const id_type& id, T&& value)
+
284  {
+
285  return nlohmann::json{
+
286  {"jsonrpc", "2.0"},
+
287  {"id", id},
+
288  {"result", std::forward<T>(value)},
+
289  }
+
290  .dump();
+
291  }
+
292 
+
293  template <typename T>
+
294  static std::string serialize_error_response(const id_type& id, T&& value)
+
295  {
+
296  return nlohmann::json{
+
297  {"jsonrpc", "2.0"},
+
298  {"id", id},
+
299  {"error",
+
300  [&]() {
+
301  nlohmann::json error = {
+
302  {"code", -32000}, // -32000 is an implementation-defined error
+
303  {"data", std::forward<T>(value)},
+
304  };
+
305  if (error["data"].is_string()) {
+
306  error["message"] = error["data"];
+
307  }
+
308  else {
+
309  error["message"] = "Unknown error";
+
310  }
+
311  return error;
+
312  }()},
+
313  }
+
314  .dump();
+
315  }
+
316 
+
317  static net::const_buffer buffer(const std::string& buf)
+
318  {
+
319  return net::const_buffer(buf.data(), buf.size());
+
320  }
+
321 
+
322  template <typename T, typename NamesContainer>
+
323  static std::optional<T> extract_args(
+
324  const nlohmann::json& args,
+
325  const NamesContainer& names)
+
326  {
+
327  try {
+
328  if (args.is_array()) {
+
329  if (args.size() != std::tuple_size_v<T>) {
+
330  // keep this check otherwise the converter
+
331  // may silently drop arguments
+
332  PACKIO_WARN(
+
333  "cannot convert args: wrong number of arguments");
+
334  return std::nullopt;
+
335  }
+
336 
+
337  return args.get<T>();
+
338  }
+
339  else if (args.is_object()) {
+
340  return convert_named_args<T>(args, names);
+
341  }
+
342  else {
+
343  PACKIO_ERROR("arguments are not a structured type");
+
344  return std::nullopt;
+
345  }
+
346  }
+
347  catch (const std::exception& exc) {
+
348  PACKIO_WARN("cannot convert args: {}", exc.what());
+
349  (void)exc;
+
350  return std::nullopt;
+
351  }
+
352  }
+
353 
+
354 private:
+
355  template <typename T, typename NamesContainer>
+
356  static T convert_named_args(const nlohmann::json& args, const NamesContainer& names)
+
357  {
+
358  return convert_named_args<T>(
+
359  args, names, std::make_index_sequence<std::tuple_size_v<T>>{});
+
360  }
+
361 
+
362  template <typename T, typename NamesContainer, std::size_t... Idxs>
+
363  static T convert_named_args(
+
364  const nlohmann::json& args,
+
365  const NamesContainer& names,
+
366  std::index_sequence<Idxs...>)
+
367  {
+
368  return T{(args.at(names.at(Idxs))
+
369  .template get<std::tuple_element_t<Idxs, T>>())...};
+
370  }
+
371 };
+
372 
+
373 } // nl_json_rpc
+
374 } // packio
+
375 
+
376 #endif // PACKIO_NL_JSON_RPC_RPC_H
+
+
internal::native_type native_type
The native type of the serialization library.
Definition: rpc.h:180
+
The JSON-RPC protocol implementation.
Definition: rpc.h:174
+
The object representing the response to a call.
Definition: rpc.h:40
+
Definition: arg.h:14
+
The incremental parser for JSON-RPC objects.
Definition: rpc.h:47
+
The object representing a client request.
Definition: rpc.h:32
+
internal::id_type id_type
Type of the call ID.
Definition: rpc.h:177
+ + + + \ No newline at end of file diff --git a/docs/nl__json__rpc_8h.html b/docs/nl__json__rpc_8h.html new file mode 100644 index 0000000..4f10e26 --- /dev/null +++ b/docs/nl__json__rpc_8h.html @@ -0,0 +1,132 @@ + + + + + + + + + packio: packio/nl_json_rpc/nl_json_rpc.h File Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
nl_json_rpc.h File Reference
+
+
+
#include "../client.h"
+#include "../server.h"
+#include "rpc.h"
+
+

Go to the source code of this file.

+ + + + + + +

+Namespaces

 packio::nl_json_rpc
 
 packio
 
+ + + + + + + + + + + + + + + + +

+Typedefs

+using packio::nl_json_rpc::completion_handler = completion_handler< rpc >
 The completion_handler for JSON-RPC.
 
+template<template< class... > class Map = default_map, typename Lockable = default_mutex>
using packio::nl_json_rpc::dispatcher = dispatcher< rpc, Map, Lockable >
 The dispatcher for JSON-RPC.
 
+template<typename Socket , template< class... > class Map = default_map>
using packio::nl_json_rpc::client = ::packio::client< rpc, Socket, Map >
 The client for JSON-RPC.
 
+template<typename Acceptor , typename Dispatcher = dispatcher<>>
using packio::nl_json_rpc::server = ::packio::server< rpc, Acceptor, Dispatcher >
 The server for JSON-RPC.
 
+ + + + + + + + + +

+Functions

+template<typename Socket , template< class... > class Map = default_map>
auto packio::nl_json_rpc::make_client (Socket &&socket)
 The make_client function for JSON-RPC.
 
+template<typename Acceptor , typename Dispatcher = dispatcher<>>
auto packio::nl_json_rpc::make_server (Acceptor &&acceptor)
 The make_server function for JSON-RPC.
 
+

Detailed Description

+

Typedefs and functions to use the JSON-RPC protocol based on the nlohmann::json library

+
+ + + + \ No newline at end of file diff --git a/docs/nl__json__rpc_8h_source.html b/docs/nl__json__rpc_8h_source.html new file mode 100644 index 0000000..2d7fcb7 --- /dev/null +++ b/docs/nl__json__rpc_8h_source.html @@ -0,0 +1,128 @@ + + + + + + + + + packio: packio/nl_json_rpc/nl_json_rpc.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
nl_json_rpc.h
+
+
+Go to the documentation of this file.
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_NL_JSON_RPC_NL_JSON_RPC_H
+
6 #define PACKIO_NL_JSON_RPC_NL_JSON_RPC_H
+
7 
+
11 
+
12 #include "../client.h"
+
13 #include "../server.h"
+
14 #include "rpc.h"
+
15 
+
19 namespace packio {
+
20 namespace nl_json_rpc {
+
21 
+ +
24 
+
26 template <template <class...> class Map = default_map, typename Lockable = default_mutex>
+ +
28 
+
30 template <typename Socket, template <class...> class Map = default_map>
+ +
32 
+
34 template <typename Socket, template <class...> class Map = default_map>
+
35 auto make_client(Socket&& socket)
+
36 {
+
37  return std::make_shared<client<Socket, Map>>(std::forward<Socket>(socket));
+
38 }
+
39 
+
41 template <typename Acceptor, typename Dispatcher = dispatcher<>>
+ +
43 
+
45 template <typename Acceptor, typename Dispatcher = dispatcher<>>
+
46 auto make_server(Acceptor&& acceptor)
+
47 {
+
48  return std::make_shared<server<Acceptor, Dispatcher>>(
+
49  std::forward<Acceptor>(acceptor));
+
50 }
+
51 
+
52 } // nl_json_rpc
+
53 } // packio
+
54 
+
55 #endif // PACKIO_NL_JSON_RPC_NL_JSON_RPC_H
+
+
The client class.
Definition: client.h:33
+
completion_handler< rpc > completion_handler
The completion_handler for JSON-RPC.
Definition: nl_json_rpc.h:23
+
The server class.
Definition: server.h:27
+
auto make_client(Socket &&socket)
The make_client function for JSON-RPC.
Definition: nl_json_rpc.h:35
+
dispatcher< rpc, Map, Lockable > dispatcher
The dispatcher for JSON-RPC.
Definition: nl_json_rpc.h:27
+
Definition: arg.h:14
+
auto make_server(Acceptor &&acceptor)
The make_server function for JSON-RPC.
Definition: nl_json_rpc.h:46
+ + + + \ No newline at end of file diff --git a/docs/nlohmann__json_2rpc_8h_source.html b/docs/nlohmann__json_2rpc_8h_source.html new file mode 100644 index 0000000..0e46d09 --- /dev/null +++ b/docs/nlohmann__json_2rpc_8h_source.html @@ -0,0 +1,440 @@ + + + + + + + + + packio: packio/nlohmann_json/rpc.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
rpc.h
+
+
+
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_NLOHMANN_JSON_RPC_H
+
6 #define PACKIO_NLOHMANN_JSON_RPC_H
+
7 
+
8 #include <deque>
+
9 
+
10 #include <nlohmann/json.hpp>
+
11 
+
12 #include "../arg.h"
+
13 #include "../internal/config.h"
+
14 #include "../internal/log.h"
+
15 #include "../internal/rpc.h"
+
16 #include "incremental_buffers.h"
+
17 
+
18 namespace packio::nlohmann_json {
+
19 
+
20 template <typename... Args>
+
21 constexpr bool positional_args_v = (!is_arg_v<Args> && ...);
+
22 
+
23 template <typename... Args>
+
24 constexpr bool named_args_v = sizeof...(Args) > 0 && (is_arg_v<Args> && ...);
+
25 
+
27 class rpc {
+
28  using buffer_type = std::string;
+
29 
+
30 public:
+
32  using id_type = nlohmann::json;
+
33 
+
35  struct request {
+
36  call_type type;
+
37  id_type id;
+
38  std::string method;
+
39  nlohmann::json args;
+
40  };
+
41 
+
43  struct response {
+
44  id_type id;
+
45  nlohmann::json result;
+
46  nlohmann::json error;
+
47  };
+
48 
+
49  class incremental_parser {
+
50  public:
+
51  std::optional<request> get_request()
+
52  {
+
53  try_parse_object();
+
54  if (!parsed_) {
+
55  return std::nullopt;
+
56  }
+
57  auto object = std::move(*parsed_);
+
58  parsed_.reset();
+
59  return parse_request(std::move(object));
+
60  }
+
61 
+
62  std::optional<response> get_response()
+
63  {
+
64  try_parse_object();
+
65  if (!parsed_) {
+
66  return std::nullopt;
+
67  }
+
68  auto object = std::move(*parsed_);
+
69  parsed_.reset();
+
70  return parse_response(std::move(object));
+
71  }
+
72 
+
73  char* buffer()
+
74  { //
+
75  return buffer_.data();
+
76  }
+
77 
+
78  std::size_t buffer_capacity() const
+
79  { //
+
80  return buffer_.size();
+
81  }
+
82 
+
83  void buffer_consumed(std::size_t bytes)
+
84  {
+
85  if (bytes == 0) {
+
86  return;
+
87  }
+
88  incremental_buffers_.feed(std::string_view(buffer_.data(), bytes));
+
89  std::copy(begin(buffer_) + bytes, end(buffer_), begin(buffer_));
+
90  buffer_.resize(buffer_.size() - bytes);
+
91  }
+
92 
+
93  void reserve_buffer(std::size_t bytes)
+
94  {
+
95  if (buffer_.size() >= bytes) {
+
96  return;
+
97  }
+
98  buffer_.resize(bytes);
+
99  }
+
100 
+
101  private:
+
102  void try_parse_object()
+
103  {
+
104  if (parsed_) {
+
105  return;
+
106  }
+
107  auto buffer = incremental_buffers_.get_buffer();
+
108  if (buffer) {
+
109  parsed_ = nlohmann::json::parse(*buffer);
+
110  }
+
111  }
+
112 
+
113  std::vector<char> buffer_;
+
114  std::optional<nlohmann::json> parsed_;
+
115  incremental_buffers incremental_buffers_;
+
116  };
+
117 
+
118  static std::string format_id(const id_type& id)
+
119  { //
+
120  return id.dump();
+
121  }
+
122 
+
123  template <typename... Args>
+
124  static auto serialize_notification(std::string_view method, Args&&... args)
+
125  -> std::enable_if_t<positional_args_v<Args...>, buffer_type>
+
126  {
+
127  return nlohmann::json({
+
128  {"jsonrpc", "2.0"},
+
129  {"method", method},
+
130  {"params",
+
131  nlohmann::json::array({nlohmann::json(
+
132  std::forward<Args>(args))...})},
+
133  })
+
134  .dump();
+
135  }
+
136 
+
137  template <typename... Args>
+
138  static auto serialize_notification(std::string_view method, Args&&... args)
+
139  -> std::enable_if_t<named_args_v<Args...>, buffer_type>
+
140  {
+
141  return nlohmann::json({
+
142  {"jsonrpc", "2.0"},
+
143  {"method", method},
+
144  {"params", {{args.name, args.value}...}},
+
145  })
+
146  .dump();
+
147  }
+
148 
+
149  template <typename... Args>
+
150  static auto serialize_notification(std::string_view, Args&&...)
+
151  -> std::enable_if_t<!positional_args_v<Args...> && !named_args_v<Args...>, buffer_type>
+
152  {
+
153  static_assert(
+
154  positional_args_v<Args...> || named_args_v<Args...>,
+
155  "JSON-RPC does not support mixed named and unnamed arguments");
+
156  }
+
157 
+
158  template <typename... Args>
+
159  static auto serialize_request(id_type id, std::string_view method, Args&&... args)
+
160  -> std::enable_if_t<positional_args_v<Args...>, buffer_type>
+
161  {
+
162  return nlohmann::json({
+
163  {"jsonrpc", "2.0"},
+
164  {"method", method},
+
165  {"params",
+
166  nlohmann::json::array({nlohmann::json(
+
167  std::forward<Args>(args))...})},
+
168  {"id", id},
+
169  })
+
170  .dump();
+
171  }
+
172 
+
173  template <typename... Args>
+
174  static auto serialize_request(id_type id, std::string_view method, Args&&... args)
+
175  -> std::enable_if_t<named_args_v<Args...>, buffer_type>
+
176  {
+
177  return nlohmann::json({
+
178  {"jsonrpc", "2.0"},
+
179  {"method", method},
+
180  {"params", {{args.name, args.value}...}},
+
181  {"id", id},
+
182  })
+
183  .dump();
+
184  }
+
185 
+
186  template <typename... Args>
+
187  static auto serialize_request(id_type, std::string_view, Args&&...)
+
188  -> std::enable_if_t<!positional_args_v<Args...> && !named_args_v<Args...>, buffer_type>
+
189  {
+
190  static_assert(
+
191  positional_args_v<Args...> || named_args_v<Args...>,
+
192  "JSON-RPC does not support mixed named and unnamed arguments");
+
193  }
+
194 
+
195  template <typename... Args>
+
196  static auto serialize_response(response response)
+
197  {
+
198  nlohmann::json resp = {
+
199  {"jsonrpc", "2.0"},
+
200  {"id", response.id},
+
201  };
+
202  if (!response.error.is_null()) {
+
203  resp["error"] = std::move(response.error);
+
204  }
+
205  else {
+
206  resp["result"] = std::move(response.result);
+
207  }
+
208  return resp.dump();
+
209  }
+
210 
+
211  static net::const_buffer buffer(const buffer_type& buf)
+
212  {
+
213  return net::const_buffer(buf.data(), buf.size());
+
214  }
+
215 
+
216  template <typename T, typename NamesContainer>
+
217  static std::optional<T> extract_args(
+
218  const nlohmann::json& args,
+
219  const NamesContainer& names)
+
220  {
+
221  try {
+
222  if (args.is_array()) {
+
223  if (args.size() != std::tuple_size_v<T>) {
+
224  // keep this check otherwise the converter
+
225  // may silently drop arguments
+
226  PACKIO_WARN(
+
227  "cannot convert args: wrong number of arguments");
+
228  return std::nullopt;
+
229  }
+
230 
+
231  return args.get<T>();
+
232  }
+
233  else if (args.is_object()) {
+
234  return convert_named_args<T>(
+
235  args, names, std::make_index_sequence<std::tuple_size_v<T>>{});
+
236  }
+
237  else {
+
238  PACKIO_ERROR("arguments are not a structured type");
+
239  return std::nullopt;
+
240  }
+
241  }
+
242  catch (const std::exception& exc) {
+
243  PACKIO_WARN("cannot convert args: {}", exc.what());
+
244  return std::nullopt;
+
245  }
+
246  }
+
247 
+
248  static response make_response(id_type id)
+
249  {
+
250  return make_response(id, nlohmann::json{});
+
251  }
+
252 
+
253  template <typename T>
+
254  static response make_response(id_type id, T&& value)
+
255  {
+
256  response resp;
+
257  resp.id = id;
+
258  resp.result = std::forward<T>(value);
+
259  return resp;
+
260  }
+
261 
+
262  template <typename T>
+
263  static response make_error_response(id_type id, T&& value)
+
264  {
+
265  response resp;
+
266  resp.id = id;
+
267  resp.error = [&]() {
+
268  nlohmann::json error = {
+
269  {"code", -32000}, // -32000 is an implementation-defined error
+
270  {"data", std::forward<T>(value)},
+
271  };
+
272  if (error["data"].is_string()) {
+
273  error["message"] = error["data"];
+
274  }
+
275  else {
+
276  error["message"] = "Unknown error";
+
277  }
+
278  return error;
+
279  }();
+
280  return resp;
+
281  }
+
282 
+
283 private:
+
284  template <typename T, typename NamesContainer, std::size_t... Idxs>
+
285  static T convert_named_args(
+
286  const nlohmann::json& args,
+
287  const NamesContainer& names,
+
288  std::index_sequence<Idxs...>)
+
289  {
+
290  return T{(
+
291  args[names.at(Idxs)].template get<std::tuple_element_t<Idxs, T>>())...};
+
292  }
+
293 
+
294  static std::optional<response> parse_response(nlohmann::json&& res)
+
295  {
+
296  auto id_it = res.find("id");
+
297  auto result_it = res.find("result");
+
298  auto error_it = res.find("error");
+
299 
+
300  if (id_it == end(res)) {
+
301  PACKIO_ERROR("missing id field");
+
302  return std::nullopt;
+
303  }
+
304  if (result_it == end(res) && error_it == end(res)) {
+
305  PACKIO_ERROR("missing error and result field");
+
306  return std::nullopt;
+
307  }
+
308 
+
309  response parsed;
+
310  parsed.id = std::move(*id_it);
+
311  if (error_it != end(res)) {
+
312  parsed.error = std::move(*error_it);
+
313  }
+
314  if (result_it != end(res)) {
+
315  parsed.result = std::move(*result_it);
+
316  }
+
317  return parsed;
+
318  }
+
319 
+
320  static std::optional<request> parse_request(nlohmann::json&& req)
+
321  {
+
322  auto id_it = req.find("id");
+
323  auto method_it = req.find("method");
+
324  auto params_it = req.find("params");
+
325 
+
326  if (method_it == end(req)) {
+
327  PACKIO_ERROR("missing method field");
+
328  return std::nullopt;
+
329  }
+
330  if (!method_it->is_string()) {
+
331  PACKIO_ERROR("method field is not a string");
+
332  return std::nullopt;
+
333  }
+
334 
+
335  request parsed;
+
336  parsed.method = method_it->get<std::string>();
+
337  if (params_it == end(req) || params_it->is_null()) {
+
338  parsed.args = nlohmann::json::array();
+
339  }
+
340  else if (!params_it->is_array() && !params_it->is_object()) {
+
341  PACKIO_ERROR("non-structured arguments are not supported");
+
342  return std::nullopt;
+
343  }
+
344  else {
+
345  parsed.args = std::move(*params_it);
+
346  }
+
347 
+
348  if (id_it == end(req) || id_it->is_null()) {
+
349  parsed.type = call_type::notification;
+
350  }
+
351  else {
+
352  parsed.type = call_type::request;
+
353  parsed.id = std::move(*id_it);
+
354  }
+
355  return parsed;
+
356  }
+
357 };
+
358 
+
359 } // packio::nlohmann_json
+
360 
+
361 #endif // PACKIO_NLOHMAANN_JSON_RPC_H
+
+
nlohmann::json id_type
Type of the call ID.
Definition: rpc.h:32
+
The JSON-RPC protocol implementation.
Definition: rpc.h:27
+
Definition: incremental_buffers.h:13
+
The object representing the response to a call.
Definition: rpc.h:43
+
The object representing a client request.
Definition: rpc.h:35
+ + + + \ No newline at end of file diff --git a/docs/nlohmann__json_8h.html b/docs/nlohmann__json_8h.html new file mode 100644 index 0000000..0fe92d9 --- /dev/null +++ b/docs/nlohmann__json_8h.html @@ -0,0 +1,122 @@ + + + + + + + + + packio: packio/nlohmann_json/nlohmann_json.h File Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
nlohmann_json.h File Reference
+
+
+
#include "../client.h"
+#include "../server.h"
+#include "rpc.h"
+
+

Go to the source code of this file.

+ + + + + + +

+Namespaces

 packio::nlohmann_json
 
 packio
 
+ + + + + + + + + + + + +

+Typedefs

template<typename Socket , template< class... > class Map = default_map>
using packio::nlohmann_json::client = ::packio::client< rpc, Socket, Map >
 The msgpack client class. More...
 
template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
using packio::nlohmann_json::server = ::packio::server< rpc, Acceptor, Dispatcher >
 The msgpack server class. More...
 
using packio::nlohmann_json::completion_handler = completion_handler< rpc >
 The completion_handler class. More...
 
+ + + + + + + + + +

+Functions

template<typename Socket , template< class... > class Map = default_map>
auto packio::nlohmann_json::make_client (Socket &&socket)
 Create a msgpack client from a socket. More...
 
template<typename Acceptor , typename Dispatcher = dispatcher<rpc>>
auto packio::nlohmann_json::make_server (Acceptor &&acceptor)
 Create a msgpack server from an acceptor. More...
 
+

Detailed Description

+

Typedefs and functions to use the JSON-RPC protocol based on the nlohmann::json library

+
+ + + + \ No newline at end of file diff --git a/docs/nlohmann__json_8h_source.html b/docs/nlohmann__json_8h_source.html new file mode 100644 index 0000000..37de47b --- /dev/null +++ b/docs/nlohmann__json_8h_source.html @@ -0,0 +1,122 @@ + + + + + + + + + packio: packio/nlohmann_json/nlohmann_json.h Source File + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
nlohmann_json.h
+
+
+Go to the documentation of this file.
1 // This Source Code Form is subject to the terms of the Mozilla Public
+
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
+
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
4 
+
5 #ifndef PACKIO_NLOHMANN_JSON_NLOHMANN_JSON_H
+
6 #define PACKIO_NLOHMANN_JSON_NLOHMANN_JSON_H
+
7 
+
11 
+
12 #include "../client.h"
+
13 #include "../server.h"
+
14 #include "rpc.h"
+
15 
+
19 namespace packio::nlohmann_json {
+
20 
+
24 template <typename Socket, template <class...> class Map = default_map>
+ +
26 
+
30 template <typename Socket, template <class...> class Map = default_map>
+
31 auto make_client(Socket&& socket)
+
32 {
+
33  return std::make_shared<client<Socket, Map>>(std::forward<Socket>(socket));
+
34 }
+
35 
+
39 template <typename Acceptor, typename Dispatcher = dispatcher<rpc>>
+ +
41 
+
45 template <typename Acceptor, typename Dispatcher = dispatcher<rpc>>
+
46 auto make_server(Acceptor&& acceptor)
+
47 {
+
48  return std::make_shared<server<Acceptor, Dispatcher>>(
+
49  std::forward<Acceptor>(acceptor));
+
50 }
+
51 
+ +
59 
+
60 } // packio::nlohmann_json
+
61 
+
62 #endif // PACKIO_NLOHMANN_JSON_NLOHMANN_JSON_H
+
+
The client class.
Definition: client.h:34
+
The server class.
Definition: server.h:27
+
Definition: incremental_buffers.h:13
+
completion_handler< rpc > completion_handler
The completion_handler class.
Definition: nlohmann_json.h:58
+
auto make_server(Acceptor &&acceptor)
Create a msgpack server from an acceptor.
Definition: nlohmann_json.h:46
+
auto make_client(Socket &&socket)
Create a msgpack client from a socket.
Definition: nlohmann_json.h:31
+ + + + \ No newline at end of file diff --git a/docs/packio_8h.html b/docs/packio_8h.html index e1ed41e..c38a6ef 100644 --- a/docs/packio_8h.html +++ b/docs/packio_8h.html @@ -73,10 +73,10 @@
packio.h File Reference
-
#include "as.h"
+
#include "internal/config.h"
+#include "arg.h"
#include "client.h"
#include "dispatcher.h"
-#include "error_code.h"
#include "handler.h"
#include "server.h"
diff --git a/docs/packio_8h_source.html b/docs/packio_8h_source.html index 48ea019..3cbd3d1 100644 --- a/docs/packio_8h_source.html +++ b/docs/packio_8h_source.html @@ -75,19 +75,29 @@
2 #define PACKIO_PACKIO_H
3 
10 
-
11 #include "as.h"
-
12 #include "client.h"
-
13 #include "dispatcher.h"
-
14 #include "error_code.h"
-
15 #include "handler.h"
-
16 #include "server.h"
-
17 
-
18 #endif // PACKIO_PACKIO_H
+
11 #include "internal/config.h"
+
12 
+
13 #include "arg.h"
+
14 #include "client.h"
+
15 #include "dispatcher.h"
+
16 #include "handler.h"
+
17 #include "server.h"
+
18 
+
19 #if PACKIO_HAS_MSGPACK
+ +
21 #endif // PACKIO_HAS_MSGPACK
+
22 
+
23 #if PACKIO_HAS_NLOHMANN_JSON
+ +
25 #endif // PACKIO_HAS_NLOHMANN_JSON
+
26 
+
27 #endif // PACKIO_PACKIO_H
- + - + + diff --git a/docs/search/all_0.js b/docs/search/all_0.js index f35173b..4737e26 100644 --- a/docs/search/all_0.js +++ b/docs/search/all_0.js @@ -1,17 +1,15 @@ var searchData= [ - ['acceptor_0',['acceptor',['../classpackio_1_1server.html#a5be66852826d65711c095751a6b92b99',1,'packio::server::acceptor()'],['../classpackio_1_1server.html#a900e9e9a37cb109c4c330795e5f83639',1,'packio::server::acceptor() const']]], - ['acceptor_5ftype_1',['acceptor_type',['../classpackio_1_1server.html#a4bcd39b0d3f5a297e476382b97402707',1,'packio::server']]], - ['add_2',['add',['../classpackio_1_1dispatcher.html#aff6c4d31f265b4590f62122e9b2548a0',1,'packio::dispatcher']]], - ['add_5fasync_3',['add_async',['../classpackio_1_1dispatcher.html#a5411e4849d5a68bc42cb5ca18dda1512',1,'packio::dispatcher']]], - ['add_5fcoro_4',['add_coro',['../classpackio_1_1dispatcher.html#a545e8e11ba04410246d8d03da4979787',1,'packio::dispatcher::add_coro(std::string_view name, const Executor &executor, CoroProcedure &&coro)'],['../classpackio_1_1dispatcher.html#a33b17f8c33362361f5cd0b1ce0f5a1d7',1,'packio::dispatcher::add_coro(std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)']]], - ['as_5',['as',['../namespacepackio.html#a98ec735bfe5e3655f1e398f9f8c122bc',1,'packio::as(AsCallHandler &&handler, std::enable_if_t<!std::is_void_v< Result >, void * >=nullptr)'],['../namespacepackio.html#a96d591f155009301646e3827cc3e4f14',1,'packio::as(AsVoidCallHandler &&handler, std::enable_if_t< std::is_void_v< Result >, void * >=nullptr)']]], - ['as_2eh_6',['as.h',['../as_8h.html',1,'']]], - ['ascallhandler_7',['AsCallHandler',['../structpackio_1_1traits_1_1AsCallHandler.html',1,'packio::traits']]], - ['asvoidcallhandler_8',['AsVoidCallHandler',['../structpackio_1_1traits_1_1AsVoidCallHandler.html',1,'packio::traits']]], - ['async_5fcall_9',['async_call',['../classpackio_1_1client.html#a05f979924252b2c34d4b256a45ee0a7c',1,'packio::client::async_call(std::string_view name, const std::tuple< Args... > &args, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)'],['../classpackio_1_1client.html#a08881f94b175afdf8d30f5af0e1f8457',1,'packio::client::async_call(std::string_view name, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)']]], - ['async_5fnotify_10',['async_notify',['../classpackio_1_1client.html#ac95f66e17622014663e9896eb7f990a2',1,'packio::client::async_notify(std::string_view name, const std::tuple< Args... > &args, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))'],['../classpackio_1_1client.html#ae29fe2a9b0a6c2b513db9302a0645611',1,'packio::client::async_notify(std::string_view name, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))']]], - ['async_5fserve_11',['async_serve',['../classpackio_1_1server.html#a0703bbd27e5b81c59e250f4fbb3cf50b',1,'packio::server']]], - ['async_5fserve_5fforever_12',['async_serve_forever',['../classpackio_1_1server.html#a03b47a89b17d09fef03b1a4bc391c5f5',1,'packio::server']]], - ['asyncprocedure_13',['AsyncProcedure',['../structpackio_1_1traits_1_1AsyncProcedure.html',1,'packio::traits']]] + ['acceptor_0',['acceptor',['../classpackio_1_1server.html#acd3378e8bb5df14f3669e630555ff3cc',1,'packio::server::acceptor()'],['../classpackio_1_1server.html#a05eaaffba89e22806be336415a2f2382',1,'packio::server::acceptor() const']]], + ['acceptor_5ftype_1',['acceptor_type',['../classpackio_1_1server.html#a07df9eaed3acb33686a40869f3e0a341',1,'packio::server']]], + ['add_2',['add',['../classpackio_1_1dispatcher.html#a9d5652505ffd5127cffe1619fb7c4a71',1,'packio::dispatcher::add(std::string_view name, const std::array< std::string, N > &arguments_names, SyncProcedure &&fct)'],['../classpackio_1_1dispatcher.html#a98c5d9dcb0820ca336cc2859e82162fe',1,'packio::dispatcher::add(std::string_view name, SyncProcedure &&fct)']]], + ['add_5fasync_3',['add_async',['../classpackio_1_1dispatcher.html#a287a41488fdc9421da77a68fe1e49846',1,'packio::dispatcher::add_async(std::string_view name, const std::array< std::string, N > &arguments_names, AsyncProcedure &&fct)'],['../classpackio_1_1dispatcher.html#a18d6db12264390103c687955aebd05f2',1,'packio::dispatcher::add_async(std::string_view name, AsyncProcedure &&fct)']]], + ['add_5fcoro_4',['add_coro',['../classpackio_1_1dispatcher.html#a2545f945918bff8f4bc0b1a63df0f898',1,'packio::dispatcher::add_coro(std::string_view name, const Executor &executor, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)'],['../classpackio_1_1dispatcher.html#a69b32ee4c046b818c1c11523eb1f93e7',1,'packio::dispatcher::add_coro(std::string_view name, const Executor &executor, CoroProcedure &&coro)'],['../classpackio_1_1dispatcher.html#a8fdb50ef2822589c1e80b35c9c7fbed5',1,'packio::dispatcher::add_coro(std::string_view name, ExecutionContext &ctx, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)'],['../classpackio_1_1dispatcher.html#a04ba29e0c1b3d13e7e565ea0fc224ca3',1,'packio::dispatcher::add_coro(std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)']]], + ['arg_2eh_5',['arg.h',['../arg_8h.html',1,'']]], + ['args_5ftype_6',['args_type',['../classpackio_1_1dispatcher.html#abaf51d5af8c29af5e198d9a6a2272a0d',1,'packio::dispatcher']]], + ['async_5fcall_7',['async_call',['../classpackio_1_1client.html#ac1f59f8f7daef410bb52c69c32d918d9',1,'packio::client::async_call(std::string_view name, ArgsTuple &&args, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)'],['../classpackio_1_1client.html#aab82f7ebe33c7e33e3fbdad0f0c5a969',1,'packio::client::async_call(std::string_view name, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)']]], + ['async_5fnotify_8',['async_notify',['../classpackio_1_1client.html#ac4f5950217f8977497b872f7a2fd0d36',1,'packio::client::async_notify(std::string_view name, ArgsTuple &&args, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())'],['../classpackio_1_1client.html#aac8c2e52f17c577d6bb002a8bfc119d9',1,'packio::client::async_notify(std::string_view name, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())']]], + ['async_5fserve_9',['async_serve',['../classpackio_1_1server.html#a36cbd8c2767ca32a86dce40d40e95e3f',1,'packio::server']]], + ['async_5fserve_5fforever_10',['async_serve_forever',['../classpackio_1_1server.html#a6a8930268e678fc7d6809cf55a9831a4',1,'packio::server']]], + ['asyncprocedure_11',['AsyncProcedure',['../structpackio_1_1traits_1_1AsyncProcedure.html',1,'packio::traits']]] ]; diff --git a/docs/search/all_1.js b/docs/search/all_1.js index ae46a44..1154fb7 100644 --- a/docs/search/all_1.js +++ b/docs/search/all_1.js @@ -1,4 +1,10 @@ var searchData= [ - ['bad_5fresult_5ftype_14',['bad_result_type',['../namespacepackio.html#ad0fad01adc607b1ef672314d1ed01809a3421ef6eef824d84f3ff3170d051ef80',1,'packio']]] + ['callhandler_12',['CallHandler',['../structpackio_1_1traits_1_1CallHandler.html',1,'packio::traits']]], + ['cancel_13',['cancel',['../classpackio_1_1client.html#ac0b565e42875e83d6f913c95a65a3999',1,'packio::client::cancel(id_type id)'],['../classpackio_1_1client.html#a803c9c74259f6ab0845a4732cf92a854',1,'packio::client::cancel()']]], + ['clear_14',['clear',['../classpackio_1_1dispatcher.html#a36d55afaa13d51008125d08cbaab77cb',1,'packio::dispatcher']]], + ['client_15',['client',['../classpackio_1_1client.html',1,'packio::client< Rpc, Socket, Map >'],['../classpackio_1_1client.html#a7e885325ce598f29878a22d9b9253829',1,'packio::client::client()'],['../namespacepackio_1_1msgpack__rpc.html#a49d32a81a0e25f0afd20c06b0f3be038',1,'packio::msgpack_rpc::client()'],['../namespacepackio_1_1nl__json__rpc.html#aee1e8414a3dbc89c9b65f51be2cd267e',1,'packio::nl_json_rpc::client()']]], + ['client_2eh_16',['client.h',['../client_8h.html',1,'']]], + ['completion_5fhandler_17',['completion_handler',['../classpackio_1_1completion__handler.html',1,'packio::completion_handler< Rpc >'],['../classpackio_1_1completion__handler.html#a3ab1ed2afc9e16de0f6d31afa5c42a05',1,'packio::completion_handler::completion_handler()'],['../namespacepackio_1_1msgpack__rpc.html#a5f26747f38ee4b858478d242f2d1fb93',1,'packio::msgpack_rpc::completion_handler()'],['../namespacepackio_1_1nl__json__rpc.html#a00239c9c3a310e25dc8641e5056815e9',1,'packio::nl_json_rpc::completion_handler()']]], + ['coroprocedure_18',['CoroProcedure',['../structpackio_1_1traits_1_1CoroProcedure.html',1,'packio::traits']]] ]; diff --git a/docs/search/all_10.js b/docs/search/all_10.js index e3b92b2..ed0fd1d 100644 --- a/docs/search/all_10.js +++ b/docs/search/all_10.js @@ -1,4 +1,4 @@ var searchData= [ - ['traits_2eh_65',['traits.h',['../traits_8h.html',1,'']]] + ['zone_69',['zone',['../structpackio_1_1msgpack__rpc_1_1internal_1_1request.html#ad05950fc46bacf68d602e20f83f4d64d',1,'packio::msgpack_rpc::internal::request::zone()'],['../structpackio_1_1msgpack__rpc_1_1internal_1_1response.html#ab86f414bf7f829e328923e78c77936be',1,'packio::msgpack_rpc::internal::response::zone()']]] ]; diff --git a/docs/search/all_11.js b/docs/search/all_11.js index 19e3bc1..ea1a4da 100644 --- a/docs/search/all_11.js +++ b/docs/search/all_11.js @@ -1,4 +1,4 @@ var searchData= [ - ['unknown_5fprocedure_66',['unknown_procedure',['../namespacepackio.html#ad0fad01adc607b1ef672314d1ed01809ae63ab84fdc5d63927652dac21ec411ac',1,'packio']]] + ['_7ecompletion_5fhandler_70',['~completion_handler',['../classpackio_1_1completion__handler.html#ab171e21dd2e0508e96fd908a542b79b5',1,'packio::completion_handler']]] ]; diff --git a/docs/search/all_2.js b/docs/search/all_2.js index 5b4e24c..20df36a 100644 --- a/docs/search/all_2.js +++ b/docs/search/all_2.js @@ -1,12 +1,6 @@ var searchData= [ - ['call_5ferror_15',['call_error',['../namespacepackio.html#ad0fad01adc607b1ef672314d1ed01809a71ecb7c2f853a21a83ebdc5a392c57b6',1,'packio']]], - ['callhandler_16',['CallHandler',['../structpackio_1_1traits_1_1CallHandler.html',1,'packio::traits']]], - ['cancel_17',['cancel',['../classpackio_1_1client.html#abccff2d668b89aa02588e759bde07363',1,'packio::client::cancel(id_type id)'],['../classpackio_1_1client.html#a7b057fa7411592cc0a1565b757c6151b',1,'packio::client::cancel()']]], - ['cancelled_18',['cancelled',['../namespacepackio.html#ad0fad01adc607b1ef672314d1ed01809a38881e0a24039dc2621e1d6f86cb71f7',1,'packio']]], - ['clear_19',['clear',['../classpackio_1_1dispatcher.html#afc1e28fd2a1f651d1b30698e1b4b6676',1,'packio::dispatcher']]], - ['client_20',['client',['../classpackio_1_1client.html',1,'packio::client< Socket, Map >'],['../classpackio_1_1client.html#a825dafa0a8e7f5b481a0b80fac77f8fe',1,'packio::client::client()']]], - ['client_2eh_21',['client.h',['../client_8h.html',1,'']]], - ['completion_5fhandler_22',['completion_handler',['../classpackio_1_1completion__handler.html',1,'packio::completion_handler'],['../classpackio_1_1completion__handler.html#aa8f78c4db0923a8debaaabf7e4df0471',1,'packio::completion_handler::completion_handler()']]], - ['coroprocedure_23',['CoroProcedure',['../structpackio_1_1traits_1_1CoroProcedure.html',1,'packio::traits']]] + ['dispatcher_19',['dispatcher',['../classpackio_1_1dispatcher.html',1,'packio::dispatcher< Rpc, Map, Lockable >'],['../classpackio_1_1server.html#aa22366b9445ea0aefd62f30b671ad803',1,'packio::server::dispatcher()'],['../classpackio_1_1server.html#a2250f0c7f67268253726730efde18f1e',1,'packio::server::dispatcher() const'],['../namespacepackio_1_1msgpack__rpc.html#ae3d9c63288b95af71c1f562c8a348437',1,'packio::msgpack_rpc::dispatcher()'],['../namespacepackio_1_1nl__json__rpc.html#a04c96d3c7fdf708974d27d3616963237',1,'packio::nl_json_rpc::dispatcher()']]], + ['dispatcher_2eh_20',['dispatcher.h',['../dispatcher_8h.html',1,'']]], + ['dispatcher_5ftype_21',['dispatcher_type',['../classpackio_1_1server.html#afaa03c3f3530583592670426de2834d5',1,'packio::server']]] ]; diff --git a/docs/search/all_3.js b/docs/search/all_3.js index b32e250..8f7b983 100644 --- a/docs/search/all_3.js +++ b/docs/search/all_3.js @@ -1,6 +1,4 @@ var searchData= [ - ['dispatcher_24',['dispatcher',['../classpackio_1_1dispatcher.html',1,'packio::dispatcher< Map, Lockable >'],['../classpackio_1_1server.html#a71c73a5ab56575e2fa3e05b39865a68e',1,'packio::server::dispatcher()'],['../classpackio_1_1server.html#a343d3dab6de63fe6dee0c0765d781f2c',1,'packio::server::dispatcher() const']]], - ['dispatcher_2eh_25',['dispatcher.h',['../dispatcher_8h.html',1,'']]], - ['dispatcher_5ftype_26',['dispatcher_type',['../classpackio_1_1server.html#a57a2a6a784736a55bec1f2e099f47a67',1,'packio::server']]] + ['executor_5ftype_22',['executor_type',['../classpackio_1_1client.html#a8a22f81e73a8c46b18a21e513e203a34',1,'packio::client::executor_type()'],['../classpackio_1_1server.html#a0e5f3b1946c1da4f81a412b972a2c782',1,'packio::server::executor_type()'],['../classpackio_1_1server__session.html#a48876882ec8f7851967a4d24cf283a7a',1,'packio::server_session::executor_type()']]] ]; diff --git a/docs/search/all_4.js b/docs/search/all_4.js index 82b6a4a..ef8b960 100644 --- a/docs/search/all_4.js +++ b/docs/search/all_4.js @@ -1,7 +1,5 @@ var searchData= [ - ['error_27',['error',['../namespacepackio.html#ad0fad01adc607b1ef672314d1ed01809',1,'packio']]], - ['error_5fcode_2eh_28',['error_code.h',['../error__code_8h.html',1,'']]], - ['error_5fduring_5fcall_29',['error_during_call',['../namespacepackio.html#ad0fad01adc607b1ef672314d1ed01809ad1ef7ee50ccddcdd2ed2ce9c69db96ae',1,'packio']]], - ['executor_5ftype_30',['executor_type',['../classpackio_1_1client.html#a0f2f08560e2ee10a7adbce5206d94a13',1,'packio::client::executor_type()'],['../classpackio_1_1server.html#a04594e9ee178269b5ae9a8b7f03967da',1,'packio::server::executor_type()'],['../classpackio_1_1server__session.html#a7ebcbb24ebb5b5a9dcd55d3f676b736b',1,'packio::server_session::executor_type()']]] + ['function_5fptr_5ftype_23',['function_ptr_type',['../classpackio_1_1dispatcher.html#a07af82e8eb144bdf958bed2cceb971fb',1,'packio::dispatcher']]], + ['function_5ftype_24',['function_type',['../classpackio_1_1dispatcher.html#aa74c0085ec00aa5e419e3b8cf295fffd',1,'packio::dispatcher']]] ]; diff --git a/docs/search/all_5.js b/docs/search/all_5.js index b7a8538..851b35f 100644 --- a/docs/search/all_5.js +++ b/docs/search/all_5.js @@ -1,5 +1,5 @@ var searchData= [ - ['function_5fptr_5ftype_31',['function_ptr_type',['../classpackio_1_1dispatcher.html#a0e935dee0a2a56517961836dbfd70a3e',1,'packio::dispatcher']]], - ['function_5ftype_32',['function_type',['../classpackio_1_1dispatcher.html#af4ef54bdd2549a659f71e59b9fc76cff',1,'packio::dispatcher']]] + ['get_5fbuffer_5freserve_5fsize_25',['get_buffer_reserve_size',['../classpackio_1_1client.html#a2d520aa1e521fd90e58156c9d6fcfb6a',1,'packio::client::get_buffer_reserve_size()'],['../classpackio_1_1server__session.html#a68b291544e6a1b63434d74a6c4d29969',1,'packio::server_session::get_buffer_reserve_size()']]], + ['get_5fexecutor_26',['get_executor',['../classpackio_1_1client.html#a94eda9b4f05c93669304656b4408a120',1,'packio::client::get_executor()'],['../classpackio_1_1server.html#aa9de1435dd562dee7c021385b71cfd58',1,'packio::server::get_executor()'],['../classpackio_1_1server__session.html#aeaa34f73dad87f3a59d106c3f7efa118',1,'packio::server_session::get_executor()']]] ]; diff --git a/docs/search/all_6.js b/docs/search/all_6.js index 987c83a..a99bfd4 100644 --- a/docs/search/all_6.js +++ b/docs/search/all_6.js @@ -1,5 +1,6 @@ var searchData= [ - ['get_5fbuffer_5freserve_5fsize_33',['get_buffer_reserve_size',['../classpackio_1_1client.html#aca85c176d510c2065d7542328e2a84ab',1,'packio::client::get_buffer_reserve_size()'],['../classpackio_1_1server__session.html#af58a304a3af85ed97f6c2f56ddf2830e',1,'packio::server_session::get_buffer_reserve_size()']]], - ['get_5fexecutor_34',['get_executor',['../classpackio_1_1client.html#acc0445305bfcaeb5aec39f5830216060',1,'packio::client::get_executor()'],['../classpackio_1_1server.html#a54d82502040ab9e63e7f31c00988fb12',1,'packio::server::get_executor()'],['../classpackio_1_1server__session.html#ab36ba2101ee2e9ad5226282234fe0e08',1,'packio::server_session::get_executor()']]] + ['handler_2eh_27',['handler.h',['../handler_8h.html',1,'']]], + ['has_28',['has',['../classpackio_1_1dispatcher.html#a84fd7d2a25577726e3ebb6e2367a123a',1,'packio::dispatcher']]], + ['header_2donly_20_7c_20json_2drpc_20_7c_20msgpack_2drpc_20_7c_20asio_20_7c_20coroutines_29',['Header-only | JSON-RPC | msgpack-RPC | asio | coroutines',['../index.html',1,'']]] ]; diff --git a/docs/search/all_7.js b/docs/search/all_7.js index 2b9be81..a29da96 100644 --- a/docs/search/all_7.js +++ b/docs/search/all_7.js @@ -1,6 +1,6 @@ var searchData= [ - ['handler_2eh_35',['handler.h',['../handler_8h.html',1,'']]], - ['has_36',['has',['../classpackio_1_1dispatcher.html#ad9117a463423f2320550a45600a78f12',1,'packio::dispatcher']]], - ['header_2donly_20_7c_20msgpack_2drpc_20_7c_20asio_20_7c_20coroutines_37',['Header-only | msgpack-RPC | asio | coroutines',['../index.html',1,'']]] + ['id_5ftype_30',['id_type',['../classpackio_1_1client.html#a86896af2ccaed0262e8dfe8728ce3809',1,'packio::client::id_type()'],['../classpackio_1_1msgpack__rpc_1_1rpc.html#aea7c1f825093a6d6c66d4cb76df96624',1,'packio::msgpack_rpc::rpc::id_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#aa09ce5e5f80fd516e8f1368bb965d83f',1,'packio::nl_json_rpc::rpc::id_type()']]], + ['incremental_5fparser_31',['incremental_parser',['../classpackio_1_1msgpack__rpc_1_1internal_1_1incremental__parser.html',1,'packio::msgpack_rpc::internal::incremental_parser'],['../classpackio_1_1nl__json__rpc_1_1internal_1_1incremental__parser.html',1,'packio::nl_json_rpc::internal::incremental_parser']]], + ['incremental_5fparser_5ftype_32',['incremental_parser_type',['../classpackio_1_1msgpack__rpc_1_1rpc.html#a3fb072c8ede82fec07c834b97f95c645',1,'packio::msgpack_rpc::rpc::incremental_parser_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#a04f825324bf02549b978ff521c12c4b0',1,'packio::nl_json_rpc::rpc::incremental_parser_type()']]] ]; diff --git a/docs/search/all_8.js b/docs/search/all_8.js index b4b46dd..415f996 100644 --- a/docs/search/all_8.js +++ b/docs/search/all_8.js @@ -1,4 +1,5 @@ var searchData= [ - ['id_5ftype_38',['id_type',['../namespacepackio.html#a02aa56c39599b9cde75f298011dc87e8',1,'packio']]] + ['kdefaultbufferreservesize_33',['kDefaultBufferReserveSize',['../classpackio_1_1client.html#ad4e5a705e61a06ffa999e7c2cbf42cb2',1,'packio::client::kDefaultBufferReserveSize()'],['../classpackio_1_1server__session.html#abda9254cbf38a8b0644b3603e55b2c15',1,'packio::server_session::kDefaultBufferReserveSize()']]], + ['known_34',['known',['../classpackio_1_1dispatcher.html#a91c7803eac9f56134e812ee1b604122f',1,'packio::dispatcher']]] ]; diff --git a/docs/search/all_9.js b/docs/search/all_9.js index a134eef..1c9a561 100644 --- a/docs/search/all_9.js +++ b/docs/search/all_9.js @@ -1,5 +1,7 @@ var searchData= [ - ['kdefaultbufferreservesize_39',['kDefaultBufferReserveSize',['../classpackio_1_1client.html#a2f73dd57767e2dac677ffd03b672e6c5',1,'packio::client::kDefaultBufferReserveSize()'],['../classpackio_1_1server__session.html#abb614afb4157378d1a533312880af595',1,'packio::server_session::kDefaultBufferReserveSize()']]], - ['known_40',['known',['../classpackio_1_1dispatcher.html#aed8b188e5d51c261f0622cd5269eb3ee',1,'packio::dispatcher']]] + ['make_5fclient_35',['make_client',['../namespacepackio.html#a5a73a8453d35e9f6f0c29e9b87e93490',1,'packio::make_client()'],['../namespacepackio_1_1msgpack__rpc.html#a10bd3630d97339e416f5e407efece04d',1,'packio::msgpack_rpc::make_client()'],['../namespacepackio_1_1nl__json__rpc.html#a5e5b0abe3f0dbfc17fbd5d217df6b5e2',1,'packio::nl_json_rpc::make_client()']]], + ['make_5fserver_36',['make_server',['../namespacepackio_1_1msgpack__rpc.html#a437273529bff1d9196ae2afdf8233f9f',1,'packio::msgpack_rpc::make_server()'],['../namespacepackio_1_1nl__json__rpc.html#a55f9e2c9a4b823f4b1147413636c1e10',1,'packio::nl_json_rpc::make_server()'],['../namespacepackio.html#a4944e82d7f3dd2ee989a49d928cef3d3',1,'packio::make_server()']]], + ['msgpack_5frpc_2eh_37',['msgpack_rpc.h',['../msgpack__rpc_8h.html',1,'']]], + ['mutex_5ftype_38',['mutex_type',['../classpackio_1_1dispatcher.html#aef789d54a0d2fa86837d029606881313',1,'packio::dispatcher']]] ]; diff --git a/docs/search/all_a.js b/docs/search/all_a.js index 0419644..143e909 100644 --- a/docs/search/all_a.js +++ b/docs/search/all_a.js @@ -1,7 +1,6 @@ var searchData= [ - ['make_5fclient_41',['make_client',['../namespacepackio.html#ae41a42d5103a615a810d6e42d68906da',1,'packio']]], - ['make_5fserver_42',['make_server',['../namespacepackio.html#adb4190a7fda2259edbbe7684c2c5a766',1,'packio']]], - ['msgpack_5frpc_2eh_43',['msgpack_rpc.h',['../msgpack__rpc_8h.html',1,'']]], - ['mutex_5ftype_44',['mutex_type',['../classpackio_1_1dispatcher.html#aa2d5ff7c0b29f52b03b5db7488ee1378',1,'packio::dispatcher']]] + ['native_5ftype_39',['native_type',['../classpackio_1_1msgpack__rpc_1_1rpc.html#a34db8ce79c9de47fe5f8245eec851fdb',1,'packio::msgpack_rpc::rpc::native_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#a9d356881153c1ee2c93e7e31d49bde4b',1,'packio::nl_json_rpc::rpc::native_type()']]], + ['nl_5fjson_5frpc_2eh_40',['nl_json_rpc.h',['../nl__json__rpc_8h.html',1,'']]], + ['notifyhandler_41',['NotifyHandler',['../structpackio_1_1traits_1_1NotifyHandler.html',1,'packio::traits']]] ]; diff --git a/docs/search/all_b.js b/docs/search/all_b.js index a9c8459..f932c8f 100644 --- a/docs/search/all_b.js +++ b/docs/search/all_b.js @@ -1,4 +1,5 @@ var searchData= [ - ['notifyhandler_45',['NotifyHandler',['../structpackio_1_1traits_1_1NotifyHandler.html',1,'packio::traits']]] + ['operator_28_29_42',['operator()',['../classpackio_1_1completion__handler.html#a525d3e3037436d4f190a36fc2c7cf755',1,'packio::completion_handler::operator()(T &&return_value)'],['../classpackio_1_1completion__handler.html#a79fa456e381d5967c8ac5ba1df3acb74',1,'packio::completion_handler::operator()()']]], + ['operator_3d_43',['operator=',['../classpackio_1_1completion__handler.html#ad1351e8aee5a4bbf44a7d0e94f9a618e',1,'packio::completion_handler']]] ]; diff --git a/docs/search/all_c.js b/docs/search/all_c.js index 9c4755f..ee241fa 100644 --- a/docs/search/all_c.js +++ b/docs/search/all_c.js @@ -1,5 +1,8 @@ var searchData= [ - ['operator_28_29_46',['operator()',['../classpackio_1_1completion__handler.html#af8fc63fe1638048313ca2e081d1bfb7e',1,'packio::completion_handler::operator()(T &&return_value)'],['../classpackio_1_1completion__handler.html#ae88a9601765c0e6ee070a73ee70b60f9',1,'packio::completion_handler::operator()()']]], - ['operator_3d_47',['operator=',['../classpackio_1_1completion__handler.html#aeedf3e5ac4eeb5a8976a82aaca769bb9',1,'packio::completion_handler']]] + ['msgpack_5frpc_44',['msgpack_rpc',['../namespacepackio_1_1msgpack__rpc.html',1,'packio']]], + ['nl_5fjson_5frpc_45',['nl_json_rpc',['../namespacepackio_1_1nl__json__rpc.html',1,'packio']]], + ['packio_46',['packio',['../namespacepackio.html',1,'']]], + ['packio_2eh_47',['packio.h',['../packio_8h.html',1,'']]], + ['protocol_5ftype_48',['protocol_type',['../classpackio_1_1client.html#a6d4173ba81572e0e1d11d4e83d57ab90',1,'packio::client::protocol_type()'],['../classpackio_1_1server.html#aeca24e496aec70feb6c1363b760a6e55',1,'packio::server::protocol_type()'],['../classpackio_1_1server__session.html#a555264e82920fac940e21abb4ca7f098',1,'packio::server_session::protocol_type()']]] ]; diff --git a/docs/search/all_d.js b/docs/search/all_d.js index c2a08cb..12a2e26 100644 --- a/docs/search/all_d.js +++ b/docs/search/all_d.js @@ -1,6 +1,10 @@ var searchData= [ - ['packio_48',['packio',['../namespacepackio.html',1,'']]], - ['packio_2eh_49',['packio.h',['../packio_8h.html',1,'']]], - ['protocol_5ftype_50',['protocol_type',['../classpackio_1_1client.html#a15b4926e18f5c3221412ae885f318a3a',1,'packio::client::protocol_type()'],['../classpackio_1_1server.html#ac3cca245e7251e2f834407bbfe6e0aaa',1,'packio::server::protocol_type()'],['../classpackio_1_1server__session.html#af544ff51d72997416c11bc8c8de4a9f9',1,'packio::server_session::protocol_type()']]] + ['remove_49',['remove',['../classpackio_1_1dispatcher.html#a28bead383b8dfcd95c0d18a9af342ad1',1,'packio::dispatcher']]], + ['request_50',['request',['../structpackio_1_1msgpack__rpc_1_1internal_1_1request.html',1,'packio::msgpack_rpc::internal::request'],['../structpackio_1_1nl__json__rpc_1_1internal_1_1request.html',1,'packio::nl_json_rpc::internal::request']]], + ['request_5ftype_51',['request_type',['../classpackio_1_1msgpack__rpc_1_1rpc.html#a1281d8595df97aea44d465ee0bd14387',1,'packio::msgpack_rpc::rpc::request_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#ae80e929ba5d0ffd30ff50d7682227005',1,'packio::nl_json_rpc::rpc::request_type()']]], + ['response_52',['response',['../structpackio_1_1nl__json__rpc_1_1internal_1_1response.html',1,'packio::nl_json_rpc::internal::response'],['../structpackio_1_1msgpack__rpc_1_1internal_1_1response.html',1,'packio::msgpack_rpc::internal::response']]], + ['response_5ftype_53',['response_type',['../classpackio_1_1client.html#a9ffe5dfb1595bcd55ab2d3e69e5261f3',1,'packio::client::response_type()'],['../classpackio_1_1msgpack__rpc_1_1rpc.html#ae326edcb041af393608f749829861a1f',1,'packio::msgpack_rpc::rpc::response_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#a4cc97964ab0d4fd9a5fed97516b2ffd2',1,'packio::nl_json_rpc::rpc::response_type()']]], + ['rpc_54',['rpc',['../classpackio_1_1msgpack__rpc_1_1rpc.html',1,'packio::msgpack_rpc::rpc'],['../classpackio_1_1nl__json__rpc_1_1rpc.html',1,'packio::nl_json_rpc::rpc']]], + ['rpc_5ftype_55',['rpc_type',['../classpackio_1_1client.html#a5d35a309258ce540e94004b27f7dbe3b',1,'packio::client::rpc_type()'],['../classpackio_1_1dispatcher.html#ac9b6747517bc29485466d00692979195',1,'packio::dispatcher::rpc_type()'],['../classpackio_1_1server.html#abbb6ae551a947e25fac4b2958c3238f1',1,'packio::server::rpc_type()']]] ]; diff --git a/docs/search/all_e.js b/docs/search/all_e.js index 0188627..45048a2 100644 --- a/docs/search/all_e.js +++ b/docs/search/all_e.js @@ -1,4 +1,15 @@ var searchData= [ - ['remove_51',['remove',['../classpackio_1_1dispatcher.html#a7c3bf380302ee8492a282cf83c35b42f',1,'packio::dispatcher']]] + ['servehandler_56',['ServeHandler',['../structpackio_1_1traits_1_1ServeHandler.html',1,'packio::traits']]], + ['server_57',['server',['../classpackio_1_1server.html',1,'packio::server< Rpc, Acceptor, Dispatcher >'],['../classpackio_1_1server.html#a4862f9f94b6112171ba8ac5549305084',1,'packio::server::server(acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)'],['../classpackio_1_1server.html#a015f43f073e5bcbb1ae12a5489fcd6a5',1,'packio::server::server(acceptor_type acceptor)'],['../namespacepackio_1_1msgpack__rpc.html#a34d73db89c36af6b191cb1b148ba77d2',1,'packio::msgpack_rpc::server()'],['../namespacepackio_1_1nl__json__rpc.html#a7509cdc0bd479cc90a81a391ac04c239',1,'packio::nl_json_rpc::server()']]], + ['server_2eh_58',['server.h',['../server_8h.html',1,'']]], + ['server_5fsession_59',['server_session',['../classpackio_1_1server__session.html',1,'packio']]], + ['server_5fsession_2eh_60',['server_session.h',['../server__session_8h.html',1,'']]], + ['set_5fbuffer_5freserve_5fsize_61',['set_buffer_reserve_size',['../classpackio_1_1client.html#aa76167481dc66a2b7d0bda6ab7eead1d',1,'packio::client::set_buffer_reserve_size()'],['../classpackio_1_1server__session.html#a0ae604b3897fd019f8dbaa491ab4012c',1,'packio::server_session::set_buffer_reserve_size()']]], + ['set_5ferror_62',['set_error',['../classpackio_1_1completion__handler.html#adba2b11b3e079002662ca2756c856f0d',1,'packio::completion_handler::set_error(T &&error_value)'],['../classpackio_1_1completion__handler.html#a125d19c56aa53ccb9b7054cd7c2a8928',1,'packio::completion_handler::set_error()']]], + ['set_5fvalue_63',['set_value',['../classpackio_1_1completion__handler.html#a2f2b5f77586b631bf4426fd4c758bd15',1,'packio::completion_handler::set_value(T &&return_value)'],['../classpackio_1_1completion__handler.html#ae11f5b5410582755090957cabf6ddcc8',1,'packio::completion_handler::set_value()']]], + ['socket_64',['socket',['../classpackio_1_1client.html#a97dbdacc125af0464dca3a37761e4e18',1,'packio::client::socket() noexcept'],['../classpackio_1_1client.html#ab6f8392c2db28ce9bf67c8290837c011',1,'packio::client::socket() const noexcept'],['../classpackio_1_1server__session.html#a74cc5ac0eefaf0edfcef3bb9666359b9',1,'packio::server_session::socket()'],['../classpackio_1_1server__session.html#a1fa1898f17fb73ad8469987b4a81033f',1,'packio::server_session::socket() const']]], + ['socket_5ftype_65',['socket_type',['../classpackio_1_1client.html#a9b06b233bdcf0f6d14db967ba45826c4',1,'packio::client::socket_type()'],['../classpackio_1_1server.html#aeadaf22c6898985ed5b49b1d27e85365',1,'packio::server::socket_type()'],['../classpackio_1_1server__session.html#a1115ebfdbbd4413ae7f5cbf99a8c6dda',1,'packio::server_session::socket_type()']]], + ['start_66',['start',['../classpackio_1_1server__session.html#aca595d69b5e342e4b46e73adaa2969ba',1,'packio::server_session']]], + ['syncprocedure_67',['SyncProcedure',['../structpackio_1_1traits_1_1SyncProcedure.html',1,'packio::traits']]] ]; diff --git a/docs/search/all_f.js b/docs/search/all_f.js index a683191..a6fb057 100644 --- a/docs/search/all_f.js +++ b/docs/search/all_f.js @@ -1,16 +1,4 @@ var searchData= [ - ['servehandler_52',['ServeHandler',['../structpackio_1_1traits_1_1ServeHandler.html',1,'packio::traits']]], - ['server_53',['server',['../classpackio_1_1server.html',1,'packio::server< Acceptor, Dispatcher >'],['../classpackio_1_1server.html#a1d957e4e7f7bfa0ae7744815b2e92184',1,'packio::server::server(acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)'],['../classpackio_1_1server.html#a46991dfa12d830c2eb3c2ba078effafc',1,'packio::server::server(acceptor_type acceptor)']]], - ['server_2eh_54',['server.h',['../server_8h.html',1,'']]], - ['server_5fsession_55',['server_session',['../classpackio_1_1server__session.html',1,'packio']]], - ['server_5fsession_2eh_56',['server_session.h',['../server__session_8h.html',1,'']]], - ['set_5fbuffer_5freserve_5fsize_57',['set_buffer_reserve_size',['../classpackio_1_1client.html#a14484788c6a5ec629e9ebb54a5971fd6',1,'packio::client::set_buffer_reserve_size()'],['../classpackio_1_1server__session.html#a4eb23e0e0dd78ff5fec025c10866970e',1,'packio::server_session::set_buffer_reserve_size()']]], - ['set_5ferror_58',['set_error',['../classpackio_1_1completion__handler.html#a19f6a250a6b0b5bc1d09b9b8948f5a9e',1,'packio::completion_handler::set_error(T &&error_value)'],['../classpackio_1_1completion__handler.html#ac99c708ff2220893a4446cec9eaa59fc',1,'packio::completion_handler::set_error()']]], - ['set_5fvalue_59',['set_value',['../classpackio_1_1completion__handler.html#a62c027610298c8e4b4d6d6cec3ab58e2',1,'packio::completion_handler::set_value(T &&return_value)'],['../classpackio_1_1completion__handler.html#a0802f6b6c5382f352dd196e1f600f2af',1,'packio::completion_handler::set_value()']]], - ['socket_60',['socket',['../classpackio_1_1client.html#a9604a810a325d5a761d752657f51f139',1,'packio::client::socket() noexcept'],['../classpackio_1_1client.html#a99bc6645de7020bd37e356b245817a85',1,'packio::client::socket() const noexcept'],['../classpackio_1_1server__session.html#a4f48ee3c8b5226c06ed2fd0a249d8405',1,'packio::server_session::socket()'],['../classpackio_1_1server__session.html#a876b18d9307ba6cc5f75c55b040764d5',1,'packio::server_session::socket() const']]], - ['socket_5ftype_61',['socket_type',['../classpackio_1_1client.html#a6f710205e0426368bd4fc1e973d0e377',1,'packio::client::socket_type()'],['../classpackio_1_1server.html#ac42874f5c340ba691c88a6ea1d44c836',1,'packio::server::socket_type()'],['../classpackio_1_1server__session.html#ab9ab57c300970cc8dbf520f214a43534',1,'packio::server_session::socket_type()']]], - ['start_62',['start',['../classpackio_1_1server__session.html#ae52740e61342e388a27f65f01cc3376f',1,'packio::server_session']]], - ['success_63',['success',['../namespacepackio.html#ad0fad01adc607b1ef672314d1ed01809a260ca9dd8a4577fc00b7bd5810298076',1,'packio']]], - ['syncprocedure_64',['SyncProcedure',['../structpackio_1_1traits_1_1SyncProcedure.html',1,'packio::traits']]] + ['traits_2eh_68',['traits.h',['../traits_8h.html',1,'']]] ]; diff --git a/docs/search/classes_0.js b/docs/search/classes_0.js index 416691d..456dbbf 100644 --- a/docs/search/classes_0.js +++ b/docs/search/classes_0.js @@ -1,6 +1,4 @@ var searchData= [ - ['ascallhandler_68',['AsCallHandler',['../structpackio_1_1traits_1_1AsCallHandler.html',1,'packio::traits']]], - ['asvoidcallhandler_69',['AsVoidCallHandler',['../structpackio_1_1traits_1_1AsVoidCallHandler.html',1,'packio::traits']]], - ['asyncprocedure_70',['AsyncProcedure',['../structpackio_1_1traits_1_1AsyncProcedure.html',1,'packio::traits']]] + ['asyncprocedure_71',['AsyncProcedure',['../structpackio_1_1traits_1_1AsyncProcedure.html',1,'packio::traits']]] ]; diff --git a/docs/search/classes_1.js b/docs/search/classes_1.js index 5bcdda7..5b55c3b 100644 --- a/docs/search/classes_1.js +++ b/docs/search/classes_1.js @@ -1,7 +1,7 @@ var searchData= [ - ['callhandler_71',['CallHandler',['../structpackio_1_1traits_1_1CallHandler.html',1,'packio::traits']]], - ['client_72',['client',['../classpackio_1_1client.html',1,'packio']]], - ['completion_5fhandler_73',['completion_handler',['../classpackio_1_1completion__handler.html',1,'packio']]], - ['coroprocedure_74',['CoroProcedure',['../structpackio_1_1traits_1_1CoroProcedure.html',1,'packio::traits']]] + ['callhandler_72',['CallHandler',['../structpackio_1_1traits_1_1CallHandler.html',1,'packio::traits']]], + ['client_73',['client',['../classpackio_1_1client.html',1,'packio']]], + ['completion_5fhandler_74',['completion_handler',['../classpackio_1_1completion__handler.html',1,'packio']]], + ['coroprocedure_75',['CoroProcedure',['../structpackio_1_1traits_1_1CoroProcedure.html',1,'packio::traits']]] ]; diff --git a/docs/search/classes_2.js b/docs/search/classes_2.js index 4322c61..e0c361c 100644 --- a/docs/search/classes_2.js +++ b/docs/search/classes_2.js @@ -1,4 +1,4 @@ var searchData= [ - ['dispatcher_75',['dispatcher',['../classpackio_1_1dispatcher.html',1,'packio']]] + ['dispatcher_76',['dispatcher',['../classpackio_1_1dispatcher.html',1,'packio']]] ]; diff --git a/docs/search/classes_3.js b/docs/search/classes_3.js index 938bf43..82a214c 100644 --- a/docs/search/classes_3.js +++ b/docs/search/classes_3.js @@ -1,4 +1,4 @@ var searchData= [ - ['notifyhandler_76',['NotifyHandler',['../structpackio_1_1traits_1_1NotifyHandler.html',1,'packio::traits']]] + ['incremental_5fparser_77',['incremental_parser',['../classpackio_1_1msgpack__rpc_1_1internal_1_1incremental__parser.html',1,'packio::msgpack_rpc::internal::incremental_parser'],['../classpackio_1_1nl__json__rpc_1_1internal_1_1incremental__parser.html',1,'packio::nl_json_rpc::internal::incremental_parser']]] ]; diff --git a/docs/search/classes_4.js b/docs/search/classes_4.js index 18cdd34..d65606d 100644 --- a/docs/search/classes_4.js +++ b/docs/search/classes_4.js @@ -1,7 +1,4 @@ var searchData= [ - ['servehandler_77',['ServeHandler',['../structpackio_1_1traits_1_1ServeHandler.html',1,'packio::traits']]], - ['server_78',['server',['../classpackio_1_1server.html',1,'packio']]], - ['server_5fsession_79',['server_session',['../classpackio_1_1server__session.html',1,'packio']]], - ['syncprocedure_80',['SyncProcedure',['../structpackio_1_1traits_1_1SyncProcedure.html',1,'packio::traits']]] + ['notifyhandler_78',['NotifyHandler',['../structpackio_1_1traits_1_1NotifyHandler.html',1,'packio::traits']]] ]; diff --git a/docs/search/classes_5.html b/docs/search/classes_5.html new file mode 100644 index 0000000..fc9cdc9 --- /dev/null +++ b/docs/search/classes_5.html @@ -0,0 +1,30 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/docs/search/classes_5.js b/docs/search/classes_5.js new file mode 100644 index 0000000..b05d9ca --- /dev/null +++ b/docs/search/classes_5.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['request_79',['request',['../structpackio_1_1msgpack__rpc_1_1internal_1_1request.html',1,'packio::msgpack_rpc::internal::request'],['../structpackio_1_1nl__json__rpc_1_1internal_1_1request.html',1,'packio::nl_json_rpc::internal::request']]], + ['response_80',['response',['../structpackio_1_1nl__json__rpc_1_1internal_1_1response.html',1,'packio::nl_json_rpc::internal::response'],['../structpackio_1_1msgpack__rpc_1_1internal_1_1response.html',1,'packio::msgpack_rpc::internal::response']]], + ['rpc_81',['rpc',['../classpackio_1_1msgpack__rpc_1_1rpc.html',1,'packio::msgpack_rpc::rpc'],['../classpackio_1_1nl__json__rpc_1_1rpc.html',1,'packio::nl_json_rpc::rpc']]] +]; diff --git a/docs/search/classes_6.html b/docs/search/classes_6.html new file mode 100644 index 0000000..1ecfddd --- /dev/null +++ b/docs/search/classes_6.html @@ -0,0 +1,30 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/docs/search/classes_6.js b/docs/search/classes_6.js new file mode 100644 index 0000000..53785d6 --- /dev/null +++ b/docs/search/classes_6.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['servehandler_82',['ServeHandler',['../structpackio_1_1traits_1_1ServeHandler.html',1,'packio::traits']]], + ['server_83',['server',['../classpackio_1_1server.html',1,'packio']]], + ['server_5fsession_84',['server_session',['../classpackio_1_1server__session.html',1,'packio']]], + ['syncprocedure_85',['SyncProcedure',['../structpackio_1_1traits_1_1SyncProcedure.html',1,'packio::traits']]] +]; diff --git a/docs/search/files_0.js b/docs/search/files_0.js index c232c6d..2d3e6fd 100644 --- a/docs/search/files_0.js +++ b/docs/search/files_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['as_2eh_82',['as.h',['../as_8h.html',1,'']]] + ['arg_2eh_89',['arg.h',['../arg_8h.html',1,'']]] ]; diff --git a/docs/search/files_1.js b/docs/search/files_1.js index 6154d3c..281c323 100644 --- a/docs/search/files_1.js +++ b/docs/search/files_1.js @@ -1,4 +1,4 @@ var searchData= [ - ['client_2eh_83',['client.h',['../client_8h.html',1,'']]] + ['client_2eh_90',['client.h',['../client_8h.html',1,'']]] ]; diff --git a/docs/search/files_2.js b/docs/search/files_2.js index 86ba46c..4d93bec 100644 --- a/docs/search/files_2.js +++ b/docs/search/files_2.js @@ -1,4 +1,4 @@ var searchData= [ - ['dispatcher_2eh_84',['dispatcher.h',['../dispatcher_8h.html',1,'']]] + ['dispatcher_2eh_91',['dispatcher.h',['../dispatcher_8h.html',1,'']]] ]; diff --git a/docs/search/files_3.js b/docs/search/files_3.js index 0baffbf..90ca56c 100644 --- a/docs/search/files_3.js +++ b/docs/search/files_3.js @@ -1,4 +1,4 @@ var searchData= [ - ['error_5fcode_2eh_85',['error_code.h',['../error__code_8h.html',1,'']]] + ['handler_2eh_92',['handler.h',['../handler_8h.html',1,'']]] ]; diff --git a/docs/search/files_4.js b/docs/search/files_4.js index cb2f72c..e1567fc 100644 --- a/docs/search/files_4.js +++ b/docs/search/files_4.js @@ -1,4 +1,4 @@ var searchData= [ - ['handler_2eh_86',['handler.h',['../handler_8h.html',1,'']]] + ['msgpack_5frpc_2eh_93',['msgpack_rpc.h',['../msgpack__rpc_8h.html',1,'']]] ]; diff --git a/docs/search/files_5.js b/docs/search/files_5.js index 5a08f6d..3af465e 100644 --- a/docs/search/files_5.js +++ b/docs/search/files_5.js @@ -1,4 +1,4 @@ var searchData= [ - ['msgpack_5frpc_2eh_87',['msgpack_rpc.h',['../msgpack__rpc_8h.html',1,'']]] + ['nl_5fjson_5frpc_2eh_94',['nl_json_rpc.h',['../nl__json__rpc_8h.html',1,'']]] ]; diff --git a/docs/search/files_6.js b/docs/search/files_6.js index f9e2317..8084562 100644 --- a/docs/search/files_6.js +++ b/docs/search/files_6.js @@ -1,4 +1,4 @@ var searchData= [ - ['packio_2eh_88',['packio.h',['../packio_8h.html',1,'']]] + ['packio_2eh_95',['packio.h',['../packio_8h.html',1,'']]] ]; diff --git a/docs/search/files_7.js b/docs/search/files_7.js index 326a011..6ce0908 100644 --- a/docs/search/files_7.js +++ b/docs/search/files_7.js @@ -1,5 +1,5 @@ var searchData= [ - ['server_2eh_89',['server.h',['../server_8h.html',1,'']]], - ['server_5fsession_2eh_90',['server_session.h',['../server__session_8h.html',1,'']]] + ['server_2eh_96',['server.h',['../server_8h.html',1,'']]], + ['server_5fsession_2eh_97',['server_session.h',['../server__session_8h.html',1,'']]] ]; diff --git a/docs/search/files_8.js b/docs/search/files_8.js index eb124c4..4f9fa77 100644 --- a/docs/search/files_8.js +++ b/docs/search/files_8.js @@ -1,4 +1,4 @@ var searchData= [ - ['traits_2eh_91',['traits.h',['../traits_8h.html',1,'']]] + ['traits_2eh_98',['traits.h',['../traits_8h.html',1,'']]] ]; diff --git a/docs/search/functions_0.js b/docs/search/functions_0.js index f4bb52b..0b7a84b 100644 --- a/docs/search/functions_0.js +++ b/docs/search/functions_0.js @@ -1,12 +1,11 @@ var searchData= [ - ['acceptor_92',['acceptor',['../classpackio_1_1server.html#a5be66852826d65711c095751a6b92b99',1,'packio::server::acceptor()'],['../classpackio_1_1server.html#a900e9e9a37cb109c4c330795e5f83639',1,'packio::server::acceptor() const']]], - ['add_93',['add',['../classpackio_1_1dispatcher.html#aff6c4d31f265b4590f62122e9b2548a0',1,'packio::dispatcher']]], - ['add_5fasync_94',['add_async',['../classpackio_1_1dispatcher.html#a5411e4849d5a68bc42cb5ca18dda1512',1,'packio::dispatcher']]], - ['add_5fcoro_95',['add_coro',['../classpackio_1_1dispatcher.html#a545e8e11ba04410246d8d03da4979787',1,'packio::dispatcher::add_coro(std::string_view name, const Executor &executor, CoroProcedure &&coro)'],['../classpackio_1_1dispatcher.html#a33b17f8c33362361f5cd0b1ce0f5a1d7',1,'packio::dispatcher::add_coro(std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)']]], - ['as_96',['as',['../namespacepackio.html#a98ec735bfe5e3655f1e398f9f8c122bc',1,'packio::as(AsCallHandler &&handler, std::enable_if_t<!std::is_void_v< Result >, void * >=nullptr)'],['../namespacepackio.html#a96d591f155009301646e3827cc3e4f14',1,'packio::as(AsVoidCallHandler &&handler, std::enable_if_t< std::is_void_v< Result >, void * >=nullptr)']]], - ['async_5fcall_97',['async_call',['../classpackio_1_1client.html#a05f979924252b2c34d4b256a45ee0a7c',1,'packio::client::async_call(std::string_view name, const std::tuple< Args... > &args, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)'],['../classpackio_1_1client.html#a08881f94b175afdf8d30f5af0e1f8457',1,'packio::client::async_call(std::string_view name, CallHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)']]], - ['async_5fnotify_98',['async_notify',['../classpackio_1_1client.html#ac95f66e17622014663e9896eb7f990a2',1,'packio::client::async_notify(std::string_view name, const std::tuple< Args... > &args, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))'],['../classpackio_1_1client.html#ae29fe2a9b0a6c2b513db9302a0645611',1,'packio::client::async_notify(std::string_view name, NotifyHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))']]], - ['async_5fserve_99',['async_serve',['../classpackio_1_1server.html#a0703bbd27e5b81c59e250f4fbb3cf50b',1,'packio::server']]], - ['async_5fserve_5fforever_100',['async_serve_forever',['../classpackio_1_1server.html#a03b47a89b17d09fef03b1a4bc391c5f5',1,'packio::server']]] + ['acceptor_99',['acceptor',['../classpackio_1_1server.html#acd3378e8bb5df14f3669e630555ff3cc',1,'packio::server::acceptor()'],['../classpackio_1_1server.html#a05eaaffba89e22806be336415a2f2382',1,'packio::server::acceptor() const']]], + ['add_100',['add',['../classpackio_1_1dispatcher.html#a9d5652505ffd5127cffe1619fb7c4a71',1,'packio::dispatcher::add(std::string_view name, const std::array< std::string, N > &arguments_names, SyncProcedure &&fct)'],['../classpackio_1_1dispatcher.html#a98c5d9dcb0820ca336cc2859e82162fe',1,'packio::dispatcher::add(std::string_view name, SyncProcedure &&fct)']]], + ['add_5fasync_101',['add_async',['../classpackio_1_1dispatcher.html#a287a41488fdc9421da77a68fe1e49846',1,'packio::dispatcher::add_async(std::string_view name, const std::array< std::string, N > &arguments_names, AsyncProcedure &&fct)'],['../classpackio_1_1dispatcher.html#a18d6db12264390103c687955aebd05f2',1,'packio::dispatcher::add_async(std::string_view name, AsyncProcedure &&fct)']]], + ['add_5fcoro_102',['add_coro',['../classpackio_1_1dispatcher.html#a2545f945918bff8f4bc0b1a63df0f898',1,'packio::dispatcher::add_coro(std::string_view name, const Executor &executor, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)'],['../classpackio_1_1dispatcher.html#a69b32ee4c046b818c1c11523eb1f93e7',1,'packio::dispatcher::add_coro(std::string_view name, const Executor &executor, CoroProcedure &&coro)'],['../classpackio_1_1dispatcher.html#a8fdb50ef2822589c1e80b35c9c7fbed5',1,'packio::dispatcher::add_coro(std::string_view name, ExecutionContext &ctx, const std::array< std::string, N > &arguments_names, CoroProcedure &&coro)'],['../classpackio_1_1dispatcher.html#a04ba29e0c1b3d13e7e565ea0fc224ca3',1,'packio::dispatcher::add_coro(std::string_view name, ExecutionContext &ctx, CoroProcedure &&coro)']]], + ['async_5fcall_103',['async_call',['../classpackio_1_1client.html#ac1f59f8f7daef410bb52c69c32d918d9',1,'packio::client::async_call(std::string_view name, ArgsTuple &&args, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)'],['../classpackio_1_1client.html#aab82f7ebe33c7e33e3fbdad0f0c5a969',1,'packio::client::async_call(std::string_view name, CallHandler &&handler=typename net::default_completion_token< executor_type >::type(), std::optional< std::reference_wrapper< id_type >> call_id=std::nullopt)']]], + ['async_5fnotify_104',['async_notify',['../classpackio_1_1client.html#ac4f5950217f8977497b872f7a2fd0d36',1,'packio::client::async_notify(std::string_view name, ArgsTuple &&args, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())'],['../classpackio_1_1client.html#aac8c2e52f17c577d6bb002a8bfc119d9',1,'packio::client::async_notify(std::string_view name, NotifyHandler &&handler=typename net::default_completion_token< executor_type >::type())']]], + ['async_5fserve_105',['async_serve',['../classpackio_1_1server.html#a36cbd8c2767ca32a86dce40d40e95e3f',1,'packio::server']]], + ['async_5fserve_5fforever_106',['async_serve_forever',['../classpackio_1_1server.html#a6a8930268e678fc7d6809cf55a9831a4',1,'packio::server']]] ]; diff --git a/docs/search/functions_1.js b/docs/search/functions_1.js index 99fec4b..abdeeee 100644 --- a/docs/search/functions_1.js +++ b/docs/search/functions_1.js @@ -1,7 +1,7 @@ var searchData= [ - ['cancel_101',['cancel',['../classpackio_1_1client.html#abccff2d668b89aa02588e759bde07363',1,'packio::client::cancel(id_type id)'],['../classpackio_1_1client.html#a7b057fa7411592cc0a1565b757c6151b',1,'packio::client::cancel()']]], - ['clear_102',['clear',['../classpackio_1_1dispatcher.html#afc1e28fd2a1f651d1b30698e1b4b6676',1,'packio::dispatcher']]], - ['client_103',['client',['../classpackio_1_1client.html#a825dafa0a8e7f5b481a0b80fac77f8fe',1,'packio::client']]], - ['completion_5fhandler_104',['completion_handler',['../classpackio_1_1completion__handler.html#aa8f78c4db0923a8debaaabf7e4df0471',1,'packio::completion_handler']]] + ['cancel_107',['cancel',['../classpackio_1_1client.html#ac0b565e42875e83d6f913c95a65a3999',1,'packio::client::cancel(id_type id)'],['../classpackio_1_1client.html#a803c9c74259f6ab0845a4732cf92a854',1,'packio::client::cancel()']]], + ['clear_108',['clear',['../classpackio_1_1dispatcher.html#a36d55afaa13d51008125d08cbaab77cb',1,'packio::dispatcher']]], + ['client_109',['client',['../classpackio_1_1client.html#a7e885325ce598f29878a22d9b9253829',1,'packio::client']]], + ['completion_5fhandler_110',['completion_handler',['../classpackio_1_1completion__handler.html#a3ab1ed2afc9e16de0f6d31afa5c42a05',1,'packio::completion_handler']]] ]; diff --git a/docs/search/functions_2.js b/docs/search/functions_2.js index 1019c56..f6b3f60 100644 --- a/docs/search/functions_2.js +++ b/docs/search/functions_2.js @@ -1,4 +1,4 @@ var searchData= [ - ['dispatcher_105',['dispatcher',['../classpackio_1_1server.html#a71c73a5ab56575e2fa3e05b39865a68e',1,'packio::server::dispatcher()'],['../classpackio_1_1server.html#a343d3dab6de63fe6dee0c0765d781f2c',1,'packio::server::dispatcher() const']]] + ['dispatcher_111',['dispatcher',['../classpackio_1_1server.html#aa22366b9445ea0aefd62f30b671ad803',1,'packio::server::dispatcher()'],['../classpackio_1_1server.html#a2250f0c7f67268253726730efde18f1e',1,'packio::server::dispatcher() const']]] ]; diff --git a/docs/search/functions_3.js b/docs/search/functions_3.js index e900248..0cb3d10 100644 --- a/docs/search/functions_3.js +++ b/docs/search/functions_3.js @@ -1,5 +1,5 @@ var searchData= [ - ['get_5fbuffer_5freserve_5fsize_106',['get_buffer_reserve_size',['../classpackio_1_1client.html#aca85c176d510c2065d7542328e2a84ab',1,'packio::client::get_buffer_reserve_size()'],['../classpackio_1_1server__session.html#af58a304a3af85ed97f6c2f56ddf2830e',1,'packio::server_session::get_buffer_reserve_size()']]], - ['get_5fexecutor_107',['get_executor',['../classpackio_1_1client.html#acc0445305bfcaeb5aec39f5830216060',1,'packio::client::get_executor()'],['../classpackio_1_1server.html#a54d82502040ab9e63e7f31c00988fb12',1,'packio::server::get_executor()'],['../classpackio_1_1server__session.html#ab36ba2101ee2e9ad5226282234fe0e08',1,'packio::server_session::get_executor()']]] + ['get_5fbuffer_5freserve_5fsize_112',['get_buffer_reserve_size',['../classpackio_1_1client.html#a2d520aa1e521fd90e58156c9d6fcfb6a',1,'packio::client::get_buffer_reserve_size()'],['../classpackio_1_1server__session.html#a68b291544e6a1b63434d74a6c4d29969',1,'packio::server_session::get_buffer_reserve_size()']]], + ['get_5fexecutor_113',['get_executor',['../classpackio_1_1client.html#a94eda9b4f05c93669304656b4408a120',1,'packio::client::get_executor()'],['../classpackio_1_1server.html#aa9de1435dd562dee7c021385b71cfd58',1,'packio::server::get_executor()'],['../classpackio_1_1server__session.html#aeaa34f73dad87f3a59d106c3f7efa118',1,'packio::server_session::get_executor()']]] ]; diff --git a/docs/search/functions_4.js b/docs/search/functions_4.js index c3bbe6e..3b02501 100644 --- a/docs/search/functions_4.js +++ b/docs/search/functions_4.js @@ -1,4 +1,4 @@ var searchData= [ - ['has_108',['has',['../classpackio_1_1dispatcher.html#ad9117a463423f2320550a45600a78f12',1,'packio::dispatcher']]] + ['has_114',['has',['../classpackio_1_1dispatcher.html#a84fd7d2a25577726e3ebb6e2367a123a',1,'packio::dispatcher']]] ]; diff --git a/docs/search/functions_5.js b/docs/search/functions_5.js index d592001..f295da5 100644 --- a/docs/search/functions_5.js +++ b/docs/search/functions_5.js @@ -1,4 +1,4 @@ var searchData= [ - ['known_109',['known',['../classpackio_1_1dispatcher.html#aed8b188e5d51c261f0622cd5269eb3ee',1,'packio::dispatcher']]] + ['known_115',['known',['../classpackio_1_1dispatcher.html#a91c7803eac9f56134e812ee1b604122f',1,'packio::dispatcher']]] ]; diff --git a/docs/search/functions_6.js b/docs/search/functions_6.js index bc4f3f0..f5aacb8 100644 --- a/docs/search/functions_6.js +++ b/docs/search/functions_6.js @@ -1,5 +1,5 @@ var searchData= [ - ['make_5fclient_110',['make_client',['../namespacepackio.html#ae41a42d5103a615a810d6e42d68906da',1,'packio']]], - ['make_5fserver_111',['make_server',['../namespacepackio.html#adb4190a7fda2259edbbe7684c2c5a766',1,'packio']]] + ['make_5fclient_116',['make_client',['../namespacepackio.html#a5a73a8453d35e9f6f0c29e9b87e93490',1,'packio::make_client()'],['../namespacepackio_1_1msgpack__rpc.html#a10bd3630d97339e416f5e407efece04d',1,'packio::msgpack_rpc::make_client()'],['../namespacepackio_1_1nl__json__rpc.html#a5e5b0abe3f0dbfc17fbd5d217df6b5e2',1,'packio::nl_json_rpc::make_client()']]], + ['make_5fserver_117',['make_server',['../namespacepackio_1_1msgpack__rpc.html#a437273529bff1d9196ae2afdf8233f9f',1,'packio::msgpack_rpc::make_server()'],['../namespacepackio_1_1nl__json__rpc.html#a55f9e2c9a4b823f4b1147413636c1e10',1,'packio::nl_json_rpc::make_server()'],['../namespacepackio.html#a4944e82d7f3dd2ee989a49d928cef3d3',1,'packio::make_server()']]] ]; diff --git a/docs/search/functions_7.js b/docs/search/functions_7.js index 1b3d43f..8719289 100644 --- a/docs/search/functions_7.js +++ b/docs/search/functions_7.js @@ -1,5 +1,5 @@ var searchData= [ - ['operator_28_29_112',['operator()',['../classpackio_1_1completion__handler.html#af8fc63fe1638048313ca2e081d1bfb7e',1,'packio::completion_handler::operator()(T &&return_value)'],['../classpackio_1_1completion__handler.html#ae88a9601765c0e6ee070a73ee70b60f9',1,'packio::completion_handler::operator()()']]], - ['operator_3d_113',['operator=',['../classpackio_1_1completion__handler.html#aeedf3e5ac4eeb5a8976a82aaca769bb9',1,'packio::completion_handler']]] + ['operator_28_29_118',['operator()',['../classpackio_1_1completion__handler.html#a525d3e3037436d4f190a36fc2c7cf755',1,'packio::completion_handler::operator()(T &&return_value)'],['../classpackio_1_1completion__handler.html#a79fa456e381d5967c8ac5ba1df3acb74',1,'packio::completion_handler::operator()()']]], + ['operator_3d_119',['operator=',['../classpackio_1_1completion__handler.html#ad1351e8aee5a4bbf44a7d0e94f9a618e',1,'packio::completion_handler']]] ]; diff --git a/docs/search/functions_8.js b/docs/search/functions_8.js index 2a9ec2f..80e6e1b 100644 --- a/docs/search/functions_8.js +++ b/docs/search/functions_8.js @@ -1,4 +1,4 @@ var searchData= [ - ['remove_114',['remove',['../classpackio_1_1dispatcher.html#a7c3bf380302ee8492a282cf83c35b42f',1,'packio::dispatcher']]] + ['remove_120',['remove',['../classpackio_1_1dispatcher.html#a28bead383b8dfcd95c0d18a9af342ad1',1,'packio::dispatcher']]] ]; diff --git a/docs/search/functions_9.js b/docs/search/functions_9.js index a8848db..dcafa60 100644 --- a/docs/search/functions_9.js +++ b/docs/search/functions_9.js @@ -1,9 +1,9 @@ var searchData= [ - ['server_115',['server',['../classpackio_1_1server.html#a1d957e4e7f7bfa0ae7744815b2e92184',1,'packio::server::server(acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)'],['../classpackio_1_1server.html#a46991dfa12d830c2eb3c2ba078effafc',1,'packio::server::server(acceptor_type acceptor)']]], - ['set_5fbuffer_5freserve_5fsize_116',['set_buffer_reserve_size',['../classpackio_1_1client.html#a14484788c6a5ec629e9ebb54a5971fd6',1,'packio::client::set_buffer_reserve_size()'],['../classpackio_1_1server__session.html#a4eb23e0e0dd78ff5fec025c10866970e',1,'packio::server_session::set_buffer_reserve_size()']]], - ['set_5ferror_117',['set_error',['../classpackio_1_1completion__handler.html#a19f6a250a6b0b5bc1d09b9b8948f5a9e',1,'packio::completion_handler::set_error(T &&error_value)'],['../classpackio_1_1completion__handler.html#ac99c708ff2220893a4446cec9eaa59fc',1,'packio::completion_handler::set_error()']]], - ['set_5fvalue_118',['set_value',['../classpackio_1_1completion__handler.html#a62c027610298c8e4b4d6d6cec3ab58e2',1,'packio::completion_handler::set_value(T &&return_value)'],['../classpackio_1_1completion__handler.html#a0802f6b6c5382f352dd196e1f600f2af',1,'packio::completion_handler::set_value()']]], - ['socket_119',['socket',['../classpackio_1_1client.html#a9604a810a325d5a761d752657f51f139',1,'packio::client::socket() noexcept'],['../classpackio_1_1client.html#a99bc6645de7020bd37e356b245817a85',1,'packio::client::socket() const noexcept'],['../classpackio_1_1server__session.html#a4f48ee3c8b5226c06ed2fd0a249d8405',1,'packio::server_session::socket()'],['../classpackio_1_1server__session.html#a876b18d9307ba6cc5f75c55b040764d5',1,'packio::server_session::socket() const']]], - ['start_120',['start',['../classpackio_1_1server__session.html#ae52740e61342e388a27f65f01cc3376f',1,'packio::server_session']]] + ['server_121',['server',['../classpackio_1_1server.html#a4862f9f94b6112171ba8ac5549305084',1,'packio::server::server(acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)'],['../classpackio_1_1server.html#a015f43f073e5bcbb1ae12a5489fcd6a5',1,'packio::server::server(acceptor_type acceptor)']]], + ['set_5fbuffer_5freserve_5fsize_122',['set_buffer_reserve_size',['../classpackio_1_1client.html#aa76167481dc66a2b7d0bda6ab7eead1d',1,'packio::client::set_buffer_reserve_size()'],['../classpackio_1_1server__session.html#a0ae604b3897fd019f8dbaa491ab4012c',1,'packio::server_session::set_buffer_reserve_size()']]], + ['set_5ferror_123',['set_error',['../classpackio_1_1completion__handler.html#adba2b11b3e079002662ca2756c856f0d',1,'packio::completion_handler::set_error(T &&error_value)'],['../classpackio_1_1completion__handler.html#a125d19c56aa53ccb9b7054cd7c2a8928',1,'packio::completion_handler::set_error()']]], + ['set_5fvalue_124',['set_value',['../classpackio_1_1completion__handler.html#a2f2b5f77586b631bf4426fd4c758bd15',1,'packio::completion_handler::set_value(T &&return_value)'],['../classpackio_1_1completion__handler.html#ae11f5b5410582755090957cabf6ddcc8',1,'packio::completion_handler::set_value()']]], + ['socket_125',['socket',['../classpackio_1_1client.html#a97dbdacc125af0464dca3a37761e4e18',1,'packio::client::socket() noexcept'],['../classpackio_1_1client.html#ab6f8392c2db28ce9bf67c8290837c011',1,'packio::client::socket() const noexcept'],['../classpackio_1_1server__session.html#a74cc5ac0eefaf0edfcef3bb9666359b9',1,'packio::server_session::socket()'],['../classpackio_1_1server__session.html#a1fa1898f17fb73ad8469987b4a81033f',1,'packio::server_session::socket() const']]], + ['start_126',['start',['../classpackio_1_1server__session.html#aca595d69b5e342e4b46e73adaa2969ba',1,'packio::server_session']]] ]; diff --git a/docs/search/functions_a.js b/docs/search/functions_a.js index 3dfedcc..cd6aab9 100644 --- a/docs/search/functions_a.js +++ b/docs/search/functions_a.js @@ -1,4 +1,4 @@ var searchData= [ - ['_7ecompletion_5fhandler_121',['~completion_handler',['../classpackio_1_1completion__handler.html#adfb61907d9efb108be79040140ebbcd9',1,'packio::completion_handler']]] + ['_7ecompletion_5fhandler_127',['~completion_handler',['../classpackio_1_1completion__handler.html#ab171e21dd2e0508e96fd908a542b79b5',1,'packio::completion_handler']]] ]; diff --git a/docs/search/namespaces_0.js b/docs/search/namespaces_0.js index 66b38cb..22a826a 100644 --- a/docs/search/namespaces_0.js +++ b/docs/search/namespaces_0.js @@ -1,4 +1,6 @@ var searchData= [ - ['packio_81',['packio',['../namespacepackio.html',1,'']]] + ['msgpack_5frpc_86',['msgpack_rpc',['../namespacepackio_1_1msgpack__rpc.html',1,'packio']]], + ['nl_5fjson_5frpc_87',['nl_json_rpc',['../namespacepackio_1_1nl__json__rpc.html',1,'packio']]], + ['packio_88',['packio',['../namespacepackio.html',1,'']]] ]; diff --git a/docs/search/pages_0.js b/docs/search/pages_0.js index a4b3476..9569f9d 100644 --- a/docs/search/pages_0.js +++ b/docs/search/pages_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['header_2donly_20_7c_20msgpack_2drpc_20_7c_20asio_20_7c_20coroutines_139',['Header-only | msgpack-RPC | asio | coroutines',['../index.html',1,'']]] + ['header_2donly_20_7c_20json_2drpc_20_7c_20msgpack_2drpc_20_7c_20asio_20_7c_20coroutines_149',['Header-only | JSON-RPC | msgpack-RPC | asio | coroutines',['../index.html',1,'']]] ]; diff --git a/docs/search/searchdata.js b/docs/search/searchdata.js index 407d83c..bbe5eda 100644 --- a/docs/search/searchdata.js +++ b/docs/search/searchdata.js @@ -1,15 +1,13 @@ var indexSectionsWithContent = { - 0: "abcdefghikmnoprstu~", - 1: "acdns", + 0: "acdefghikmnoprstz~", + 1: "acdinrs", 2: "p", - 3: "acdehmpst", + 3: "acdhmnpst", 4: "acdghkmors~", - 5: "k", - 6: "adefimps", - 7: "e", - 8: "bcesu", - 9: "h" + 5: "kz", + 6: "acdefimnprs", + 7: "h" }; var indexSectionNames = @@ -21,9 +19,7 @@ var indexSectionNames = 4: "functions", 5: "variables", 6: "typedefs", - 7: "enums", - 8: "enumvalues", - 9: "pages" + 7: "pages" }; var indexSectionLabels = @@ -35,8 +31,6 @@ var indexSectionLabels = 4: "Functions", 5: "Variables", 6: "Typedefs", - 7: "Enumerations", - 8: "Enumerator", - 9: "Pages" + 7: "Pages" }; diff --git a/docs/search/typedefs_0.js b/docs/search/typedefs_0.js index 09009de..dc0a58b 100644 --- a/docs/search/typedefs_0.js +++ b/docs/search/typedefs_0.js @@ -1,4 +1,5 @@ var searchData= [ - ['acceptor_5ftype_123',['acceptor_type',['../classpackio_1_1server.html#a4bcd39b0d3f5a297e476382b97402707',1,'packio::server']]] + ['acceptor_5ftype_130',['acceptor_type',['../classpackio_1_1server.html#a07df9eaed3acb33686a40869f3e0a341',1,'packio::server']]], + ['args_5ftype_131',['args_type',['../classpackio_1_1dispatcher.html#abaf51d5af8c29af5e198d9a6a2272a0d',1,'packio::dispatcher']]] ]; diff --git a/docs/search/typedefs_1.js b/docs/search/typedefs_1.js index 7090288..ffd21d0 100644 --- a/docs/search/typedefs_1.js +++ b/docs/search/typedefs_1.js @@ -1,4 +1,5 @@ var searchData= [ - ['dispatcher_5ftype_124',['dispatcher_type',['../classpackio_1_1server.html#a57a2a6a784736a55bec1f2e099f47a67',1,'packio::server']]] + ['client_132',['client',['../namespacepackio_1_1msgpack__rpc.html#a49d32a81a0e25f0afd20c06b0f3be038',1,'packio::msgpack_rpc::client()'],['../namespacepackio_1_1nl__json__rpc.html#aee1e8414a3dbc89c9b65f51be2cd267e',1,'packio::nl_json_rpc::client()']]], + ['completion_5fhandler_133',['completion_handler',['../namespacepackio_1_1msgpack__rpc.html#a5f26747f38ee4b858478d242f2d1fb93',1,'packio::msgpack_rpc::completion_handler()'],['../namespacepackio_1_1nl__json__rpc.html#a00239c9c3a310e25dc8641e5056815e9',1,'packio::nl_json_rpc::completion_handler()']]] ]; diff --git a/docs/search/typedefs_2.js b/docs/search/typedefs_2.js index 90c0351..2fe79d3 100644 --- a/docs/search/typedefs_2.js +++ b/docs/search/typedefs_2.js @@ -1,4 +1,5 @@ var searchData= [ - ['executor_5ftype_125',['executor_type',['../classpackio_1_1client.html#a0f2f08560e2ee10a7adbce5206d94a13',1,'packio::client::executor_type()'],['../classpackio_1_1server.html#a04594e9ee178269b5ae9a8b7f03967da',1,'packio::server::executor_type()'],['../classpackio_1_1server__session.html#a7ebcbb24ebb5b5a9dcd55d3f676b736b',1,'packio::server_session::executor_type()']]] + ['dispatcher_134',['dispatcher',['../namespacepackio_1_1msgpack__rpc.html#ae3d9c63288b95af71c1f562c8a348437',1,'packio::msgpack_rpc::dispatcher()'],['../namespacepackio_1_1nl__json__rpc.html#a04c96d3c7fdf708974d27d3616963237',1,'packio::nl_json_rpc::dispatcher()']]], + ['dispatcher_5ftype_135',['dispatcher_type',['../classpackio_1_1server.html#afaa03c3f3530583592670426de2834d5',1,'packio::server']]] ]; diff --git a/docs/search/typedefs_3.js b/docs/search/typedefs_3.js index 8d3d7f9..13f1268 100644 --- a/docs/search/typedefs_3.js +++ b/docs/search/typedefs_3.js @@ -1,5 +1,4 @@ var searchData= [ - ['function_5fptr_5ftype_126',['function_ptr_type',['../classpackio_1_1dispatcher.html#a0e935dee0a2a56517961836dbfd70a3e',1,'packio::dispatcher']]], - ['function_5ftype_127',['function_type',['../classpackio_1_1dispatcher.html#af4ef54bdd2549a659f71e59b9fc76cff',1,'packio::dispatcher']]] + ['executor_5ftype_136',['executor_type',['../classpackio_1_1client.html#a8a22f81e73a8c46b18a21e513e203a34',1,'packio::client::executor_type()'],['../classpackio_1_1server.html#a0e5f3b1946c1da4f81a412b972a2c782',1,'packio::server::executor_type()'],['../classpackio_1_1server__session.html#a48876882ec8f7851967a4d24cf283a7a',1,'packio::server_session::executor_type()']]] ]; diff --git a/docs/search/typedefs_4.js b/docs/search/typedefs_4.js index 0c6c3c2..7eeb8ce 100644 --- a/docs/search/typedefs_4.js +++ b/docs/search/typedefs_4.js @@ -1,4 +1,5 @@ var searchData= [ - ['id_5ftype_128',['id_type',['../namespacepackio.html#a02aa56c39599b9cde75f298011dc87e8',1,'packio']]] + ['function_5fptr_5ftype_137',['function_ptr_type',['../classpackio_1_1dispatcher.html#a07af82e8eb144bdf958bed2cceb971fb',1,'packio::dispatcher']]], + ['function_5ftype_138',['function_type',['../classpackio_1_1dispatcher.html#aa74c0085ec00aa5e419e3b8cf295fffd',1,'packio::dispatcher']]] ]; diff --git a/docs/search/typedefs_5.js b/docs/search/typedefs_5.js index 31e4f9a..1dcac4c 100644 --- a/docs/search/typedefs_5.js +++ b/docs/search/typedefs_5.js @@ -1,4 +1,5 @@ var searchData= [ - ['mutex_5ftype_129',['mutex_type',['../classpackio_1_1dispatcher.html#aa2d5ff7c0b29f52b03b5db7488ee1378',1,'packio::dispatcher']]] + ['id_5ftype_139',['id_type',['../classpackio_1_1client.html#a86896af2ccaed0262e8dfe8728ce3809',1,'packio::client::id_type()'],['../classpackio_1_1msgpack__rpc_1_1rpc.html#aea7c1f825093a6d6c66d4cb76df96624',1,'packio::msgpack_rpc::rpc::id_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#aa09ce5e5f80fd516e8f1368bb965d83f',1,'packio::nl_json_rpc::rpc::id_type()']]], + ['incremental_5fparser_5ftype_140',['incremental_parser_type',['../classpackio_1_1msgpack__rpc_1_1rpc.html#a3fb072c8ede82fec07c834b97f95c645',1,'packio::msgpack_rpc::rpc::incremental_parser_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#a04f825324bf02549b978ff521c12c4b0',1,'packio::nl_json_rpc::rpc::incremental_parser_type()']]] ]; diff --git a/docs/search/typedefs_6.js b/docs/search/typedefs_6.js index 13707ea..9af9aaa 100644 --- a/docs/search/typedefs_6.js +++ b/docs/search/typedefs_6.js @@ -1,4 +1,4 @@ var searchData= [ - ['protocol_5ftype_130',['protocol_type',['../classpackio_1_1client.html#a15b4926e18f5c3221412ae885f318a3a',1,'packio::client::protocol_type()'],['../classpackio_1_1server.html#ac3cca245e7251e2f834407bbfe6e0aaa',1,'packio::server::protocol_type()'],['../classpackio_1_1server__session.html#af544ff51d72997416c11bc8c8de4a9f9',1,'packio::server_session::protocol_type()']]] + ['mutex_5ftype_141',['mutex_type',['../classpackio_1_1dispatcher.html#aef789d54a0d2fa86837d029606881313',1,'packio::dispatcher']]] ]; diff --git a/docs/search/typedefs_7.js b/docs/search/typedefs_7.js index 094c879..45bbf88 100644 --- a/docs/search/typedefs_7.js +++ b/docs/search/typedefs_7.js @@ -1,4 +1,4 @@ var searchData= [ - ['socket_5ftype_131',['socket_type',['../classpackio_1_1client.html#a6f710205e0426368bd4fc1e973d0e377',1,'packio::client::socket_type()'],['../classpackio_1_1server.html#ac42874f5c340ba691c88a6ea1d44c836',1,'packio::server::socket_type()'],['../classpackio_1_1server__session.html#ab9ab57c300970cc8dbf520f214a43534',1,'packio::server_session::socket_type()']]] + ['native_5ftype_142',['native_type',['../classpackio_1_1msgpack__rpc_1_1rpc.html#a34db8ce79c9de47fe5f8245eec851fdb',1,'packio::msgpack_rpc::rpc::native_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#a9d356881153c1ee2c93e7e31d49bde4b',1,'packio::nl_json_rpc::rpc::native_type()']]] ]; diff --git a/docs/search/typedefs_8.html b/docs/search/typedefs_8.html new file mode 100644 index 0000000..52ab5aa --- /dev/null +++ b/docs/search/typedefs_8.html @@ -0,0 +1,30 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/docs/search/typedefs_8.js b/docs/search/typedefs_8.js new file mode 100644 index 0000000..4bea2dc --- /dev/null +++ b/docs/search/typedefs_8.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['protocol_5ftype_143',['protocol_type',['../classpackio_1_1client.html#a6d4173ba81572e0e1d11d4e83d57ab90',1,'packio::client::protocol_type()'],['../classpackio_1_1server.html#aeca24e496aec70feb6c1363b760a6e55',1,'packio::server::protocol_type()'],['../classpackio_1_1server__session.html#a555264e82920fac940e21abb4ca7f098',1,'packio::server_session::protocol_type()']]] +]; diff --git a/docs/search/typedefs_9.html b/docs/search/typedefs_9.html new file mode 100644 index 0000000..7b6dd85 --- /dev/null +++ b/docs/search/typedefs_9.html @@ -0,0 +1,30 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/docs/search/typedefs_9.js b/docs/search/typedefs_9.js new file mode 100644 index 0000000..b107a7b --- /dev/null +++ b/docs/search/typedefs_9.js @@ -0,0 +1,6 @@ +var searchData= +[ + ['request_5ftype_144',['request_type',['../classpackio_1_1msgpack__rpc_1_1rpc.html#a1281d8595df97aea44d465ee0bd14387',1,'packio::msgpack_rpc::rpc::request_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#ae80e929ba5d0ffd30ff50d7682227005',1,'packio::nl_json_rpc::rpc::request_type()']]], + ['response_5ftype_145',['response_type',['../classpackio_1_1client.html#a9ffe5dfb1595bcd55ab2d3e69e5261f3',1,'packio::client::response_type()'],['../classpackio_1_1msgpack__rpc_1_1rpc.html#ae326edcb041af393608f749829861a1f',1,'packio::msgpack_rpc::rpc::response_type()'],['../classpackio_1_1nl__json__rpc_1_1rpc.html#a4cc97964ab0d4fd9a5fed97516b2ffd2',1,'packio::nl_json_rpc::rpc::response_type()']]], + ['rpc_5ftype_146',['rpc_type',['../classpackio_1_1client.html#a5d35a309258ce540e94004b27f7dbe3b',1,'packio::client::rpc_type()'],['../classpackio_1_1dispatcher.html#ac9b6747517bc29485466d00692979195',1,'packio::dispatcher::rpc_type()'],['../classpackio_1_1server.html#abbb6ae551a947e25fac4b2958c3238f1',1,'packio::server::rpc_type()']]] +]; diff --git a/docs/search/typedefs_a.html b/docs/search/typedefs_a.html new file mode 100644 index 0000000..ba5e668 --- /dev/null +++ b/docs/search/typedefs_a.html @@ -0,0 +1,30 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/docs/search/typedefs_a.js b/docs/search/typedefs_a.js new file mode 100644 index 0000000..3a55663 --- /dev/null +++ b/docs/search/typedefs_a.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['server_147',['server',['../namespacepackio_1_1msgpack__rpc.html#a34d73db89c36af6b191cb1b148ba77d2',1,'packio::msgpack_rpc::server()'],['../namespacepackio_1_1nl__json__rpc.html#a7509cdc0bd479cc90a81a391ac04c239',1,'packio::nl_json_rpc::server()']]], + ['socket_5ftype_148',['socket_type',['../classpackio_1_1client.html#a9b06b233bdcf0f6d14db967ba45826c4',1,'packio::client::socket_type()'],['../classpackio_1_1server.html#aeadaf22c6898985ed5b49b1d27e85365',1,'packio::server::socket_type()'],['../classpackio_1_1server__session.html#a1115ebfdbbd4413ae7f5cbf99a8c6dda',1,'packio::server_session::socket_type()']]] +]; diff --git a/docs/search/variables_0.js b/docs/search/variables_0.js index 2457ed1..a3b651e 100644 --- a/docs/search/variables_0.js +++ b/docs/search/variables_0.js @@ -1,4 +1,4 @@ var searchData= [ - ['kdefaultbufferreservesize_122',['kDefaultBufferReserveSize',['../classpackio_1_1client.html#a2f73dd57767e2dac677ffd03b672e6c5',1,'packio::client::kDefaultBufferReserveSize()'],['../classpackio_1_1server__session.html#abb614afb4157378d1a533312880af595',1,'packio::server_session::kDefaultBufferReserveSize()']]] + ['kdefaultbufferreservesize_128',['kDefaultBufferReserveSize',['../classpackio_1_1client.html#ad4e5a705e61a06ffa999e7c2cbf42cb2',1,'packio::client::kDefaultBufferReserveSize()'],['../classpackio_1_1server__session.html#abda9254cbf38a8b0644b3603e55b2c15',1,'packio::server_session::kDefaultBufferReserveSize()']]] ]; diff --git a/docs/search/variables_1.html b/docs/search/variables_1.html new file mode 100644 index 0000000..49fe59a --- /dev/null +++ b/docs/search/variables_1.html @@ -0,0 +1,30 @@ + + + + + + + + + +
+
Loading...
+
+ +
Searching...
+
No Matches
+ +
+ + diff --git a/docs/search/variables_1.js b/docs/search/variables_1.js new file mode 100644 index 0000000..3055b21 --- /dev/null +++ b/docs/search/variables_1.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['zone_129',['zone',['../structpackio_1_1msgpack__rpc_1_1internal_1_1request.html#ad05950fc46bacf68d602e20f83f4d64d',1,'packio::msgpack_rpc::internal::request::zone()'],['../structpackio_1_1msgpack__rpc_1_1internal_1_1response.html#ab86f414bf7f829e328923e78c77936be',1,'packio::msgpack_rpc::internal::response::zone()']]] +]; diff --git a/docs/server_8h.html b/docs/server_8h.html index 85c4d85..e164e21 100644 --- a/docs/server_8h.html +++ b/docs/server_8h.html @@ -76,7 +76,6 @@
#include <memory>
-#include <msgpack.hpp>
#include "dispatcher.h"
#include "internal/config.h"
#include "internal/log.h"
@@ -88,7 +87,7 @@ - +

Classes

class  packio::server< Acceptor, Dispatcher >
class  packio::server< Rpc, Acceptor, Dispatcher >
 The server class. More...
 
@@ -99,10 +98,10 @@
- - - - + + + +

Functions

template<typename Acceptor , typename Dispatcher = dispatcher<>>
auto packio::make_server (Acceptor &&acceptor)
 Create a server from an acceptor. More...
 
template<typename Rpc , typename Acceptor , typename Dispatcher = dispatcher<Rpc>>
auto packio::make_server (Acceptor &&acceptor)
 Create a server from an acceptor. More...
 

Detailed Description

Class server

diff --git a/docs/server_8h_source.html b/docs/server_8h_source.html index 181438d..6022303 100644 --- a/docs/server_8h_source.html +++ b/docs/server_8h_source.html @@ -81,56 +81,56 @@
10 
11 #include <memory>
12 
-
13 #include <msgpack.hpp>
-
14 
-
15 #include "dispatcher.h"
-
16 #include "internal/config.h"
-
17 #include "internal/log.h"
-
18 #include "internal/utils.h"
-
19 #include "server_session.h"
-
20 #include "traits.h"
+
13 #include "dispatcher.h"
+
14 #include "internal/config.h"
+
15 #include "internal/log.h"
+
16 #include "internal/utils.h"
+
17 #include "server_session.h"
+
18 #include "traits.h"
+
19 
+
20 namespace packio {
21 
-
22 namespace packio {
-
23 
-
27 template <typename Acceptor, typename Dispatcher = dispatcher<>>
-
28 class server : public std::enable_shared_from_this<server<Acceptor, Dispatcher>> {
+
26 template <typename Rpc, typename Acceptor, typename Dispatcher = dispatcher<Rpc>>
+
27 class server
+
28  : public std::enable_shared_from_this<server<Rpc, Acceptor, Dispatcher>> {
29 public:
-
30  using acceptor_type = Acceptor;
-
31  using protocol_type = typename Acceptor::protocol_type;
-
32  using dispatcher_type = Dispatcher;
-
33  using executor_type =
-
34  typename acceptor_type::executor_type;
-
35  using socket_type = std::decay_t<decltype(
-
36  std::declval<acceptor_type>().accept())>;
- -
38 
-
39  using std::enable_shared_from_this<server<Acceptor, Dispatcher>>::shared_from_this;
-
40 
-
45  server(acceptor_type acceptor, std::shared_ptr<dispatcher_type> dispatcher)
-
46  : acceptor_{std::move(acceptor)}, dispatcher_ptr_{std::move(dispatcher)}
-
47  {
-
48  }
-
49 
- -
53  : server{std::move(acceptor), std::make_shared<dispatcher_type>()}
+
30  using rpc_type = Rpc;
+
31  using acceptor_type = Acceptor;
+
32  using protocol_type = typename Acceptor::protocol_type;
+
33  using dispatcher_type = Dispatcher;
+
34  using executor_type =
+
35  typename acceptor_type::executor_type;
+
36  using socket_type = std::decay_t<decltype(
+
37  std::declval<acceptor_type>().accept())>;
+ +
39 
+
40  using std::enable_shared_from_this<server<Rpc, Acceptor, Dispatcher>>::shared_from_this;
+
41 
+
46  server(acceptor_type acceptor, std::shared_ptr<dispatcher_type> dispatcher)
+
47  : acceptor_{std::move(acceptor)}, dispatcher_ptr_{std::move(dispatcher)}
+
48  {
+
49  }
+
50 
+ +
53  : server{std::move(acceptor), std::make_shared<dispatcher_type>()}
54  {
55  }
56 
-
58  acceptor_type& acceptor() { return acceptor_; }
-
60  const acceptor_type& acceptor() const { return acceptor_; }
+
58  acceptor_type& acceptor() { return acceptor_; }
+
60  const acceptor_type& acceptor() const { return acceptor_; }
61 
-
63  std::shared_ptr<dispatcher_type> dispatcher() { return dispatcher_ptr_; }
-
65  std::shared_ptr<const dispatcher_type> dispatcher() const
+
63  std::shared_ptr<dispatcher_type> dispatcher() { return dispatcher_ptr_; }
+
65  std::shared_ptr<const dispatcher_type> dispatcher() const
66  {
67  return dispatcher_ptr_;
68  }
69 
-
71  executor_type get_executor() { return acceptor().get_executor(); }
+
71  executor_type get_executor() { return acceptor().get_executor(); }
72 
78  template <PACKIO_COMPLETION_TOKEN_FOR(void(error_code, std::shared_ptr<session_type>))
79  ServeHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
- -
81  ServeHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
+ +
81  ServeHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
82  {
83  return net::async_initiate<
84  ServeHandler,
@@ -138,9 +138,9 @@
86  initiate_async_serve(this), handler);
87  }
88 
- +
91  {
-
92  async_serve([self = shared_from_this()](auto ec, auto session) {
+
92  async_serve([self = shared_from_this()](auto ec, auto session) {
93  if (ec) {
94  return;
95  }
@@ -153,11 +153,11 @@
102 private:
103  class initiate_async_serve {
104  public:
-
105  using executor_type = typename server::executor_type;
+
105  using executor_type = typename server::executor_type;
106 
107  explicit initiate_async_serve(server* self) : self_(self) {}
108 
-
109  executor_type get_executor() const noexcept
+
109  executor_type get_executor() const noexcept
110  {
111  return self_->get_executor();
112  }
@@ -171,7 +171,7 @@
120  self_->acceptor_.async_accept(
121  [self = self_->shared_from_this(),
122  handler = std::forward<ServeHandler>(handler)](
-
123  error_code ec, socket_type sock) mutable {
+
123  error_code ec, socket_type sock) mutable {
124  std::shared_ptr<session_type> session;
125  if (ec) {
126  PACKIO_WARN("accept error: {}", ec.message());
@@ -186,46 +186,47 @@
135  }
136 
137  private:
-
138  server* self_;
+
138  server* self_;
139  };
140 
141  acceptor_type acceptor_;
142  std::shared_ptr<dispatcher_type> dispatcher_ptr_;
143 };
144 
-
148 template <typename Acceptor, typename Dispatcher = dispatcher<>>
-
149 auto make_server(Acceptor&& acceptor)
-
150 {
-
151  return std::make_shared<server<Acceptor, Dispatcher>>(
-
152  std::forward<Acceptor>(acceptor));
-
153 }
-
154 
-
155 } // packio
-
156 
-
157 #endif // PACKIO_SERVER_H
+
149 template <typename Rpc, typename Acceptor, typename Dispatcher = dispatcher<Rpc>>
+
150 auto make_server(Acceptor&& acceptor)
+
151 {
+
152  return std::make_shared<server<Rpc, Acceptor, Dispatcher>>(
+
153  std::forward<Acceptor>(acceptor));
+
154 }
+
155 
+
156 } // packio
+
157 
+
158 #endif // PACKIO_SERVER_H
-
std::decay_t< decltype(std::declval< acceptor_type >().accept())> socket_type
The connection socket type.
Definition: server.h:36
+
typename acceptor_type::executor_type executor_type
The executor type.
Definition: server.h:35
+
Dispatcher dispatcher_type
The dispatcher type.
Definition: server.h:33
-
The server class.
Definition: server.h:28
-
The dispatcher class, used to store and dispatch procedures.
Definition: dispatcher.h:33
-
const acceptor_type & acceptor() const
Get the underlying acceptor, const.
Definition: server.h:60
-
auto async_serve(ServeHandler &&handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type))
Accept one connection and initialize a session for it.
Definition: server.h:80
-
typename Acceptor::protocol_type protocol_type
The protocol type.
Definition: server.h:31
-
server(acceptor_type acceptor)
Simplified constructor: will allocate a new dispatcher automatically This is an overloaded member fun...
Definition: server.h:52
-
std::shared_ptr< const dispatcher_type > dispatcher() const
Get the dispatcher, const.
Definition: server.h:65
-
The server_session class, created by the server.
Definition: server_session.h:26
-
Definition: as.h:16
-
auto make_server(Acceptor &&acceptor)
Create a server from an acceptor.
Definition: server.h:149
-
Dispatcher dispatcher_type
The dispatcher type.
Definition: server.h:32
-
server(acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)
The constructor.
Definition: server.h:45
-
executor_type get_executor()
Get the executor associated with the object.
Definition: server.h:71
-
typename acceptor_type::executor_type executor_type
The executor type.
Definition: server.h:34
-
void async_serve_forever()
Accept connections and automatically start the associated sessions forever.
Definition: server.h:90
-
acceptor_type & acceptor()
Get the underlying acceptor.
Definition: server.h:58
+
The server class.
Definition: server.h:27
+
The dispatcher class, used to store and dispatch procedures.
Definition: dispatcher.h:32
+
void async_serve_forever()
Accept connections and automatically start the associated sessions forever.
Definition: server.h:90
+
const acceptor_type & acceptor() const
Get the underlying acceptor, const.
Definition: server.h:60
+
Acceptor acceptor_type
The acceptor type.
Definition: server.h:31
+
typename Acceptor::protocol_type protocol_type
The protocol type.
Definition: server.h:32
+
The server_session class, created by the server.
Definition: server_session.h:25
+
Definition: arg.h:14
+
server(acceptor_type acceptor, std::shared_ptr< dispatcher_type > dispatcher)
The constructor.
Definition: server.h:46
+
std::decay_t< decltype(std::declval< acceptor_type >().accept())> socket_type
The connection socket type.
Definition: server.h:37
+
acceptor_type & acceptor()
Get the underlying acceptor.
Definition: server.h:58
+
auto async_serve(ServeHandler &&handler=typename net::default_completion_token< executor_type >::type())
Accept one connection and initialize a session for it.
Definition: server.h:80
+
Rpc rpc_type
The RPC protocol type.
Definition: server.h:30
+
auto make_server(Acceptor &&acceptor)
Create a server from an acceptor.
Definition: server.h:150
-
std::shared_ptr< dispatcher_type > dispatcher()
Get the dispatcher.
Definition: server.h:63
+
executor_type get_executor()
Get the executor associated with the object.
Definition: server.h:71
+
server(acceptor_type acceptor)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: server.h:52
+
std::shared_ptr< const dispatcher_type > dispatcher() const
Get the dispatcher, const.
Definition: server.h:65
-
Acceptor acceptor_type
The acceptor type.
Definition: server.h:30
+
std::shared_ptr< dispatcher_type > dispatcher()
Get the dispatcher.
Definition: server.h:63
diff --git a/docs/server__session_8h.html b/docs/server__session_8h.html index 7dd21a1..47f8063 100644 --- a/docs/server__session_8h.html +++ b/docs/server__session_8h.html @@ -76,19 +76,18 @@
#include <memory>
#include <queue>
-#include <msgpack.hpp>
-#include "error_code.h"
+#include "handler.h"
#include "internal/config.h"
#include "internal/log.h"
#include "internal/manual_strand.h"
-#include "internal/msgpack_rpc.h"
+#include "internal/rpc.h"
#include "internal/utils.h"

Go to the source code of this file.

- +

Classes

class  packio::server_session< Socket, Dispatcher >
class  packio::server_session< Rpc, Socket, Dispatcher >
 The server_session class, created by the server. More...
 
diff --git a/docs/server__session_8h_source.html b/docs/server__session_8h_source.html index a51095d..23a2c89 100644 --- a/docs/server__session_8h_source.html +++ b/docs/server__session_8h_source.html @@ -81,276 +81,188 @@
10 
11 #include <memory>
12 #include <queue>
-
13 #include <msgpack.hpp>
-
14 
-
15 #include "error_code.h"
-
16 #include "internal/config.h"
-
17 #include "internal/log.h"
-
18 #include "internal/manual_strand.h"
-
19 #include "internal/msgpack_rpc.h"
-
20 #include "internal/utils.h"
-
21 
-
22 namespace packio {
-
23 
-
25 template <typename Socket, typename Dispatcher>
- -
27  : public std::enable_shared_from_this<server_session<Socket, Dispatcher>> {
-
28 public:
-
29  using socket_type = Socket;
-
30  using protocol_type =
-
31  typename socket_type::protocol_type;
-
32  using executor_type =
-
33  typename socket_type::executor_type;
-
34  using std::enable_shared_from_this<server_session<Socket, Dispatcher>>::shared_from_this;
-
35 
-
37  static constexpr size_t kDefaultBufferReserveSize = 4096;
-
38 
-
39  server_session(socket_type sock, std::shared_ptr<Dispatcher> dispatcher_ptr)
-
40  : socket_{std::move(sock)},
-
41  dispatcher_ptr_{std::move(dispatcher_ptr)},
-
42  wstrand_{socket_.get_executor()}
-
43  {
-
44  }
-
45 
-
47  socket_type& socket() { return socket_; }
-
49  const socket_type& socket() const { return socket_; }
-
50 
-
52  executor_type get_executor() { return socket().get_executor(); }
-
53 
-
55  void set_buffer_reserve_size(std::size_t size) noexcept
-
56  {
-
57  buffer_reserve_size_ = size;
-
58  }
-
60  std::size_t get_buffer_reserve_size() const noexcept
-
61  {
-
62  return buffer_reserve_size_;
-
63  }
-
64 
-
66  void start() { async_read(std::make_unique<msgpack::unpacker>()); }
-
67 
-
68 private:
-
69  using buffer_type = msgpack::vrefbuffer; // non-owning buffer
-
70  using message_type = std::tuple<buffer_type, msgpack::object_handle>;
-
71  using message_queue = std::queue<std::unique_ptr<message_type>>;
-
72 
-
73  struct Call {
-
74  msgpack_rpc_type type;
-
75  id_type id;
-
76  std::string name;
-
77  msgpack::object args;
-
78  };
-
79 
-
80  void async_read(std::unique_ptr<msgpack::unpacker> unpacker)
-
81  {
-
82  // abort R/W on error
-
83  if (!socket_.is_open()) {
-
84  return;
-
85  }
-
86 
-
87  unpacker->reserve_buffer(buffer_reserve_size_);
-
88  auto buffer = net::buffer(
-
89  unpacker->buffer(), unpacker->buffer_capacity());
-
90  socket_.async_read_some(
-
91  buffer,
-
92  [self = shared_from_this(), unpacker = std::move(unpacker)](
-
93  error_code ec, size_t length) mutable {
-
94  if (ec) {
-
95  PACKIO_WARN("read error: {}", ec.message());
-
96  self->close_connection();
-
97  return;
-
98  }
-
99 
-
100  PACKIO_TRACE("read: {}", length);
-
101  unpacker->buffer_consumed(length);
-
102 
-
103  for (msgpack::object_handle call; unpacker->next(call);) {
-
104  // handle the call asynchronously (post)
-
105  // to schedule the next read immediately
-
106  // this will allow parallel call handling
-
107  // in multi-threaded environments
-
108  net::post(
-
109  self->get_executor(), [self, call = std::move(call)] {
-
110  self->dispatch(call.get());
-
111  });
-
112  }
-
113 
-
114  self->async_read(std::move(unpacker));
-
115  });
-
116  }
-
117 
-
118  void dispatch(const msgpack::object& msgpack_call)
-
119  {
-
120  std::optional<Call> call = parse_call(msgpack_call);
-
121  if (!call) {
-
122  close_connection();
-
123  return;
-
124  }
+
13 
+
14 #include "handler.h"
+
15 #include "internal/config.h"
+
16 #include "internal/log.h"
+
17 #include "internal/manual_strand.h"
+
18 #include "internal/rpc.h"
+
19 #include "internal/utils.h"
+
20 
+
21 namespace packio {
+
22 
+
24 template <typename Rpc, typename Socket, typename Dispatcher>
+ +
26  : public std::enable_shared_from_this<server_session<Rpc, Socket, Dispatcher>> {
+
27 public:
+
28  using socket_type = Socket;
+
29  using protocol_type =
+
30  typename socket_type::protocol_type;
+
31  using executor_type =
+
32  typename socket_type::executor_type;
+
33  using std::enable_shared_from_this<server_session<Rpc, Socket, Dispatcher>>::shared_from_this;
+
34 
+
36  static constexpr size_t kDefaultBufferReserveSize = 4096;
+
37 
+
38  server_session(socket_type sock, std::shared_ptr<Dispatcher> dispatcher_ptr)
+
39  : socket_{std::move(sock)},
+
40  dispatcher_ptr_{std::move(dispatcher_ptr)},
+
41  wstrand_{socket_.get_executor()}
+
42  {
+
43  }
+
44 
+
46  socket_type& socket() { return socket_; }
+
48  const socket_type& socket() const { return socket_; }
+
49 
+
51  executor_type get_executor() { return socket().get_executor(); }
+
52 
+
54  void set_buffer_reserve_size(std::size_t size) noexcept
+
55  {
+
56  buffer_reserve_size_ = size;
+
57  }
+
59  std::size_t get_buffer_reserve_size() const noexcept
+
60  {
+
61  return buffer_reserve_size_;
+
62  }
+
63 
+
65  void start() { this->async_read(parser_type{}); }
+
66 
+
67 private:
+
68  using parser_type = typename Rpc::incremental_parser_type;
+
69  using request_type = typename Rpc::request_type;
+
70 
+
71  void async_read(parser_type&& parser)
+
72  {
+
73  // abort R/W on error
+
74  if (!socket_.is_open()) {
+
75  return;
+
76  }
+
77 
+
78  parser.reserve_buffer(buffer_reserve_size_);
+
79  auto buffer = net::buffer(parser.buffer(), parser.buffer_capacity());
+
80  socket_.async_read_some(
+
81  buffer,
+
82  [self = shared_from_this(), parser = std::move(parser)](
+
83  error_code ec, size_t length) mutable {
+
84  if (ec) {
+
85  PACKIO_WARN("read error: {}", ec.message());
+
86  self->close_connection();
+
87  return;
+
88  }
+
89 
+
90  PACKIO_TRACE("read: {}", length);
+
91  parser.buffer_consumed(length);
+
92 
+
93  while (auto request = parser.get_request()) {
+
94  if (!request) {
+
95  self->close_connection();
+
96  continue;
+
97  }
+
98  // handle the call asynchronously (post)
+
99  // to schedule the next read immediately
+
100  // this will allow parallel call handling
+
101  // in multi-threaded environments
+
102  net::post(
+
103  self->get_executor(),
+
104  [self, request = std::move(*request)]() mutable {
+
105  self->async_handle_request(std::move(request));
+
106  });
+
107  }
+
108 
+
109  self->async_read(std::move(parser));
+
110  });
+
111  }
+
112 
+
113  void async_handle_request(request_type&& request)
+
114  {
+
115  completion_handler<Rpc> handler(
+
116  request.id,
+
117  [type = request.type, id = request.id, self = shared_from_this()](
+
118  auto&& response_buffer) {
+
119  if (type == call_type::request) {
+
120  PACKIO_TRACE("result (id={})", Rpc::format_id(id));
+
121  (void)id;
+
122  self->async_send_response(std::move(response_buffer));
+
123  }
+
124  });
125 
-
126  auto completion_handler =
-
127  [type = call->type, id = call->id, self = shared_from_this()](
-
128  error_code ec, msgpack::object_handle result) {
-
129  if (type == msgpack_rpc_type::request) {
-
130  PACKIO_TRACE("result: {}", ec.message());
-
131  self->async_send_result(id, ec, std::move(result));
-
132  }
-
133  };
-
134 
-
135  const auto function = dispatcher_ptr_->get(call->name);
-
136  if (function) {
-
137  PACKIO_TRACE("call: {} (id={})", call->name, call->id);
-
138  (*function)(completion_handler, call->args);
-
139  }
-
140  else {
-
141  PACKIO_DEBUG("unknown function {}", call->name);
-
142  completion_handler(make_error_code(error::unknown_procedure), {});
-
143  }
-
144  }
+
126  const auto function = dispatcher_ptr_->get(request.method);
+
127  if (function) {
+
128  PACKIO_TRACE(
+
129  "call: {} (id={})", request.method, Rpc::format_id(request.id));
+
130  (*function)(std::move(handler), std::move(request.args));
+
131  }
+
132  else {
+
133  PACKIO_DEBUG("unknown function {}", request.method);
+
134  handler.set_error("Unknown function");
+
135  }
+
136  }
+
137 
+
138  template <typename Buffer>
+
139  void async_send_response(Buffer&& response_buffer)
+
140  {
+
141  // abort R/W on error
+
142  if (!socket_.is_open()) {
+
143  return;
+
144  }
145 
-
146  std::optional<Call> parse_call(const msgpack::object& call)
-
147  {
-
148  if (call.type != msgpack::type::ARRAY || call.via.array.size < 3) {
-
149  PACKIO_ERROR("unexpected message type: {}", call.type);
-
150  return std::nullopt;
-
151  }
-
152 
-
153  try {
-
154  int idx = 0;
-
155  id_type id = 0;
-
156  msgpack_rpc_type type = static_cast<msgpack_rpc_type>(
-
157  call.via.array.ptr[idx++].as<int>());
+
146  auto message_ptr = internal::to_unique_ptr(std::move(response_buffer));
+
147 
+
148  wstrand_.push([this,
+
149  self = shared_from_this(),
+
150  message_ptr = std::move(message_ptr)]() mutable {
+
151  auto buf = Rpc::buffer(*message_ptr);
+
152  net::async_write(
+
153  socket_,
+
154  buf,
+
155  [self = std::move(self), message_ptr = std::move(message_ptr)](
+
156  error_code ec, size_t length) {
+
157  self->wstrand_.next();
158 
-
159  std::size_t expected_size;
-
160  switch (type) {
-
161  case msgpack_rpc_type::request:
-
162  id = call.via.array.ptr[idx++].as<id_type>();
-
163  expected_size = 4;
-
164  break;
-
165  case msgpack_rpc_type::notification:
-
166  expected_size = 3;
-
167  break;
-
168  default:
-
169  PACKIO_ERROR("unexpected type: {}", type);
-
170  return std::nullopt;
-
171  }
-
172 
-
173  if (call.via.array.size != expected_size) {
-
174  PACKIO_ERROR("unexpected message size: {}", call.via.array.size);
-
175  return std::nullopt;
-
176  }
-
177 
-
178  std::string name = call.via.array.ptr[idx++].as<std::string>();
-
179  const msgpack::object& args = call.via.array.ptr[idx++];
-
180 
-
181  return Call{type, id, name, args};
-
182  }
-
183  catch (msgpack::type_error& exc) {
-
184  PACKIO_ERROR("unexpected message content: {}", exc.what());
-
185  (void)exc;
-
186  return std::nullopt;
-
187  }
-
188  }
-
189 
-
190  void async_send_result(id_type id, error_code ec, msgpack::object_handle result_handle)
-
191  {
-
192  // abort R/W on error
-
193  if (!socket_.is_open()) {
-
194  return;
-
195  }
-
196 
-
197  auto message_ptr = std::make_unique<message_type>();
-
198  msgpack::packer<buffer_type> packer(std::get<buffer_type>(*message_ptr));
-
199 
-
200  // serialize the result into the buffer
-
201  const auto pack = [&](auto&& error, auto&& result) {
-
202  packer.pack(std::forward_as_tuple(
-
203  static_cast<int>(msgpack_rpc_type::response),
-
204  id,
-
205  std::forward<decltype(error)>(error),
-
206  std::forward<decltype(result)>(result)));
-
207  };
-
208 
-
209  if (ec) {
-
210  if (result_handle.get().is_nil()) {
-
211  pack(ec.message(), msgpack::type::nil_t{});
-
212  }
-
213  else {
-
214  pack(result_handle.get(), msgpack::type::nil_t{});
-
215  }
-
216  }
-
217  else {
-
218  pack(msgpack::type::nil_t{}, result_handle.get());
-
219  }
-
220 
-
221  // move the result handle to the message pointer
-
222  // as the buffer is non-owning, we need to keep the result handle
-
223  // with the buffer
-
224  std::get<msgpack::object_handle>(*message_ptr) = std::move(result_handle);
-
225  async_send_message(std::move(message_ptr));
-
226  }
-
227 
-
228  void async_send_message(std::unique_ptr<message_type> message_ptr)
-
229  {
-
230  wstrand_.push([this,
-
231  self = shared_from_this(),
-
232  message_ptr = std::move(message_ptr)]() mutable {
-
233  using internal::buffer;
-
234 
-
235  auto buf = buffer(std::get<buffer_type>(*message_ptr));
-
236  net::async_write(
-
237  socket_,
-
238  buf,
-
239  [self = std::move(self), message_ptr = std::move(message_ptr)](
-
240  error_code ec, size_t length) {
-
241  self->wstrand_.next();
-
242 
-
243  if (ec) {
-
244  PACKIO_WARN("write error: {}", ec.message());
-
245  self->close_connection();
-
246  return;
-
247  }
-
248 
-
249  PACKIO_TRACE("write: {}", length);
-
250  (void)length;
-
251  });
-
252  });
-
253  };
-
254 
-
255  void close_connection()
-
256  {
-
257  error_code ec;
-
258  socket_.close(ec);
-
259  if (ec) {
-
260  PACKIO_WARN("close error: {}", ec.message());
-
261  }
-
262  }
-
263 
-
264  socket_type socket_;
-
265  std::size_t buffer_reserve_size_{kDefaultBufferReserveSize};
-
266  std::shared_ptr<Dispatcher> dispatcher_ptr_;
-
267  internal::manual_strand<typename socket_type::executor_type> wstrand_;
-
268 };
-
269 
-
270 } // packio
-
271 
-
272 #endif // PACKIO_SERVER_SESSION_H
+
159  if (ec) {
+
160  PACKIO_WARN("write error: {}", ec.message());
+
161  self->close_connection();
+
162  return;
+
163  }
+
164 
+
165  PACKIO_TRACE("write: {}", length);
+
166  (void)length;
+
167  });
+
168  });
+
169  }
+
170 
+
171  void close_connection()
+
172  {
+
173  error_code ec;
+
174  socket_.close(ec);
+
175  if (ec) {
+
176  PACKIO_WARN("close error: {}", ec.message());
+
177  }
+
178  }
+
179 
+
180  socket_type socket_;
+
181  std::size_t buffer_reserve_size_{kDefaultBufferReserveSize};
+
182  std::shared_ptr<Dispatcher> dispatcher_ptr_;
+
183  internal::manual_strand<typename socket_type::executor_type> wstrand_;
+
184 };
+
185 
+
186 } // packio
+
187 
+
188 #endif // PACKIO_SERVER_SESSION_H
-
static constexpr size_t kDefaultBufferReserveSize
The default size reserved by the reception buffer.
Definition: server_session.h:37
-
std::size_t get_buffer_reserve_size() const noexcept
Get the size reserved by the reception buffer.
Definition: server_session.h:60
-
void start()
Start the session.
Definition: server_session.h:66
-
executor_type get_executor()
Get the executor associated with the object.
Definition: server_session.h:52
- -
const socket_type & socket() const
Get the underlying socket, const.
Definition: server_session.h:49
-
uint32_t id_type
Type used to store call IDs.
Definition: msgpack_rpc.h:16
-
Socket socket_type
The socket type.
Definition: server_session.h:29
- -
The server_session class, created by the server.
Definition: server_session.h:26
-
typename socket_type::executor_type executor_type
The executor type.
Definition: server_session.h:33
-
Definition: as.h:16
-
@ unknown_procedure
The procedure name is unknown, server-side error.
-
typename socket_type::protocol_type protocol_type
The protocol type.
Definition: server_session.h:31
-
void set_buffer_reserve_size(std::size_t size) noexcept
Set the size reserved by the reception buffer.
Definition: server_session.h:55
-
error
The error codes enumeration.
Definition: error_code.h:28
-
socket_type & socket()
Get the underlying socket.
Definition: server_session.h:47
+ +
executor_type get_executor()
Get the executor associated with the object.
Definition: server_session.h:51
+
Socket socket_type
The socket type.
Definition: server_session.h:28
+
typename socket_type::protocol_type protocol_type
The protocol type.
Definition: server_session.h:30
+
static constexpr size_t kDefaultBufferReserveSize
The default size reserved by the reception buffer.
Definition: server_session.h:36
+
void set_buffer_reserve_size(std::size_t size) noexcept
Set the size reserved by the reception buffer.
Definition: server_session.h:54
+
void start()
Start the session.
Definition: server_session.h:65
+
The server_session class, created by the server.
Definition: server_session.h:25
+
Definition: arg.h:14
+
const socket_type & socket() const
Get the underlying socket, const.
Definition: server_session.h:48
+
socket_type & socket()
Get the underlying socket.
Definition: server_session.h:46
+
typename socket_type::executor_type executor_type
The executor type.
Definition: server_session.h:32
+
std::size_t get_buffer_reserve_size() const noexcept
Get the size reserved by the reception buffer.
Definition: server_session.h:59
diff --git a/docs/structpackio_1_1msgpack_1_1rpc_1_1request-members.html b/docs/structpackio_1_1msgpack_1_1rpc_1_1request-members.html new file mode 100644 index 0000000..074bb09 --- /dev/null +++ b/docs/structpackio_1_1msgpack_1_1rpc_1_1request-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+
+ + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack::rpc::request Member List
+
+
+ +

This is the complete list of members for packio::msgpack::rpc::request, including all inherited members.

+ + +
zonepackio::msgpack::rpc::request
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack_1_1rpc_1_1request.html b/docs/structpackio_1_1msgpack_1_1rpc_1_1request.html new file mode 100644 index 0000000..31e73b9 --- /dev/null +++ b/docs/structpackio_1_1msgpack_1_1rpc_1_1request.html @@ -0,0 +1,99 @@ + + + + + + + + + packio: packio::msgpack::rpc::request Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack::rpc::request Struct Reference
+
+
+ +

The object representing a client request. + More...

+ +

#include <packio/msgpack/rpc.h>

+ + + + + +

+Public Attributes

+std::unique_ptr<::msgpack::zone > zone
 Msgpack zone storing the args.
 
+

Detailed Description

+

The object representing a client request.

+

The documentation for this struct was generated from the following file: +
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack_1_1rpc_1_1response-members.html b/docs/structpackio_1_1msgpack_1_1rpc_1_1response-members.html new file mode 100644 index 0000000..839d095 --- /dev/null +++ b/docs/structpackio_1_1msgpack_1_1rpc_1_1response-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack::rpc::response Member List
+
+
+ +

This is the complete list of members for packio::msgpack::rpc::response, including all inherited members.

+ + +
zonepackio::msgpack::rpc::response
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack_1_1rpc_1_1response.html b/docs/structpackio_1_1msgpack_1_1rpc_1_1response.html new file mode 100644 index 0000000..158517d --- /dev/null +++ b/docs/structpackio_1_1msgpack_1_1rpc_1_1response.html @@ -0,0 +1,99 @@ + + + + + + + + + packio: packio::msgpack::rpc::response Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack::rpc::response Struct Reference
+
+
+ +

The object representing the response to a call. + More...

+ +

#include <packio/msgpack/rpc.h>

+ + + + + +

+Public Attributes

+std::unique_ptr<::msgpack::zone > zone
 Msgpack zone storing error and result.
 
+

Detailed Description

+

The object representing the response to a call.

+

The documentation for this struct was generated from the following file: +
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1request-members.html b/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1request-members.html new file mode 100644 index 0000000..e8e1903 --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1request-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack_rpc::internal::request Member List
+
+
+ +

This is the complete list of members for packio::msgpack_rpc::internal::request, including all inherited members.

+ + +
zonepackio::msgpack_rpc::internal::request
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1request.html b/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1request.html new file mode 100644 index 0000000..0ece0b3 --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1request.html @@ -0,0 +1,99 @@ + + + + + + + + + packio: packio::msgpack_rpc::internal::request Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc::internal::request Struct Reference
+
+
+ +

The object representing a client request. + More...

+ +

#include <packio/msgpack_rpc/rpc.h>

+ + + + + +

+Public Attributes

+std::unique_ptr<::msgpack::zone > zone
 Msgpack zone storing the args.
 
+

Detailed Description

+

The object representing a client request.

+

The documentation for this struct was generated from the following file:
    +
  • packio/msgpack_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1response-members.html b/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1response-members.html new file mode 100644 index 0000000..44ff5ab --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1response-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack_rpc::internal::response Member List
+
+
+ +

This is the complete list of members for packio::msgpack_rpc::internal::response, including all inherited members.

+ + +
zonepackio::msgpack_rpc::internal::response
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1response.html b/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1response.html new file mode 100644 index 0000000..4fe31bc --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1internal_1_1response.html @@ -0,0 +1,99 @@ + + + + + + + + + packio: packio::msgpack_rpc::internal::response Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc::internal::response Struct Reference
+
+
+ +

The object representing the response to a call. + More...

+ +

#include <packio/msgpack_rpc/rpc.h>

+ + + + + +

+Public Attributes

+std::unique_ptr<::msgpack::zone > zone
 Msgpack zone storing error and result.
 
+

Detailed Description

+

The object representing the response to a call.

+

The documentation for this struct was generated from the following file:
    +
  • packio/msgpack_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1request-members.html b/docs/structpackio_1_1msgpack__rpc_1_1request-members.html new file mode 100644 index 0000000..350cd0d --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1request-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack_rpc::request Member List
+
+
+ +

This is the complete list of members for packio::msgpack_rpc::request, including all inherited members.

+ + +
zonepackio::msgpack_rpc::request
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1request.html b/docs/structpackio_1_1msgpack__rpc_1_1request.html new file mode 100644 index 0000000..cb9bca8 --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1request.html @@ -0,0 +1,99 @@ + + + + + + + + + packio: packio::msgpack_rpc::request Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc::request Struct Reference
+
+
+ +

The object representing a client request. + More...

+ +

#include <packio/msgpack_rpc/rpc.h>

+ + + + + +

+Public Attributes

+std::unique_ptr<::msgpack::zone > zone
 Msgpack zone storing the args.
 
+

Detailed Description

+

The object representing a client request.

+

The documentation for this struct was generated from the following file:
    +
  • packio/msgpack_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1response-members.html b/docs/structpackio_1_1msgpack__rpc_1_1response-members.html new file mode 100644 index 0000000..82f1332 --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1response-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack_rpc::response Member List
+
+
+ +

This is the complete list of members for packio::msgpack_rpc::response, including all inherited members.

+ + +
zonepackio::msgpack_rpc::response
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1response.html b/docs/structpackio_1_1msgpack__rpc_1_1response.html new file mode 100644 index 0000000..15a399c --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1response.html @@ -0,0 +1,99 @@ + + + + + + + + + packio: packio::msgpack_rpc::response Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc::response Struct Reference
+
+
+ +

The object representing the response to a call. + More...

+ +

#include <packio/msgpack_rpc/rpc.h>

+ + + + + +

+Public Attributes

+std::unique_ptr<::msgpack::zone > zone
 Msgpack zone storing error and result.
 
+

Detailed Description

+

The object representing the response to a call.

+

The documentation for this struct was generated from the following file:
    +
  • packio/msgpack_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1request-members.html b/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1request-members.html new file mode 100644 index 0000000..7d38959 --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1request-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack_rpc::rpc::request Member List
+
+
+ +

This is the complete list of members for packio::msgpack_rpc::rpc::request, including all inherited members.

+ + +
zonepackio::msgpack_rpc::rpc::request
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1request.html b/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1request.html new file mode 100644 index 0000000..e460b4c --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1request.html @@ -0,0 +1,99 @@ + + + + + + + + + packio: packio::msgpack_rpc::rpc::request Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc::rpc::request Struct Reference
+
+
+ +

The object representing a client request. + More...

+ +

#include <packio/msgpack_rpc/rpc.h>

+ + + + + +

+Public Attributes

+std::unique_ptr<::msgpack::zone > zone
 Msgpack zone storing the args.
 
+

Detailed Description

+

The object representing a client request.

+

The documentation for this struct was generated from the following file:
    +
  • packio/msgpack_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1response-members.html b/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1response-members.html new file mode 100644 index 0000000..98ca0dd --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1response-members.html @@ -0,0 +1,82 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::msgpack_rpc::rpc::response Member List
+
+
+ +

This is the complete list of members for packio::msgpack_rpc::rpc::response, including all inherited members.

+ + +
zonepackio::msgpack_rpc::rpc::response
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1response.html b/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1response.html new file mode 100644 index 0000000..82dee0c --- /dev/null +++ b/docs/structpackio_1_1msgpack__rpc_1_1rpc_1_1response.html @@ -0,0 +1,99 @@ + + + + + + + + + packio: packio::msgpack_rpc::rpc::response Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::msgpack_rpc::rpc::response Struct Reference
+
+
+ +

The object representing the response to a call. + More...

+ +

#include <packio/msgpack_rpc/rpc.h>

+ + + + + +

+Public Attributes

+std::unique_ptr<::msgpack::zone > zone
 Msgpack zone storing error and result.
 
+

Detailed Description

+

The object representing the response to a call.

+

The documentation for this struct was generated from the following file:
    +
  • packio/msgpack_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1request-members.html b/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1request-members.html new file mode 100644 index 0000000..663bb3b --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1request-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nl_json_rpc::internal::request Member List
+
+
+ +

This is the complete list of members for packio::nl_json_rpc::internal::request, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1request.html b/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1request.html new file mode 100644 index 0000000..190ff56 --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1request.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nl_json_rpc::internal::request Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc::internal::request Struct Reference
+
+
+ +

The object representing a client request. + More...

+ +

#include <packio/nl_json_rpc/rpc.h>

+

Detailed Description

+

The object representing a client request.

+

The documentation for this struct was generated from the following file:
    +
  • packio/nl_json_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1response-members.html b/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1response-members.html new file mode 100644 index 0000000..10d2757 --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1response-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nl_json_rpc::internal::response Member List
+
+
+ +

This is the complete list of members for packio::nl_json_rpc::internal::response, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1response.html b/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1response.html new file mode 100644 index 0000000..f049997 --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1internal_1_1response.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nl_json_rpc::internal::response Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc::internal::response Struct Reference
+
+
+ +

The object representing the response to a call. + More...

+ +

#include <packio/nl_json_rpc/rpc.h>

+

Detailed Description

+

The object representing the response to a call.

+

The documentation for this struct was generated from the following file:
    +
  • packio/nl_json_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1request-members.html b/docs/structpackio_1_1nl__json__rpc_1_1request-members.html new file mode 100644 index 0000000..74f587e --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1request-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nl_json_rpc::request Member List
+
+
+ +

This is the complete list of members for packio::nl_json_rpc::request, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1request.html b/docs/structpackio_1_1nl__json__rpc_1_1request.html new file mode 100644 index 0000000..757f337 --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1request.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nl_json_rpc::request Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc::request Struct Reference
+
+
+ +

The object representing a client request. + More...

+ +

#include <packio/nl_json_rpc/rpc.h>

+

Detailed Description

+

The object representing a client request.

+

The documentation for this struct was generated from the following file:
    +
  • packio/nl_json_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1response-members.html b/docs/structpackio_1_1nl__json__rpc_1_1response-members.html new file mode 100644 index 0000000..f689732 --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1response-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nl_json_rpc::response Member List
+
+
+ +

This is the complete list of members for packio::nl_json_rpc::response, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1response.html b/docs/structpackio_1_1nl__json__rpc_1_1response.html new file mode 100644 index 0000000..0848723 --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1response.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nl_json_rpc::response Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc::response Struct Reference
+
+
+ +

The object representing the response to a call. + More...

+ +

#include <packio/nl_json_rpc/rpc.h>

+

Detailed Description

+

The object representing the response to a call.

+

The documentation for this struct was generated from the following file:
    +
  • packio/nl_json_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1request-members.html b/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1request-members.html new file mode 100644 index 0000000..9e3952b --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1request-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nl_json_rpc::rpc::request Member List
+
+
+ +

This is the complete list of members for packio::nl_json_rpc::rpc::request, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1request.html b/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1request.html new file mode 100644 index 0000000..a271cee --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1request.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nl_json_rpc::rpc::request Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc::rpc::request Struct Reference
+
+
+ +

The object representing a client request. + More...

+ +

#include <packio/nl_json_rpc/rpc.h>

+

Detailed Description

+

The object representing a client request.

+

The documentation for this struct was generated from the following file:
    +
  • packio/nl_json_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1response-members.html b/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1response-members.html new file mode 100644 index 0000000..33810a0 --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1response-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nl_json_rpc::rpc::response Member List
+
+
+ +

This is the complete list of members for packio::nl_json_rpc::rpc::response, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1response.html b/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1response.html new file mode 100644 index 0000000..787df7b --- /dev/null +++ b/docs/structpackio_1_1nl__json__rpc_1_1rpc_1_1response.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nl_json_rpc::rpc::response Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nl_json_rpc::rpc::response Struct Reference
+
+
+ +

The object representing the response to a call. + More...

+ +

#include <packio/nl_json_rpc/rpc.h>

+

Detailed Description

+

The object representing the response to a call.

+

The documentation for this struct was generated from the following file:
    +
  • packio/nl_json_rpc/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1request-members.html b/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1request-members.html new file mode 100644 index 0000000..84ff27a --- /dev/null +++ b/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1request-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nlohmann_json::rpc::request Member List
+
+
+ +

This is the complete list of members for packio::nlohmann_json::rpc::request, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1request.html b/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1request.html new file mode 100644 index 0000000..d41967f --- /dev/null +++ b/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1request.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nlohmann_json::rpc::request Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nlohmann_json::rpc::request Struct Reference
+
+
+ +

The object representing a client request. + More...

+ +

#include <packio/nlohmann_json/rpc.h>

+

Detailed Description

+

The object representing a client request.

+

The documentation for this struct was generated from the following file:
    +
  • packio/nlohmann_json/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1response-members.html b/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1response-members.html new file mode 100644 index 0000000..d95f354 --- /dev/null +++ b/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1response-members.html @@ -0,0 +1,80 @@ + + + + + + + + + packio: Member List + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
packio::nlohmann_json::rpc::response Member List
+
+
+ +

This is the complete list of members for packio::nlohmann_json::rpc::response, including all inherited members.

+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1response.html b/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1response.html new file mode 100644 index 0000000..b57f91b --- /dev/null +++ b/docs/structpackio_1_1nlohmann__json_1_1rpc_1_1response.html @@ -0,0 +1,90 @@ + + + + + + + + + packio: packio::nlohmann_json::rpc::response Struct Reference + + + + + + + + + +
+ +
+ + + + + + +
+
packio +
+
+
+ + + + + + + +
+
+ + +
+ +
+ + +
+
+ +
+
packio::nlohmann_json::rpc::response Struct Reference
+
+
+ +

The object representing the response to a call. + More...

+ +

#include <packio/nlohmann_json/rpc.h>

+

Detailed Description

+

The object representing the response to a call.

+

The documentation for this struct was generated from the following file:
    +
  • packio/nlohmann_json/rpc.h
  • +
+
+ + + + \ No newline at end of file diff --git a/docs/structpackio_1_1traits_1_1AsyncProcedure.html b/docs/structpackio_1_1traits_1_1AsyncProcedure.html index 2ac9bc5..374e6c8 100644 --- a/docs/structpackio_1_1traits_1_1AsyncProcedure.html +++ b/docs/structpackio_1_1traits_1_1AsyncProcedure.html @@ -7,7 +7,7 @@ - packio: packio::traits::AsyncProcedure< T > Struct Template Reference + packio: packio::traits::AsyncProcedure< T, Rpc > Struct Template Reference @@ -68,7 +68,7 @@
-
packio::traits::AsyncProcedure< T > Struct Template Reference
+
packio::traits::AsyncProcedure< T, Rpc > Struct Template Reference
@@ -77,14 +77,14 @@

#include <packio/traits.h>

Detailed Description

-

template<typename T>
-struct packio::traits::AsyncProcedure< T >

+

template<typename T, typename Rpc>
+struct packio::traits::AsyncProcedure< T, Rpc >

AsyncProcedure trait.

-

Procedure registered with dispatcher::add_async

    +

    Procedure registered with dispatcher::add_async

    • Must be callable with completion_handler as first argument.
    • No overload resolution can be performed.
    • -
    • The other arguments must be msgpack-able and will be used as the procedure's arguments.
    • +
    • The other arguments must be serializable and will be used as the procedure's arguments.

The documentation for this struct was generated from the following file:
  • packio/traits.h
  • diff --git a/docs/structpackio_1_1traits_1_1CallHandler.html b/docs/structpackio_1_1traits_1_1CallHandler.html index 784ff6d..883e781 100644 --- a/docs/structpackio_1_1traits_1_1CallHandler.html +++ b/docs/structpackio_1_1traits_1_1CallHandler.html @@ -7,7 +7,7 @@ - packio: packio::traits::CallHandler< T > Struct Template Reference + packio: packio::traits::CallHandler< T, Rpc > Struct Template Reference @@ -68,7 +68,7 @@
-
packio::traits::CallHandler< T > Struct Template Reference
+
packio::traits::CallHandler< T, Rpc > Struct Template Reference
@@ -77,12 +77,12 @@

#include <packio/traits.h>

Detailed Description

-

template<typename T>
-struct packio::traits::CallHandler< T >

+

template<typename T, typename Rpc>
+struct packio::traits::CallHandler< T, Rpc >

CallHandler trait.

-

Handler used by client::async_call

    -
  • Must be callable with error_code, msgpack::object_handle
  • +

    Handler used by client::async_call

      +
    • Must be callable with error_code, response_type

The documentation for this struct was generated from the following file:
  • packio/traits.h
  • diff --git a/docs/structpackio_1_1traits_1_1CoroProcedure.html b/docs/structpackio_1_1traits_1_1CoroProcedure.html index ef0ddf9..1fe530a 100644 --- a/docs/structpackio_1_1traits_1_1CoroProcedure.html +++ b/docs/structpackio_1_1traits_1_1CoroProcedure.html @@ -81,10 +81,10 @@ struct packio::traits::CoroProcedure< T >

    CoroProcedure trait.

    -

    Procedure registered with dispatcher::add_coro

      +

      Procedure registered with dispatcher::add_coro

      • Must be coroutine.
      • No overload resolution can be performed.
      • -
      • The arguments must be msgpack-able and will be used as the procedure's arguments.
      • +
      • The arguments must be serializable and will be used as the procedure's arguments.

The documentation for this struct was generated from the following file:
  • packio/traits.h
  • diff --git a/docs/structpackio_1_1traits_1_1NotifyHandler.html b/docs/structpackio_1_1traits_1_1NotifyHandler.html index 51af1ca..0ecd9b7 100644 --- a/docs/structpackio_1_1traits_1_1NotifyHandler.html +++ b/docs/structpackio_1_1traits_1_1NotifyHandler.html @@ -81,7 +81,7 @@ struct packio::traits::NotifyHandler< T >

    NotifyHandler trait.

    -

    Handler used by client::async_notify


The documentation for this struct was generated from the following file:
    diff --git a/docs/structpackio_1_1traits_1_1ServeHandler.html b/docs/structpackio_1_1traits_1_1ServeHandler.html index cd83a40..5bf18e3 100644 --- a/docs/structpackio_1_1traits_1_1ServeHandler.html +++ b/docs/structpackio_1_1traits_1_1ServeHandler.html @@ -81,8 +81,8 @@ struct packio::traits::ServeHandler< T, Session >

    ServeHandler trait.

    -

    Handler used by server::async_serve

      -
    • Must be callable with error_code, std::shared_ptr<session_type>
    • +

      Handler used by server::async_serve


      The documentation for this struct was generated from the following file:
      • packio/traits.h
      • diff --git a/docs/structpackio_1_1traits_1_1SyncProcedure.html b/docs/structpackio_1_1traits_1_1SyncProcedure.html index d72b3d1..9cf72c4 100644 --- a/docs/structpackio_1_1traits_1_1SyncProcedure.html +++ b/docs/structpackio_1_1traits_1_1SyncProcedure.html @@ -81,10 +81,10 @@ struct packio::traits::SyncProcedure< T >

        SyncProcedure trait.

        -

        Procedure registered with dispatcher::add

          +

          Procedure registered with dispatcher::add

          • Must be callable.
          • No overload resolution can be performed.
          • -
          • The arguments must be msgpack-able and will be used as the procedure's arguments.
          • +
          • The arguments must be serializable and will be used as the procedure's arguments.

          The documentation for this struct was generated from the following file:
          • packio/traits.h
          • diff --git a/docs/traits_8h.html b/docs/traits_8h.html index a8634f4..66cc006 100644 --- a/docs/traits_8h.html +++ b/docs/traits_8h.html @@ -76,30 +76,27 @@
            #include <type_traits>
            #include <utility>
            -#include <msgpack.hpp>
            #include "internal/config.h"
            +#include "internal/rpc.h"
            #include "internal/utils.h"

            Go to the source code of this file.

            + + + - + - - - - - - - + diff --git a/docs/traits_8h_source.html b/docs/traits_8h_source.html index 872ee0c..290dd5b 100644 --- a/docs/traits_8h_source.html +++ b/docs/traits_8h_source.html @@ -82,109 +82,101 @@
            11 #include <type_traits>
            12 #include <utility>
            13 
            -
            14 #include <msgpack.hpp>
            -
            15 
            -
            16 #include "internal/config.h"
            -
            17 #include "internal/utils.h"
            -
            18 
            -
            19 #if defined(PACKIO_TRAITS_CHECK_DISABLE)
            -
            20 #define PACKIO_STATIC_ASSERT_TRAIT(Trait) (void)0
            -
            21 #define PACKIO_STATIC_ASSERT_TTRAIT(Trait, ...) (void)0
            -
            22 #else
            -
            23 #define PACKIO_STATIC_ASSERT_TRAIT(Trait) \
            -
            24  static_assert( \
            -
            25  ::packio::traits::Trait<Trait>::value, "Trait " #Trait " not satisfied")
            -
            26 #define PACKIO_STATIC_ASSERT_TTRAIT(Trait, ...) \
            -
            27  static_assert( \
            -
            28  ::packio::traits::Trait<Trait, __VA_ARGS__>::value, \
            -
            29  "Trait " #Trait " not satisfied")
            -
            30 #endif
            -
            31 
            -
            32 namespace packio {
            -
            33 
            -
            34 class completion_handler;
            +
            14 #include "internal/config.h"
            +
            15 #include "internal/rpc.h"
            +
            16 #include "internal/utils.h"
            +
            17 
            +
            18 #if defined(PACKIO_TRAITS_CHECK_DISABLE)
            +
            19 #define PACKIO_STATIC_ASSERT_TRAIT(Trait) (void)0
            +
            20 #define PACKIO_STATIC_ASSERT_TTRAIT(Trait, ...) (void)0
            +
            21 #else
            +
            22 #define PACKIO_STATIC_ASSERT_TRAIT(Trait) \
            +
            23  static_assert( \
            +
            24  ::packio::traits::Trait<Trait>::value, "Trait " #Trait " not satisfied")
            +
            25 #define PACKIO_STATIC_ASSERT_TTRAIT(Trait, ...) \
            +
            26  static_assert( \
            +
            27  ::packio::traits::Trait<Trait, __VA_ARGS__>::value, \
            +
            28  "Trait " #Trait " not satisfied")
            +
            29 #endif
            +
            30 
            +
            31 namespace packio {
            +
            32 
            +
            33 template <typename Rpc>
            +
            34 class completion_handler;
            35 
            36 namespace traits {
            37 namespace details {
            38 
            -
            39 template <typename, typename = void>
            +
            39 template <typename, typename, typename = void>
            40 struct AsyncProcedureImpl : std::false_type {
            41 };
            42 
            -
            43 template <typename T>
            -
            44 struct AsyncProcedureImpl<T, std::enable_if_t<internal::func_traits_v<T>>> {
            +
            43 template <typename T, typename Rpc>
            +
            44 struct AsyncProcedureImpl<T, Rpc, std::enable_if_t<internal::func_traits_v<T>>> {
            45  using TArgs = typename internal::func_traits<T>::args_type;
            46  static constexpr bool value = [] {
            47  if constexpr (std::tuple_size_v<TArgs> == 0) {
            48  return false;
            49  }
            50  else {
            -
            51  return std::is_same_v<std::decay_t<std::tuple_element_t<0, TArgs>>, completion_handler>;
            -
            52  }
            -
            53  }();
            -
            54 };
            -
            55 
            -
            56 template <typename T>
            -
            57 constexpr bool is_async_procedure_v = AsyncProcedureImpl<T>::value;
            -
            58 
            -
            59 } // details
            +
            51  return std::is_same_v<
            +
            52  std::decay_t<std::tuple_element_t<0, TArgs>>,
            +
            53  completion_handler<Rpc>>;
            +
            54  }
            +
            55  }();
            +
            56 };
            +
            57 
            +
            58 template <typename T, typename Rpc>
            +
            59 constexpr bool is_async_procedure_v = AsyncProcedureImpl<T, Rpc>::value;
            60 
            -
            61 template <bool condition>
            -
            62 struct Trait : std::integral_constant<bool, condition> {
            -
            63 };
            -
            64 
            -
            69 template <typename T>
            -
            70 struct NotifyHandler : Trait<std::is_invocable_v<T, error_code>> {
            -
            71 };
            -
            72 
            -
            77 template <typename T>
            - -
            79  : Trait<std::is_invocable_v<T, error_code, msgpack::object_handle>> {
            -
            80 };
            -
            81 
            -
            86 template <typename T, typename Result>
            - -
            88  : Trait<std::is_invocable_v<T, error_code, std::optional<Result>>> {
            -
            89 };
            -
            90 
            -
            95 template <typename T>
            -
            96 struct AsVoidCallHandler : Trait<std::is_invocable_v<T, error_code>> {
            -
            97 };
            -
            98 
            -
            104 template <typename T, typename Session>
            - -
            106  : Trait<std::is_invocable_v<T, error_code, std::shared_ptr<Session>>> {
            -
            107 };
            -
            108 
            +
            61 } // details
            +
            62 
            +
            63 template <bool condition>
            +
            64 struct Trait : std::integral_constant<bool, condition> {
            +
            65 };
            +
            66 
            +
            71 template <typename T>
            +
            72 struct NotifyHandler : Trait<std::is_invocable_v<T, error_code>> {
            +
            73 };
            +
            74 
            +
            79 template <typename T, typename Rpc>
            + +
            81  : Trait<std::is_invocable_v<T, error_code, typename Rpc::response_type>> {
            +
            82 };
            +
            83 
            +
            89 template <typename T, typename Session>
            + +
            91  : Trait<std::is_invocable_v<T, error_code, std::shared_ptr<Session>>> {
            +
            92 };
            +
            93 
            +
            100 template <typename T, typename Rpc>
            +
            101 struct AsyncProcedure : Trait<details::is_async_procedure_v<T, Rpc>> {
            +
            102 };
            +
            103 
            +
            110 template <typename T>
            +
            111 struct SyncProcedure : Trait<internal::func_traits_v<T>> {
            +
            112 };
            +
            113 
            +
            114 #if defined(PACKIO_HAS_CO_AWAIT)
            115 template <typename T>
            -
            116 struct AsyncProcedure : Trait<details::is_async_procedure_v<T>> {
            -
            117 };
            -
            118 
            -
            125 template <typename T>
            -
            126 struct SyncProcedure : Trait<internal::func_traits_v<T>> {
            -
            127 };
            -
            128 
            -
            129 #if defined(PACKIO_HAS_CO_AWAIT) || defined(PACKIO_DOCUMENTATION)
            -
            130 template <typename T>
            - -
            138  : Trait<internal::is_coroutine_v<T> && internal::func_traits_v<T>> {
            -
            139 };
            -
            140 #endif // defined(PACKIO_HAS_CO_AWAIT) || defined(PACKIO_DOCUMENTATION)
            -
            141 
            -
            142 } // traits
            -
            143 } // packio
            -
            144 
            -
            145 #endif // PACKIO_TRAITS_H
            + +
            123  : Trait<internal::is_coroutine_v<T> && internal::func_traits_v<T>> {
            +
            124 };
            +
            125 #endif // defined(PACKIO_HAS_CO_AWAIT)
            +
            126 
            +
            127 } // traits
            +
            128 } // packio
            +
            129 
            +
            130 #endif // PACKIO_TRAITS_H
            -
            AsCallHandler.
            Definition: traits.h:87
            -
            ServeHandler trait.
            Definition: traits.h:105
            -
            SyncProcedure trait.
            Definition: traits.h:126
            -
            CallHandler trait.
            Definition: traits.h:78
            -
            NotifyHandler trait.
            Definition: traits.h:70
            -
            AsyncProcedure trait.
            Definition: traits.h:116
            -
            Definition: as.h:16
            -
            CoroProcedure trait.
            Definition: traits.h:137
            -
            AsVoidCallHandler.
            Definition: traits.h:96
            +
            ServeHandler trait.
            Definition: traits.h:90
            +
            SyncProcedure trait.
            Definition: traits.h:111
            +
            CallHandler trait.
            Definition: traits.h:80
            +
            completion_handler< rpc > completion_handler
            The completion_handler for msgpack-RPC.
            Definition: msgpack_rpc.h:21
            +
            NotifyHandler trait.
            Definition: traits.h:72
            +
            AsyncProcedure trait.
            Definition: traits.h:101
            +
            Definition: arg.h:14
            +
            CoroProcedure trait.
            Definition: traits.h:122
            diff --git a/docs/utils_8h_source.html b/docs/utils_8h_source.html index 90dd108..2264f05 100644 --- a/docs/utils_8h_source.html +++ b/docs/utils_8h_source.html @@ -83,139 +83,118 @@
            10 #include <type_traits>
            11 #include <vector>
            12 
            -
            13 #include <msgpack.hpp>
            -
            14 
            -
            15 #include "../error_code.h"
            -
            16 #include "config.h"
            -
            17 #include "log.h"
            +
            13 #include "config.h"
            +
            14 #include "log.h"
            +
            15 
            +
            16 namespace packio {
            +
            17 namespace internal {
            18 
            -
            19 namespace packio {
            -
            20 namespace internal {
            -
            21 
            -
            22 template <typename, typename = void>
            -
            23 struct func_traits : std::false_type {
            -
            24 };
            -
            25 
            -
            26 template <typename T>
            -
            27 struct func_traits<T, std::void_t<decltype(&std::decay_t<T>::operator())>>
            -
            28  : func_traits<decltype(&std::decay_t<T>::operator())> {
            -
            29 };
            -
            30 
            -
            31 template <typename C, typename R, typename... Args>
            -
            32 struct func_traits<R (C::*)(Args...)> : func_traits<R (*)(Args...)> {
            -
            33 };
            -
            34 
            -
            35 template <typename C, typename R, typename... Args>
            -
            36 struct func_traits<R (C::*)(Args...) const> : func_traits<R (*)(Args...)> {
            -
            37 };
            -
            38 
            -
            39 template <typename R, typename... Args>
            -
            40 struct func_traits<R (*)(Args...)> : std::true_type {
            -
            41  using result_type = R;
            -
            42  using args_type = std::tuple<Args...>;
            -
            43  static constexpr auto args_count = std::tuple_size_v<args_type>;
            -
            44 };
            +
            19 template <typename, typename = void>
            +
            20 struct func_traits : std::false_type {
            +
            21 };
            +
            22 
            +
            23 template <typename T>
            +
            24 struct func_traits<T, std::void_t<decltype(&std::decay_t<T>::operator())>>
            +
            25  : func_traits<decltype(&std::decay_t<T>::operator())> {
            +
            26 };
            +
            27 
            +
            28 template <typename C, typename R, typename... Args>
            +
            29 struct func_traits<R (C::*)(Args...)> : func_traits<R (*)(Args...)> {
            +
            30 };
            +
            31 
            +
            32 template <typename C, typename R, typename... Args>
            +
            33 struct func_traits<R (C::*)(Args...) const> : func_traits<R (*)(Args...)> {
            +
            34 };
            +
            35 
            +
            36 template <typename R, typename... Args>
            +
            37 struct func_traits<R (*)(Args...)> : std::true_type {
            +
            38  using result_type = R;
            +
            39  using args_type = std::tuple<Args...>;
            +
            40  static constexpr auto args_count = std::tuple_size_v<args_type>;
            +
            41 };
            +
            42 
            +
            43 template <typename T>
            +
            44 constexpr bool func_traits_v = func_traits<T>::value;
            45 
            -
            46 template <typename T>
            -
            47 constexpr bool func_traits_v = func_traits<T>::value;
            -
            48 
            -
            49 #if defined(PACKIO_HAS_CO_AWAIT) || defined(PACKIO_DOCUMENTATION)
            -
            50 template <typename>
            -
            51 struct is_awaitable : std::false_type {
            -
            52 };
            -
            53 
            -
            54 template <typename... Args>
            -
            55 struct is_awaitable<net::awaitable<Args...>> : std::true_type {
            -
            56 };
            -
            57 
            -
            58 template <typename, typename = void>
            -
            59 struct is_coroutine : std::false_type {
            -
            60 };
            -
            61 
            -
            62 template <typename T>
            -
            63 struct is_coroutine<T, std::enable_if_t<func_traits_v<T>>>
            -
            64  : is_awaitable<typename func_traits<T>::result_type> {
            -
            65 };
            -
            66 
            -
            67 template <typename T>
            -
            68 constexpr bool is_coroutine_v = is_coroutine<T>::value;
            -
            69 #endif // defined(PACKIO_HAS_CO_AWAIT) || defined(PACKIO_DOCUMENTATION)
            -
            70 
            -
            71 template <typename T>
            -
            72 struct is_tuple : std::false_type {
            -
            73 };
            -
            74 
            -
            75 template <typename... Args>
            -
            76 struct is_tuple<std::tuple<Args...>> : std::true_type {
            -
            77 };
            -
            78 
            -
            79 template <typename T>
            -
            80 constexpr auto is_tuple_v = is_tuple<T>::value;
            -
            81 
            -
            82 template <typename T>
            -
            83 struct shift_tuple;
            -
            84 
            -
            85 template <typename A, typename... Bs>
            -
            86 struct shift_tuple<std::tuple<A, Bs...>> {
            -
            87  using type = std::tuple<Bs...>;
            -
            88 };
            -
            89 
            -
            90 template <typename T>
            -
            91 using shift_tuple_t = typename shift_tuple<T>::type;
            -
            92 
            -
            93 template <typename T>
            -
            94 struct decay_tuple;
            -
            95 
            -
            96 template <typename... Args>
            -
            97 struct decay_tuple<std::tuple<Args...>> {
            -
            98  using type = std::tuple<std::decay_t<Args>...>;
            -
            99 };
            -
            100 
            -
            101 template <typename T>
            -
            102 using decay_tuple_t = typename decay_tuple<T>::type;
            -
            103 
            -
            104 inline net::const_buffer buffer(const msgpack::sbuffer& buf)
            -
            105 {
            -
            106  return net::const_buffer(buf.data(), buf.size());
            -
            107 }
            -
            108 
            -
            109 inline std::vector<net::const_buffer> buffer(const msgpack::vrefbuffer& buf)
            -
            110 {
            -
            111  std::vector<net::const_buffer> vec;
            -
            112  vec.reserve(buf.vector_size());
            -
            113  const struct iovec* iov = buf.vector();
            -
            114  for (std::size_t i = 0; i < buf.vector_size(); ++i) {
            -
            115  vec.push_back(net::const_buffer(iov->iov_base, iov->iov_len));
            -
            116  ++iov;
            -
            117  }
            -
            118  return vec;
            -
            119 }
            -
            120 
            -
            121 template <typename T>
            -
            122 msgpack::object_handle make_msgpack_object(T&& value)
            -
            123 {
            -
            124  msgpack::object_handle oh({}, std::make_unique<msgpack::zone>());
            -
            125  oh.set(msgpack::object(std::forward<T>(value), *oh.zone()));
            -
            126  return oh;
            -
            127 }
            -
            128 
            -
            129 template <typename T>
            -
            130 void set_no_delay(T&)
            -
            131 {
            -
            132 }
            -
            133 
            -
            134 template <>
            -
            135 inline void set_no_delay(net::ip::tcp::socket& socket)
            -
            136 {
            -
            137  socket.set_option(net::ip::tcp::no_delay{true});
            -
            138 }
            -
            139 
            -
            140 } // internal
            -
            141 } // packio
            -
            142 
            -
            143 #endif // PACKIO_UTILS_H
            +
            46 #if defined(PACKIO_HAS_CO_AWAIT)
            +
            47 template <typename>
            +
            48 struct is_awaitable : std::false_type {
            +
            49 };
            +
            50 
            +
            51 template <typename... Args>
            +
            52 struct is_awaitable<net::awaitable<Args...>> : std::true_type {
            +
            53 };
            +
            54 
            +
            55 template <typename, typename = void>
            +
            56 struct is_coroutine : std::false_type {
            +
            57 };
            +
            58 
            +
            59 template <typename T>
            +
            60 struct is_coroutine<T, std::enable_if_t<func_traits_v<T>>>
            +
            61  : is_awaitable<typename func_traits<T>::result_type> {
            +
            62 };
            +
            63 
            +
            64 template <typename T>
            +
            65 constexpr bool is_coroutine_v = is_coroutine<T>::value;
            +
            66 #endif // defined(PACKIO_HAS_CO_AWAIT)
            +
            67 
            +
            68 template <typename T, typename = void>
            +
            69 struct is_tuple : std::false_type {
            +
            70 };
            +
            71 
            +
            72 template <typename T>
            +
            73 struct is_tuple<T, std::void_t<decltype(std::tuple_size<std::decay_t<T>>::value)>>
            +
            74  : std::true_type {
            +
            75 };
            +
            76 
            +
            77 template <typename T>
            +
            78 constexpr auto is_tuple_v = is_tuple<T>::value;
            +
            79 
            +
            80 template <typename T>
            +
            81 struct shift_tuple;
            +
            82 
            +
            83 template <typename A, typename... Bs>
            +
            84 struct shift_tuple<std::tuple<A, Bs...>> {
            +
            85  using type = std::tuple<Bs...>;
            +
            86 };
            +
            87 
            +
            88 template <typename T>
            +
            89 using shift_tuple_t = typename shift_tuple<T>::type;
            +
            90 
            +
            91 template <typename T>
            +
            92 struct decay_tuple;
            +
            93 
            +
            94 template <typename... Args>
            +
            95 struct decay_tuple<std::tuple<Args...>> {
            +
            96  using type = std::tuple<std::decay_t<Args>...>;
            +
            97 };
            +
            98 
            +
            99 template <typename T>
            +
            100 using decay_tuple_t = typename decay_tuple<T>::type;
            +
            101 
            +
            102 template <typename T>
            +
            103 void set_no_delay(T&)
            +
            104 {
            +
            105 }
            +
            106 
            +
            107 template <>
            +
            108 inline void set_no_delay(net::ip::tcp::socket& socket)
            +
            109 {
            +
            110  socket.set_option(net::ip::tcp::no_delay{true});
            +
            111 }
            +
            112 
            +
            113 template <typename T>
            +
            114 std::unique_ptr<std::decay_t<T>> to_unique_ptr(T&& value)
            +
            115 {
            +
            116  return std::make_unique<std::decay_t<T>>(std::forward<T>(value));
            +
            117 }
            +
            118 
            +
            119 } // internal
            +
            120 } // packio
            +
            121 
            +
            122 #endif // PACKIO_UTILS_H
            -
            Definition: as.h:16
            +
            Definition: arg.h:14
            diff --git a/include/packio/arg.h b/include/packio/arg.h new file mode 100644 index 0000000..4288d33 --- /dev/null +++ b/include/packio/arg.h @@ -0,0 +1,62 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#ifndef PACKIO_ARG_H +#define PACKIO_ARG_H + +//! @file +//! Class arg + +#include +#include + +namespace packio { + +class arg { +public: + template + struct with_value { + const std::string name; + T value; + }; + + explicit constexpr arg(std::string_view name) : name_{name} {} + + template + constexpr with_value operator=(T&& value) + { + return {std::string{name_}, std::forward(value)}; + } + +private: + std::string_view name_; +}; + +template +struct is_arg_impl : std::false_type { +}; + +template +struct is_arg_impl> : std::true_type { +}; + +template +struct is_arg : is_arg_impl> { +}; + +template +constexpr bool is_arg_v = is_arg::value; + +namespace arg_literals { + +constexpr arg operator"" _arg(const char* str, std::size_t) +{ + return arg{str}; +} + +} // arg_literals + +} // packio + +#endif // PACKIO_INTERNAL_ARG_H diff --git a/include/packio/as.h b/include/packio/as.h deleted file mode 100644 index 73f526b..0000000 --- a/include/packio/as.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef PACKIO_AS_H -#define PACKIO_AS_H - -//! @file -//! Function @ref packio::as "as" - -#include -#include -#include - -#include "error_code.h" -#include "internal/config.h" -#include "internal/utils.h" -#include "traits.h" - -namespace packio { - -//! Function used to wrap a typed call handler -//! -//! This function is used to provide a call handler that expects a specific -//! return type. If the procedure call succeeds but the returned type is not -//! what is expected, the handler will be called with @ref -//! error::bad_result_type. The optional given as second argument will have a -//! value only if the error code is @ref error::success. -//! -//! @tparam Result The expected return type for the procedure -//! @param handler Call handler to wrap. Must satisfy @ref traits::AsCallHandler -template -auto as( - AsCallHandler&& handler, - std::enable_if_t, void*> = nullptr) -{ - PACKIO_STATIC_ASSERT_TTRAIT(AsCallHandler, Result); - return [handler = std::forward(handler)]( - error_code ec, msgpack::object_handle result) mutable { - if (ec) { - handler(ec, std::nullopt); - } - else { - try { - handler(ec, std::optional{result->as()}); - } - catch (msgpack::type_error&) { - ec = make_error_code(error::bad_result_type); - handler(ec, std::nullopt); - } - } - }; -} - -//! Function used to wrap a call handler that expects a void result -//! -//! @overload -//! The only point of this wrapper is to verify that the remote procedure -//! returned void. If the remote procedure returns any other type, this wrapper -//! will set the error code to @ref error::bad_result_type. -template -auto as( - AsVoidCallHandler&& handler, - std::enable_if_t, void*> = nullptr) -{ - PACKIO_STATIC_ASSERT_TRAIT(AsVoidCallHandler); - return [handler = std::forward(handler)]( - error_code ec, msgpack::object_handle result) mutable { - if (!ec && result->type != msgpack::type::NIL) { - ec = make_error_code(error::bad_result_type); - } - handler(ec); - }; -} - -} // packio - -#endif // PACKIO_AS_H diff --git a/include/packio/client.h b/include/packio/client.h index bd98b29..f0a6862 100644 --- a/include/packio/client.h +++ b/include/packio/client.h @@ -11,36 +11,40 @@ #include #include #include -#include #include #include #include #include -#include - -#include "error_code.h" #include "internal/config.h" #include "internal/manual_strand.h" -#include "internal/msgpack_rpc.h" -#include "internal/unique_function.h" +#include "internal/movable_function.h" +#include "internal/rpc.h" #include "internal/utils.h" #include "traits.h" namespace packio { //! The client class +//! @tparam Rpc RPC protocol implementation //! @tparam Socket Socket type to use for this client //! @tparam Map Container used to associate call IDs and handlers -template class Map = std::map> -class client : public std::enable_shared_from_this> { +template class Map = default_map> +class client : public std::enable_shared_from_this> { public: - using socket_type = Socket; //!< The socket type - using protocol_type = - typename socket_type::protocol_type; //!< The protocol type - using executor_type = - typename socket_type::executor_type; //!< The executor type - using std::enable_shared_from_this>::shared_from_this; + //! The RPC protocol type + using rpc_type = Rpc; + //! The call ID type + using id_type = typename rpc_type::id_type; + //! The response of a RPC call + using response_type = typename rpc_type::response_type; + //! The socket type + using socket_type = Socket; + //! The protocol type + using protocol_type = typename socket_type::protocol_type; + //! The executor type + using executor_type = typename socket_type::executor_type; + using std::enable_shared_from_this>::shared_from_this; //! The default size reserved by the reception buffer static constexpr size_t kDefaultBufferReserveSize = 4096; @@ -56,6 +60,7 @@ class client : public std::enable_shared_from_this> { //! Get the underlying socket socket_type& socket() noexcept { return socket_; } + //! Get the underlying socket, const const socket_type& socket() const noexcept { return socket_; } @@ -75,30 +80,23 @@ class client : public std::enable_shared_from_this> { //! Cancel a pending call //! - //! The associated handler will be called with @ref error::cancelled + //! The associated handler will be called with net::error::operation_aborted //! @param id The call ID of the call to cancel void cancel(id_type id) { net::dispatch(call_strand_, [self = shared_from_this(), id] { - auto ec = make_error_code(error::cancelled); - self->async_call_handler( - id, internal::make_msgpack_object(ec.message()), ec); + auto ec = make_error_code(net::error::operation_aborted); + self->async_call_handler(id, ec, {}); }); } //! Cancel all pending calls //! - //! The associated handlers will be called with @ref error::cancelled + //! The associated handlers will be called with net::error::operation_aborted void cancel() { net::dispatch(call_strand_, [self = shared_from_this()] { - auto ec = make_error_code(error::cancelled); - while (!self->pending_.empty()) { - self->async_call_handler( - self->pending_.begin()->first, - internal::make_msgpack_object(ec.message()), - ec); - } + self->cancel_all_calls(); }); } @@ -106,31 +104,29 @@ class client : public std::enable_shared_from_this> { //! //! A notify request will call the remote procedure but //! does not expect a response - //! @tparam Buffer Buffer used to serialize the arguments. Recommended: - //! - msgpack::sbuffer is an owning buffer \n - //! - msgpack::vrefbuffer is a non-owning buffer //! @param name Remote procedure name to call //! @param args Tuple of arguments to pass to the remote procedure //! @param handler Handler called after the notify request is sent. //! Must satisfy the @ref traits::NotifyHandler trait template < - typename Buffer = msgpack::sbuffer, PACKIO_COMPLETION_TOKEN_FOR(void(error_code)) NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type), - typename... Args> + typename ArgsTuple, + typename = std::enable_if_t>> auto async_notify( std::string_view name, - const std::tuple& args, + ArgsTuple&& args, NotifyHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type)) { return net::async_initiate( - initiate_async_notify(this), handler, name, args); + initiate_async_notify(this), + handler, + name, + std::forward(args)); } - //! Send a notify request to the server with no argument //! @overload template < - typename Buffer = msgpack::sbuffer, PACKIO_COMPLETION_TOKEN_FOR(void(error_code)) NotifyHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type), typename = std::enable_if_t>> @@ -138,40 +134,39 @@ class client : public std::enable_shared_from_this> { std::string_view name, NotifyHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type)) { - return async_notify( + return async_notify( name, std::tuple{}, std::forward(handler)); } //! Call a remote procedure //! - //! @tparam Buffer Buffer used to serialize the arguments. Recommended: - //! - msgpack::sbuffer is an owning buffer \n - //! - msgpack::vrefbuffer is a non-owning buffer //! @param name Remote procedure name to call //! @param args Tuple of arguments to pass to the remote procedure //! @param handler Handler called with the return value //! Must satisfy the @ref traits::CallHandler trait //! @param call_id Output parameter that will receive the call ID template < - typename Buffer = msgpack::sbuffer, - PACKIO_COMPLETION_TOKEN_FOR(void(error_code, msgpack::object_handle)) + PACKIO_COMPLETION_TOKEN_FOR(void(error_code, response_type)) CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type), - typename... Args> + typename ArgsTuple, + typename = std::enable_if_t>> auto async_call( std::string_view name, - const std::tuple& args, + ArgsTuple&& args, CallHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional> call_id = std::nullopt) { - return net::async_initiate( - initiate_async_call(this), handler, name, args, call_id); + return net::async_initiate( + initiate_async_call(this), + handler, + name, + std::forward(args), + call_id); } - //! Call a remote procedure //! @overload template < - typename Buffer = msgpack::sbuffer, - PACKIO_COMPLETION_TOKEN_FOR(void(error_code, msgpack::object_handle)) + PACKIO_COMPLETION_TOKEN_FOR(void(error_code, response_type)) CallHandler PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type), typename = std::enable_if_t>> auto async_call( @@ -179,13 +174,23 @@ class client : public std::enable_shared_from_this> { CallHandler&& handler PACKIO_DEFAULT_COMPLETION_TOKEN(executor_type), std::optional> call_id = std::nullopt) { - return async_call( + return async_call( name, std::tuple{}, std::forward(handler), call_id); } private: + using parser_type = typename rpc_type::incremental_parser_type; using async_call_handler_type = - internal::unique_function; + internal::movable_function; + + void cancel_all_calls() + { + assert(call_strand_.running_in_this_thread()); + auto ec = make_error_code(net::error::operation_aborted); + while (!pending_.empty()) { + async_call_handler(pending_.begin()->first, ec, {}); + } + } void maybe_stop_reading() { @@ -201,16 +206,14 @@ class client : public std::enable_shared_from_this> { } template - void async_send(std::unique_ptr buffer_ptr, WriteHandler&& handler) + void async_send(std::unique_ptr&& buffer_ptr, WriteHandler&& handler) { wstrand_.push([self = shared_from_this(), buffer_ptr = std::move(buffer_ptr), handler = std::forward(handler)]() mutable { - using internal::buffer; - internal::set_no_delay(self->socket_); - auto buf = buffer(*buffer_ptr); + auto buf = rpc_type::buffer(*buffer_ptr); net::async_write( self->socket_, buf, @@ -224,11 +227,10 @@ class client : public std::enable_shared_from_this> { }); } - void async_read(std::unique_ptr unpacker) + void async_read(parser_type&& parser) { - unpacker->reserve_buffer(buffer_reserve_size_); - auto buffer = net::buffer( - unpacker->buffer(), unpacker->buffer_capacity()); + parser.reserve_buffer(buffer_reserve_size_); + auto buffer = net::buffer(parser.buffer(), parser.buffer_capacity()); assert(call_strand_.running_in_this_thread()); reading_ = true; @@ -237,76 +239,62 @@ class client : public std::enable_shared_from_this> { buffer, net::bind_executor( call_strand_, - [self = shared_from_this(), unpacker = std::move(unpacker)]( + [self = shared_from_this(), parser = std::move(parser)]( error_code ec, size_t length) mutable { - PACKIO_TRACE("read: {}", length); - unpacker->buffer_consumed(length); - - msgpack::object_handle response; - while (unpacker->next(response)) { - self->process_response(std::move(response), ec); - } - // stop if there is an error or there is no more pending calls assert(self->call_strand_.running_in_this_thread()); - if (ec && ec != net::error::operation_aborted) { + if (ec) { PACKIO_WARN("read error: {}", ec.message()); self->reading_ = false; // cancel all pending calls - while (!self->pending_.empty()) { - self->async_call_handler( - self->pending_.begin()->first, - internal::make_msgpack_object(ec.message()), - ec); - } + self->cancel_all_calls(); return; } + PACKIO_TRACE("read: {}", length); + parser.buffer_consumed(length); + + while (auto response = parser.get_response()) { + if (!response) { + PACKIO_ERROR("bad response"); + continue; + } + self->async_call_handler(std::move(*response)); + } + if (self->pending_.empty()) { PACKIO_TRACE("done reading, no more pending calls"); self->reading_ = false; return; } - self->async_read(std::move(unpacker)); + self->async_read(std::move(parser)); })); } - void process_response(msgpack::object_handle response, error_code ec) + void async_call_handler(response_type&& response) { - if (!verify_reponse(response.get())) { - PACKIO_ERROR("received unexpected response"); - return; - } - - const auto& call_response = response->via.array.ptr; - int id = call_response[1].as(); - msgpack::object err = call_response[2]; - msgpack::object result = call_response[3]; - - if (err.type != msgpack::type::NIL) { - ec = make_error_code(error::call_error); - async_call_handler(id, {err, std::move(response.zone())}, ec); - } - else { - ec = make_error_code(error::success); - async_call_handler(id, {result, std::move(response.zone())}, ec); - } + auto id = response.id; + return async_call_handler(id, {}, std::move(response)); } - void async_call_handler(id_type id, msgpack::object_handle result, error_code ec) + void async_call_handler(id_type id, error_code ec, response_type&& response) { net::dispatch( call_strand_, - [ec, id, self = shared_from_this(), result = std::move(result)]() mutable { - PACKIO_DEBUG("calling handler for id: {}", id); + [ec, + id, + self = shared_from_this(), + response = std::move(response)]() mutable { + PACKIO_DEBUG( + "calling handler for id: {}", rpc_type::format_id(id)); assert(call_strand_.running_in_this_thread()); auto it = self->pending_.find(id); if (it == self->pending_.end()) { - PACKIO_WARN("unexisting id"); + PACKIO_WARN("unexisting id: {}", rpc_type::format_id(id)); return; } @@ -322,31 +310,12 @@ class client : public std::enable_shared_from_this> { self->socket_.get_executor(), [ec, handler = std::move(handler), - result = std::move(result)]() mutable { - handler(ec, std::move(result)); + response = std::move(response)]() mutable { + handler(ec, std::move(response)); }); }); } - bool verify_reponse(const msgpack::object& response) - { - if (response.type != msgpack::type::ARRAY) { - PACKIO_ERROR("unexpected message type: {}", response.type); - return false; - } - if (response.via.array.size != 4) { - PACKIO_ERROR("unexpected message size: {}", response.via.array.size); - return false; - } - int type = response.via.array.ptr[0].as(); - if (type != static_cast(msgpack_rpc_type::response)) { - PACKIO_ERROR("unexpected type: {}", type); - return false; - } - return true; - } - - template class initiate_async_notify { public: using executor_type = typename client::executor_type; @@ -358,21 +327,23 @@ class client : public std::enable_shared_from_this> { return self_->get_executor(); } - template + template void operator()( NotifyHandler&& handler, std::string_view name, - const std::tuple& args) const + ArgsTuple&& args) const { PACKIO_STATIC_ASSERT_TRAIT(NotifyHandler); PACKIO_DEBUG("async_notify: {}", name); - auto packer_buf = std::make_unique(); - msgpack::pack( - *packer_buf, - std::forward_as_tuple( - static_cast(msgpack_rpc_type::notification), name, args)); + auto packer_buf = internal::to_unique_ptr(std::apply( + [&name](auto&&... args) { + return rpc_type::serialize_notification( + name, std::forward(args)...); + }, + std::forward(args)) + ); self_->async_send( std::move(packer_buf), [handler = std::forward(handler)]( @@ -393,7 +364,6 @@ class client : public std::enable_shared_from_this> { client* self_; }; - template class initiate_async_call { public: using executor_type = typename client::executor_type; @@ -405,14 +375,14 @@ class client : public std::enable_shared_from_this> { return self_->get_executor(); } - template + template void operator()( CallHandler&& handler, std::string_view name, - const std::tuple& args, + ArgsTuple&& args, std::optional> opt_call_id) const { - PACKIO_STATIC_ASSERT_TRAIT(CallHandler); + PACKIO_STATIC_ASSERT_TTRAIT(CallHandler, rpc_type); PACKIO_DEBUG("async_call: {}", name); id_type call_id = self_->id_.fetch_add(1, std::memory_order_acq_rel); @@ -420,14 +390,12 @@ class client : public std::enable_shared_from_this> { opt_call_id->get() = call_id; } - auto packer_buf = std::make_unique(); - msgpack::pack( - *packer_buf, - std::forward_as_tuple( - static_cast(msgpack_rpc_type::request), - call_id, - name, - args)); + auto packer_buf = internal::to_unique_ptr(std::apply( + [&name, &call_id](auto&&... args) { + return rpc_type::serialize_request( + call_id, name, std::forward(args)...); + }, + std::forward(args))); net::dispatch( self_->call_strand_, @@ -443,7 +411,7 @@ class client : public std::enable_shared_from_this> { // if we are not reading, start the read operation if (!self->reading_) { PACKIO_DEBUG("start reading"); - self->async_read(std::make_unique()); + self->async_read(parser_type{}); } // send the request buffer @@ -453,10 +421,7 @@ class client : public std::enable_shared_from_this> { error_code ec, std::size_t length) mutable { if (ec) { PACKIO_WARN("write error: {}", ec.message()); - self->async_call_handler( - call_id, - internal::make_msgpack_object(ec.message()), - ec); + self->async_call_handler(call_id, ec, {}); } else { PACKIO_TRACE("write: {}", length); @@ -472,7 +437,7 @@ class client : public std::enable_shared_from_this> { socket_type socket_; std::size_t buffer_reserve_size_{kDefaultBufferReserveSize}; - std::atomic id_{0}; + std::atomic id_{0}; internal::manual_strand wstrand_; @@ -482,12 +447,14 @@ class client : public std::enable_shared_from_this> { }; //! Create a client from a socket +//! @tparam Rpc RPC protocol implementation //! @tparam Socket Socket type to use for this client //! @tparam Map Container used to associate call IDs and handlers -template class Map = std::map> +template class Map = default_map> auto make_client(Socket&& socket) { - return std::make_shared>(std::forward(socket)); + return std::make_shared>( + std::forward(socket)); } } // packio diff --git a/include/packio/dispatcher.h b/include/packio/dispatcher.h index 6f40766..e28082a 100644 --- a/include/packio/dispatcher.h +++ b/include/packio/dispatcher.h @@ -15,81 +15,153 @@ #include #include -#include - -#include "error_code.h" #include "handler.h" #include "internal/config.h" -#include "internal/unique_function.h" +#include "internal/movable_function.h" +#include "internal/rpc.h" #include "internal/utils.h" #include "traits.h" namespace packio { //! The dispatcher class, used to store and dispatch procedures +//! @tparam Rpc RPC protocol implementation //! @tparam Map The container used to associate procedures to their name //! @tparam Lockable The lockable used to protect accesses to the procedure map -template

            Classes

            class  packio::completion_handler< Rpc >
             The completion_handler class. More...
             
            struct  packio::traits::NotifyHandler< T >
             NotifyHandler trait. More...
             
            struct  packio::traits::CallHandler< T >
            struct  packio::traits::CallHandler< T, Rpc >
             CallHandler trait. More...
             
            struct  packio::traits::AsCallHandler< T, Result >
             AsCallHandler. More...
             
            struct  packio::traits::AsVoidCallHandler< T >
             AsVoidCallHandler. More...
             
            struct  packio::traits::ServeHandler< T, Session >
             ServeHandler trait. More...
             
            struct  packio::traits::AsyncProcedure< T >
            struct  packio::traits::AsyncProcedure< T, Rpc >
             AsyncProcedure trait. More...
             
            struct  packio::traits::SyncProcedure< T >