From 21fb69b630178d39ef19f82987f25f695aad1688 Mon Sep 17 00:00:00 2001 From: niansa Date: Mon, 19 Jul 2021 15:14:37 +0200 Subject: [PATCH] Updated to use QBiIPC instead of simple QIPC --- child_launcher.cpp | 10 +++++----- example/child.cpp | 2 +- example/main.cpp | 2 +- hss.hpp | 12 ++++++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/child_launcher.cpp b/child_launcher.cpp index 1bc0d6f..6a39e10 100644 --- a/child_launcher.cpp +++ b/child_launcher.cpp @@ -33,17 +33,17 @@ void enable_limits() { int main(int argc, char **argv) { // Get IPC - if (argc != 4) { + if (argc != 6) { abort(); } - QIPC ipc(std::stoi(argv[1]), std::stoi(argv[2])); + QBiIPC ipc({QIPC(std::stoi(argv[1]), std::stoi(argv[2])), QIPC(std::stoi(argv[3]), std::stoi(argv[4]))}); // Launch + Dlhandle dl(argv[5], RTLD_NOW | RTLD_LOCAL); + auto entry = dl.get("entry"); + enable_limits(); close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); - Dlhandle dl(argv[3], RTLD_NOW | RTLD_LOCAL); - auto entry = dl.get("entry"); - enable_limits(); entry(ipc); exit(EXIT_SUCCESS); } diff --git a/example/child.cpp b/example/child.cpp index 5ec8247..df4ad02 100644 --- a/example/child.cpp +++ b/example/child.cpp @@ -5,7 +5,7 @@ extern "C" -void entry(QIPC& ipc) { +void entry(QBiIPC& ipc) { ipc.send("Hello world!"); ipc.send_raw(size_t(1234567890)); diff --git a/example/main.cpp b/example/main.cpp index b4446a4..cae6fca 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -6,7 +6,7 @@ int main() { - QIPC ipc; + QBiIPC ipc; ipc.create(); HSS::run(ipc, "./libHSSTestChild.so"); diff --git a/hss.hpp b/hss.hpp index e2f12ba..2f654fa 100644 --- a/hss.hpp +++ b/hss.hpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,14 +6,17 @@ namespace HSS { -inline void run(QIPC& ipc, const std::string& file) { +inline void run(QBiIPC& ipc, const std::string& file) { if (fork() == 0) { execlp("HSSChildLauncher", "child", - std::to_string(ipc.get_in()).c_str(), - std::to_string(ipc.get_out()).c_str(), + std::to_string(ipc.out.get_in()).c_str(), + std::to_string(ipc.out.get_out()).c_str(), + std::to_string(ipc.in.get_in()).c_str(), + std::to_string(ipc.in.get_out()).c_str(), file.c_str(), nullptr); - throw std::runtime_error("Failed to run HSSChildLauncher"); + std::cerr << "Failed to run HSSChildLauncher" << std::endl; + abort(); } } }