-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Unix Domain Socket Transport Layers (#20)
* Add asio 1.28.2 dependency * Add PipeTransport class with Unix domain socket support * Upgrade project to C++20 and add FramedPipeTransport implementation
- Loading branch information
1 parent
67abe75
commit 5d0149a
Showing
28 changed files
with
716 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <iostream> | ||
#include <memory> | ||
|
||
#include <jsonrpc/client/client.hpp> | ||
#include <jsonrpc/transport/framed_pipe_transport.hpp> | ||
#include <nlohmann/json.hpp> | ||
#include <spdlog/sinks/basic_file_sink.h> | ||
#include <spdlog/spdlog.h> | ||
|
||
using namespace jsonrpc::client; | ||
using namespace jsonrpc::transport; | ||
using Json = nlohmann::json; | ||
|
||
int main() { | ||
auto logger = spdlog::basic_logger_mt("client", "logs/client.log", true); | ||
spdlog::set_default_logger(logger); | ||
spdlog::set_level(spdlog::level::debug); | ||
spdlog::flush_on(spdlog::level::debug); | ||
|
||
std::string socketPath = "/tmp/calculator_pipe"; | ||
auto transport = std::make_unique<FramedPipeTransport>(socketPath, false); | ||
Client client(std::move(transport)); | ||
client.Start(); | ||
|
||
Json addRes = client.SendMethodCall("add", Json({{"a", 10}, {"b", 5}})); | ||
spdlog::info("Add result: {}", addRes.dump()); | ||
|
||
Json divRes = client.SendMethodCall("divide", Json({{"a", 10}, {"b", 0}})); | ||
spdlog::info("Divide result: {}", divRes.dump()); | ||
|
||
client.SendNotification("stop"); | ||
|
||
client.Stop(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <memory> | ||
|
||
#include <jsonrpc/server/server.hpp> | ||
#include <jsonrpc/transport/framed_pipe_transport.hpp> | ||
#include <nlohmann/json.hpp> | ||
#include <spdlog/sinks/basic_file_sink.h> | ||
#include <spdlog/spdlog.h> | ||
|
||
#include "calculator.hpp" | ||
|
||
using namespace jsonrpc::server; | ||
using namespace jsonrpc::transport; | ||
using Json = nlohmann::json; | ||
|
||
int main() { | ||
auto logger = spdlog::basic_logger_mt("server", "logs/server.log", true); | ||
spdlog::set_default_logger(logger); | ||
spdlog::set_level(spdlog::level::debug); | ||
spdlog::flush_on(spdlog::level::debug); | ||
|
||
std::string socketPath = "/tmp/calculator_pipe"; | ||
auto transport = std::make_unique<FramedPipeTransport>(socketPath, true); | ||
Server server(std::move(transport)); | ||
Calculator calculator; | ||
|
||
server.RegisterMethodCall( | ||
"add", [&calculator](const std::optional<Json> ¶ms) { | ||
return calculator.Add(params.value()); | ||
}); | ||
|
||
server.RegisterMethodCall( | ||
"divide", [&calculator](const std::optional<Json> ¶ms) { | ||
return calculator.Divide(params.value()); | ||
}); | ||
|
||
server.RegisterNotification( | ||
"stop", [&server](const std::optional<Json> &) { server.Stop(); }); | ||
|
||
server.Start(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <iostream> | ||
#include <memory> | ||
|
||
#include <jsonrpc/client/client.hpp> | ||
#include <jsonrpc/transport/pipe_transport.hpp> | ||
#include <nlohmann/json.hpp> | ||
#include <spdlog/sinks/basic_file_sink.h> | ||
#include <spdlog/spdlog.h> | ||
|
||
using namespace jsonrpc::client; | ||
using namespace jsonrpc::transport; | ||
using Json = nlohmann::json; | ||
|
||
int main() { | ||
auto logger = spdlog::basic_logger_mt("client", "logs/client.log", true); | ||
spdlog::set_default_logger(logger); | ||
spdlog::set_level(spdlog::level::debug); | ||
spdlog::flush_on(spdlog::level::debug); | ||
|
||
std::string socketPath = "/tmp/calculator_pipe"; | ||
auto transport = std::make_unique<PipeTransport>(socketPath, false); | ||
Client client(std::move(transport)); | ||
client.Start(); | ||
|
||
Json addRes = client.SendMethodCall("add", Json({{"a", 10}, {"b", 5}})); | ||
spdlog::info("Add result: {}", addRes.dump()); | ||
|
||
Json divRes = client.SendMethodCall("divide", Json({{"a", 10}, {"b", 0}})); | ||
spdlog::info("Divide result: {}", divRes.dump()); | ||
|
||
client.SendNotification("stop"); | ||
|
||
client.Stop(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <memory> | ||
|
||
#include <jsonrpc/server/server.hpp> | ||
#include <jsonrpc/transport/pipe_transport.hpp> | ||
#include <nlohmann/json.hpp> | ||
#include <spdlog/sinks/basic_file_sink.h> | ||
#include <spdlog/spdlog.h> | ||
|
||
#include "calculator.hpp" | ||
|
||
using namespace jsonrpc::server; | ||
using namespace jsonrpc::transport; | ||
using Json = nlohmann::json; | ||
|
||
int main() { | ||
auto logger = spdlog::basic_logger_mt("server", "logs/server.log", true); | ||
spdlog::set_default_logger(logger); | ||
spdlog::set_level(spdlog::level::debug); | ||
spdlog::flush_on(spdlog::level::debug); | ||
|
||
std::string socketPath = "/tmp/calculator_pipe"; | ||
|
||
auto transport = std::make_unique<PipeTransport>(socketPath, true); | ||
Server server(std::move(transport)); | ||
Calculator calculator; | ||
|
||
server.RegisterMethodCall( | ||
"add", [&calculator](const std::optional<Json> ¶ms) { | ||
return calculator.Add(params.value()); | ||
}); | ||
|
||
server.RegisterMethodCall( | ||
"divide", [&calculator](const std::optional<Json> ¶ms) { | ||
return calculator.Divide(params.value()); | ||
}); | ||
|
||
server.RegisterNotification( | ||
"stop", [&server](const std::optional<Json> &) { server.Stop(); }); | ||
|
||
server.Start(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.