change status signal place

This commit is contained in:
springzfx
2020-05-30 01:59:24 +08:00
parent dfc688b5e5
commit 34e5d81329
4 changed files with 11 additions and 7 deletions

View File

@@ -48,6 +48,7 @@ struct data_t {
};
function<int(int)> callback = NULL;
promise<void> status;
void handle_events(void *cb_cookie, void *data, int data_size) {
auto event = static_cast<data_t *>(data);
@@ -91,13 +92,15 @@ int execsnoop() {
return 1;
}
status.set_value();
while (true) bpf.poll_perf_buffer("events");
return 0;
}
void startThread(function<int(int)> c, promise<void> status) {
status.set_value();
void startThread(function<int(int)> c, promise<void> _status) {
status = move(_status);
callback = c;
execsnoop();
}

View File

@@ -14,7 +14,7 @@ extern function<int(int)> callback;
void handle_events(void *cb_cookie, void *data, int data_size);
int execsnoop();
extern "C" void startThread(function<int(int)> c, promise<void> status);
extern "C" void startThread(function<int(int)> c, promise<void> _status);
typedef void startThread_t(function<int(int)>, promise<void>);
startThread_t *_startThread; // only for dlsym()

View File

@@ -9,7 +9,7 @@ namespace fs = std::filesystem;
namespace CGPROXY::SOCKET {
void SocketServer::socketListening(function<int(char *)> callback) {
void SocketServer::socketListening(function<int(char *)> callback, promise<void> status) {
debug("starting socket listening");
sfd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -26,6 +26,8 @@ void SocketServer::socketListening(function<int(char *)> callback) {
listen(sfd, LISTEN_BACKLOG);
chmod(SOCKET_PATH, S_IRWXU | S_IRWXG | S_IRWXO);
status.set_value();
while (true) {
close(cfd);
cfd = accept(sfd, NULL, NULL);
@@ -56,9 +58,8 @@ SocketServer::~SocketServer() {
}
void startThread(function<int(char *)> callback, promise<void> status) {
status.set_value();
SocketServer server;
server.socketListening(callback);
server.socketListening(callback, move(status));
}
} // namespace CGPROXY::SOCKET

View File

@@ -20,7 +20,7 @@ public:
int sfd = -1, cfd = -1, flag = -1;
struct sockaddr_un unix_socket;
void socketListening(function<int(char *)> callback);
void socketListening(function<int(char *)> callback, promise<void> status);
~SocketServer();
};