Skip to content

Commit

Permalink
Send acknowledge on unregister
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyStreamlabs committed Dec 5, 2018
1 parent 9a10be6 commit 5596e7f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
4 changes: 3 additions & 1 deletion crash-handler-process/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ void checkProcesses(std::mutex* m) {
processes.at(index)->mutex.unlock();
index++;
}

m->unlock();

if (!alive) {
index--;
if (!processes.at(index)->getCritical()) {
Expand Down Expand Up @@ -249,7 +252,6 @@ void checkProcesses(std::mutex* m) {
else {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
m->unlock();
}
*exitApp = true;
}
Expand Down
33 changes: 31 additions & 2 deletions crash-handler-process/namedsocket-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,36 @@ NamedSocket_win::~NamedSocket_win() {
DisconnectNamedPipe(m_handle);
}

void acknowledgeUnregister(void) {
std::cout << "Send ack" << std::endl;
std::string buffer = "exit";
HANDLE hPipe = CreateFile(
TEXT("\\\\.\\pipe\\exit-slobs-crash-handler"),
GENERIC_READ |
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);

if (hPipe == INVALID_HANDLE_VALUE)
return;

if (GetLastError() == ERROR_PIPE_BUSY)
return;

DWORD bytesWritten;

WriteFile(
hPipe,
buffer.data(),
buffer.size(), &bytesWritten,
NULL);

CloseHandle(hPipe);
}

void processRequest(std::vector<char> p_buffer, std::vector<Process*>* processes, std::mutex* mu, bool* exitApp) {
Message msg(p_buffer);
mu->lock();
Expand All @@ -157,14 +187,13 @@ void processRequest(std::vector<char> p_buffer, std::vector<Process*>* processe
if (it != processes->end()) {
Process* p = (Process*)(*it);
p->stopWorker();
if (p->getWorker()->joinable())
p->getWorker()->join();

processes->erase(it);

if (p->getCritical())
*exitApp = true;
}
acknowledgeUnregister();
break;
}
case EXIT:
Expand Down

0 comments on commit 5596e7f

Please sign in to comment.