utils/filedescriptor: add helper to query if the fd is readable
This commit is contained in:
parent
7c24242300
commit
a64e43e6b1
2 changed files with 13 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
#include "filedescriptor.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/poll.h>
|
||||
#include <unistd.h>
|
||||
#include <utility>
|
||||
|
||||
|
@ -72,4 +73,14 @@ FileDescriptor FileDescriptor::duplicate() const
|
|||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
bool FileDescriptor::isReadable() const
|
||||
{
|
||||
pollfd fd = {
|
||||
.fd = m_fd,
|
||||
.events = POLLIN,
|
||||
.revents = 0,
|
||||
};
|
||||
return poll(&fd, 1, 0) && (fd.revents & (POLLIN | POLLNVAL)) != 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ public:
|
|||
void reset();
|
||||
FileDescriptor duplicate() const;
|
||||
|
||||
bool isReadable() const;
|
||||
|
||||
private:
|
||||
int m_fd = -1;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue