replace uint8_t with uint64_t for the send/close requests types / use named variable to index into the _fildes array
This commit is contained in:
parent
9d245add9c
commit
b5e7fb20b6
@ -31,6 +31,11 @@
|
||||
|
||||
namespace ix
|
||||
{
|
||||
// File descriptor at index 0 in _fildes is the read end of the pipe
|
||||
// File descriptor at index 1 in _fildes is the write end of the pipe
|
||||
const int EventFd::kPipeReadIndex = 0;
|
||||
const int EventFd::kPipeWriteIndex = 1;
|
||||
|
||||
EventFd::EventFd()
|
||||
{
|
||||
#ifdef __linux__
|
||||
@ -38,12 +43,12 @@ namespace ix
|
||||
_eventfd = eventfd(0, 0);
|
||||
fcntl(_eventfd, F_SETFL, O_NONBLOCK);
|
||||
#else
|
||||
_fildes[0] = -1;
|
||||
_fildes[1] = -1;
|
||||
_fildes[kPipeReadIndex] = -1;
|
||||
_fildes[kPipeWriteIndex] = -1;
|
||||
|
||||
pipe(_fildes);
|
||||
fcntl(_fildes[0], F_SETFL, O_NONBLOCK);
|
||||
fcntl(_fildes[1], F_SETFL, O_NONBLOCK);
|
||||
fcntl(_fildes[kPipeReadIndex], F_SETFL, O_NONBLOCK);
|
||||
fcntl(_fildes[kPipeWriteIndex], F_SETFL, O_NONBLOCK);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -52,10 +57,10 @@ namespace ix
|
||||
#ifdef __linux__
|
||||
::close(_eventfd);
|
||||
#else
|
||||
::close(_fildes[0]);
|
||||
::close(_fildes[1]);
|
||||
_fildes[0] = -1;
|
||||
_fildes[1] = -1;
|
||||
::close(_fildes[kPipeReadIndex]);
|
||||
::close(_fildes[kPipeWriteIndex]);
|
||||
_fildes[kPipeReadIndex] = -1;
|
||||
_fildes[kPipeWriteIndex] = -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -66,8 +71,7 @@ namespace ix
|
||||
#if defined(__linux__)
|
||||
fd = _eventfd;
|
||||
#else
|
||||
// File descriptor at index 1 in _fildes is the write end of the pipe
|
||||
fd = _fildes[1];
|
||||
fd = _fildes[kPipeWriteIndex];
|
||||
#endif
|
||||
|
||||
if (fd == -1) return false;
|
||||
@ -84,7 +88,7 @@ namespace ix
|
||||
#if defined(__linux__)
|
||||
fd = _eventfd;
|
||||
#else
|
||||
fd = _fildes[0];
|
||||
fd = _fildes[kPipeReadIndex];
|
||||
#endif
|
||||
uint64_t value = 0;
|
||||
::read(fd, &value, sizeof(value));
|
||||
@ -111,7 +115,7 @@ namespace ix
|
||||
#if defined(__linux__)
|
||||
return _eventfd;
|
||||
#else
|
||||
return _fildes[0];
|
||||
return _fildes[kPipeReadIndex];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ namespace ix
|
||||
// happens between a control thread and a background thread, which is
|
||||
// blocked on select.
|
||||
int _fildes[2];
|
||||
|
||||
// Used to identify the read/write idx
|
||||
static const int kPipeReadIndex;
|
||||
static const int kPipeWriteIndex;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ namespace ix
|
||||
{
|
||||
const int Socket::kDefaultPollNoTimeout = -1; // No poll timeout by default
|
||||
const int Socket::kDefaultPollTimeout = kDefaultPollNoTimeout;
|
||||
const uint8_t Socket::kSendRequest = 1;
|
||||
const uint8_t Socket::kCloseRequest = 2;
|
||||
const uint64_t Socket::kSendRequest = 1;
|
||||
const uint64_t Socket::kCloseRequest = 2;
|
||||
constexpr size_t Socket::kChunkSize;
|
||||
|
||||
Socket::Socket(int fd) :
|
||||
@ -86,7 +86,7 @@ namespace ix
|
||||
}
|
||||
else if (eventfd != -1 && FD_ISSET(eventfd, &rfds))
|
||||
{
|
||||
uint8_t value = _eventfd.read();
|
||||
uint64_t value = _eventfd.read();
|
||||
|
||||
if (value == kSendRequest)
|
||||
{
|
||||
|
@ -76,8 +76,8 @@ namespace ix
|
||||
static void cleanup(); // Required on Windows to cleanup WinSocket
|
||||
|
||||
// Used as special codes for pipe communication
|
||||
static const uint8_t kSendRequest;
|
||||
static const uint8_t kCloseRequest;
|
||||
static const uint64_t kSendRequest;
|
||||
static const uint64_t kCloseRequest;
|
||||
|
||||
protected:
|
||||
void closeSocket(int fd);
|
||||
|
Loading…
Reference in New Issue
Block a user