library/src/internal.cpp

38 lines
729 B
C++
Raw Normal View History

#include "internal.h"
2019-11-04 23:17:15 +01:00
#include <sys/shm.h>
2019-11-06 12:47:34 +01:00
#include <csignal>
2019-11-04 23:17:15 +01:00
Impl impl;
2019-11-04 23:17:15 +01:00
void *getSharedMemory(){
impl.sharedMemorySize = 8000;
2019-11-06 12:47:34 +01:00
auto id = shmget(impl.sharedMemoryKey, impl.sharedMemorySize, 0644u | IPC_CREAT);
2019-11-04 23:17:15 +01:00
if(id == -1){
//error
impl.sharedMemorySize = 0;
return nullptr;
}
2019-11-04 23:17:15 +01:00
void *data = shmat(id, nullptr, 0);
if(data == (char*)(-1)){
//error
impl.sharedMemorySize = 0;
return nullptr;
}
return data;
}
int getSharedMemorySize(){
return impl.sharedMemorySize;
}
2019-11-06 12:47:34 +01:00
void sendSignal(pid_t pid, int signalNumber) {
kill(pid, signalNumber);
}
void onSignal(int signalNumber, void(*callback)(int)) {
signal(signalNumber, callback);
}