1
0
Fork 0
mirror of https://gitlab.com/niansa/libhss.git synced 2025-03-06 20:49:21 +01:00

Updated to use QBiIPC instead of simple QIPC

This commit is contained in:
niansa 2021-07-19 15:14:37 +02:00
parent 574a8e191a
commit 21fb69b630
4 changed files with 15 additions and 11 deletions

View file

@ -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<void*(QBiIPC&)>("entry");
enable_limits();
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
Dlhandle dl(argv[3], RTLD_NOW | RTLD_LOCAL);
auto entry = dl.get<void*(QIPC&)>("entry");
enable_limits();
entry(ipc);
exit(EXIT_SUCCESS);
}

View file

@ -5,7 +5,7 @@
extern "C"
void entry(QIPC& ipc) {
void entry(QBiIPC& ipc) {
ipc.send("Hello world!");
ipc.send_raw(size_t(1234567890));

View file

@ -6,7 +6,7 @@
int main() {
QIPC ipc;
QBiIPC ipc;
ipc.create();
HSS::run(ipc, "./libHSSTestChild.so");

12
hss.hpp
View file

@ -1,3 +1,4 @@
#include <iostream>
#include <string>
#include <unistd.h>
#include <QIPC/ipc.hpp>
@ -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();
}
}
}