This commit is contained in:
Benjamin Sergeant 2019-03-15 11:41:57 -07:00
parent 6ff8c6e7f3
commit 3a9cc9b079
7 changed files with 20 additions and 13 deletions

View File

@ -38,7 +38,7 @@ namespace ix
return true; return true;
} }
int SelectInterrupt::getFd() int SelectInterrupt::getFd() const
{ {
return -1; return -1;
} }

View File

@ -21,7 +21,7 @@ namespace ix
virtual bool notify(uint64_t value); virtual bool notify(uint64_t value);
virtual bool clear(); virtual bool clear();
virtual uint64_t read(); virtual uint64_t read();
virtual int getFd(); virtual int getFd() const;
}; };
} }

View File

@ -38,7 +38,7 @@ namespace ix
{ {
SelectInterruptEventFd::SelectInterruptEventFd() SelectInterruptEventFd::SelectInterruptEventFd()
{ {
; _eventfd = -1;
} }
SelectInterruptEventFd::~SelectInterruptEventFd() SelectInterruptEventFd::~SelectInterruptEventFd()
@ -48,7 +48,8 @@ namespace ix
bool SelectInterruptEventFd::init(std::string& errorMsg) bool SelectInterruptEventFd::init(std::string& errorMsg)
{ {
_eventfd = -1; // calling init twice is a programming error
assert(_eventfd == -1);
_eventfd = eventfd(0, 0); _eventfd = eventfd(0, 0);
if (_eventfd < 0) if (_eventfd < 0)
@ -107,7 +108,7 @@ namespace ix
return write(_eventfd, &value, sizeof(value)) == 8; return write(_eventfd, &value, sizeof(value)) == 8;
} }
int SelectInterruptEventFd::getFd() int SelectInterruptEventFd::getFd() const
{ {
return _eventfd; return _eventfd;
} }

View File

@ -23,7 +23,7 @@ namespace ix
bool notify(uint64_t value) final; bool notify(uint64_t value) final;
bool clear() final; bool clear() final;
uint64_t read() final; uint64_t read() final;
int getFd() final; int getFd() const final;
private: private:
int _eventfd; int _eventfd;

View File

@ -8,8 +8,10 @@
#if defined(__linux__) #if defined(__linux__)
# include <ixwebsocket/IXSelectInterruptEventFd.h> # include <ixwebsocket/IXSelectInterruptEventFd.h>
#else #elif defined(__APPLE__)
# include <ixwebsocket/IXSelectInterruptPipe.h> # include <ixwebsocket/IXSelectInterruptPipe.h>
#else
# include <ixwebsocket/IXSelectInterrupt.h>
#endif #endif
namespace ix namespace ix
@ -18,8 +20,10 @@ namespace ix
{ {
#if defined(__linux__) #if defined(__linux__)
return std::make_shared<SelectInterruptEventFd>(); return std::make_shared<SelectInterruptEventFd>();
#else #elif defined(__APPLE__)
return std::make_shared<SelectInterruptPipe>(); return std::make_shared<SelectInterruptPipe>();
#else
return std::make_shared<SelectInterrupt>();
#endif #endif
} }
} }

View File

@ -25,7 +25,8 @@ namespace ix
SelectInterruptPipe::SelectInterruptPipe() SelectInterruptPipe::SelectInterruptPipe()
{ {
; _fildes[kPipeReadIndex] = -1;
_fildes[kPipeWriteIndex] = -1;
} }
SelectInterruptPipe::~SelectInterruptPipe() SelectInterruptPipe::~SelectInterruptPipe()
@ -38,8 +39,9 @@ namespace ix
bool SelectInterruptPipe::init(std::string& errorMsg) bool SelectInterruptPipe::init(std::string& errorMsg)
{ {
_fildes[kPipeReadIndex] = -1; // calling init twice is a programming error
_fildes[kPipeWriteIndex] = -1; assert(_fildes[kPipeReadIndex] == -1);
assert(_fildes[kPipeWriteIndex] == -1);
if (pipe(_fildes) < 0) if (pipe(_fildes) < 0)
{ {
@ -101,7 +103,7 @@ namespace ix
return true; return true;
} }
int SelectInterruptPipe::getFd() int SelectInterruptPipe::getFd() const
{ {
return _fildes[kPipeReadIndex]; return _fildes[kPipeReadIndex];
} }

View File

@ -23,7 +23,7 @@ namespace ix
bool notify(uint64_t value) final; bool notify(uint64_t value) final;
bool clear() final; bool clear() final;
uint64_t read() final; uint64_t read() final;
int getFd() final; int getFd() const final;
private: private:
// Store file descriptors used by the communication pipe. Communication // Store file descriptors used by the communication pipe. Communication