Transport implementation using Unix domain sockets.
More...
#include <pipe_transport.hpp>
|
auto | GetSocket () -> asio::local::stream_protocol::socket & |
|
Transport implementation using Unix domain sockets.
This class provides transport functionality over Unix domain sockets, supporting both client and server modes for inter-process communication on the same machine.
Definition at line 17 of file pipe_transport.hpp.
◆ PipeTransport() [1/3]
jsonrpc::transport::PipeTransport::PipeTransport |
( |
const std::string & | socket_path, |
|
|
bool | is_server ) |
Constructs a PipeTransport.
- Parameters
-
socketPath | Path to the Unix domain socket. |
isServer | True if the transport acts as a server; false if it acts as a client. |
Definition at line 10 of file pipe_transport.cpp.
11 : socket_(io_context_), socket_path_(socket_path), is_server_(is_server) {
12 spdlog::info(
13 "Initializing PipeTransport with socket path: {}. IsServer: {}",
14 socket_path, is_server);
15
16 if (is_server_) {
17 RemoveExistingSocketFile();
18 BindAndListen();
19 } else {
20 Connect();
21 }
22}
◆ ~PipeTransport()
jsonrpc::transport::PipeTransport::~PipeTransport |
( |
| ) |
|
|
override |
Definition at line 28 of file pipe_transport.cpp.
28 {
29 spdlog::info("Closing socket and shutting down PipeTransport.");
30 socket_.close();
31 io_context_.stop();
32}
◆ PipeTransport() [2/3]
jsonrpc::transport::PipeTransport::PipeTransport |
( |
const PipeTransport & | | ) |
|
|
delete |
◆ PipeTransport() [3/3]
jsonrpc::transport::PipeTransport::PipeTransport |
( |
PipeTransport && | | ) |
|
|
delete |
◆ GetSocket()
auto jsonrpc::transport::PipeTransport::GetSocket |
( |
| ) |
-> asio::local::stream_protocol::socket & |
|
protected |
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ ReceiveMessage()
auto jsonrpc::transport::PipeTransport::ReceiveMessage |
( |
| ) |
-> std::string |
|
overridevirtual |
Receives a message from the transport layer.
- Returns
- The JSON-RPC response as a string.
Implements jsonrpc::transport::Transport.
Definition at line 81 of file pipe_transport.cpp.
81 {
82 try {
83 asio::streambuf buffer;
84 asio::read_until(socket_, buffer, '\n');
85 std::istream is(&buffer);
86 std::string message;
87 std::getline(is, message);
88 spdlog::debug("Received message: {}", message);
89 return message;
90 } catch (const std::exception &e) {
91 spdlog::error("Error receiving message: {}", e.what());
92 socket_.close();
93 throw std::runtime_error("Error receiving message");
94 }
95}
◆ SendMessage()
void jsonrpc::transport::PipeTransport::SendMessage |
( |
const std::string & | message | ) |
|
|
overridevirtual |
Sends a message in string to the transport layer.
- Parameters
-
request | The JSON-RPC request as a string. |
Implements jsonrpc::transport::Transport.
Definition at line 70 of file pipe_transport.cpp.
70 {
71 try {
72 std::string full_message = message + "\n";
73 asio::write(socket_, asio::buffer(full_message));
74 spdlog::debug("Sent message: {}", message);
75 } catch (const std::exception &e) {
76 spdlog::error("Error sending message: {}", e.what());
77 throw std::runtime_error("Error sending message");
78 }
79}
The documentation for this class was generated from the following files: