diff --git a/src/utils/filedescriptor.cpp b/src/utils/filedescriptor.cpp index 768f1a22d1..8824632d5d 100644 --- a/src/utils/filedescriptor.cpp +++ b/src/utils/filedescriptor.cpp @@ -9,6 +9,7 @@ #include "filedescriptor.h" #include +#include #include #include @@ -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; +} } diff --git a/src/utils/filedescriptor.h b/src/utils/filedescriptor.h index b7e694a8ec..90b9ee2223 100644 --- a/src/utils/filedescriptor.h +++ b/src/utils/filedescriptor.h @@ -28,6 +28,8 @@ public: void reset(); FileDescriptor duplicate() const; + bool isReadable() const; + private: int m_fd = -1; };