Fixed bug with event notifier being notified with a bad eventfd
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <atomic>
|
||||
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
|
||||
@@ -26,9 +27,7 @@ namespace Bloom
|
||||
{
|
||||
private:
|
||||
int fileDescriptor = -1;
|
||||
|
||||
public:
|
||||
EventNotifier() = default;
|
||||
std::atomic<bool> initialised = false;
|
||||
|
||||
void init() {
|
||||
this->fileDescriptor = ::eventfd(0, EFD_NONBLOCK);
|
||||
@@ -37,12 +36,34 @@ namespace Bloom
|
||||
throw Exceptions::Exception("Failed to create new eventfd object - error number: "
|
||||
+ std::to_string(errno));
|
||||
}
|
||||
|
||||
this->initialised = true;
|
||||
}
|
||||
|
||||
void close() {
|
||||
::close(this->fileDescriptor);
|
||||
this->initialised = false;
|
||||
}
|
||||
|
||||
public:
|
||||
EventNotifier() {
|
||||
this->init();
|
||||
};
|
||||
|
||||
~EventNotifier() {
|
||||
if (this->initialised) {
|
||||
this->close();
|
||||
}
|
||||
}
|
||||
|
||||
int getFileDescriptor() {
|
||||
return this->fileDescriptor;
|
||||
}
|
||||
|
||||
bool isInitialised() {
|
||||
return this->initialised;
|
||||
}
|
||||
|
||||
void notify() {
|
||||
if (::eventfd_write(this->fileDescriptor, 1) < 0) {
|
||||
throw Exceptions::Exception("Failed to increment eventfd counter - error number: "
|
||||
@@ -57,9 +78,5 @@ namespace Bloom
|
||||
"error number: " + std::to_string(errno));
|
||||
}
|
||||
}
|
||||
|
||||
void close() {
|
||||
::close(this->fileDescriptor);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user