diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-08-30 22:56:47 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-08-30 22:56:47 +0100 |
| commit | 8b02bb749dece7690f4919372d19cd40907b91b1 (patch) | |
| tree | 98e636beca5e83f909d3872586f383e95095851b /src/file.cc | |
| parent | d0a29511d28f1481622ac9bb3a6ebfa9f8988c2b (diff) | |
Add a fd_readable(int fd) helper function
Use it instead of direct calls to select scatered around the code
base.
Diffstat (limited to 'src/file.cc')
| -rw-r--r-- | src/file.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/file.cc b/src/file.cc index f8928243..1bd0406e 100644 --- a/src/file.cc +++ b/src/file.cc @@ -13,6 +13,7 @@ #include <unistd.h> #include <dirent.h> #include <stdlib.h> +#include <sys/select.h> #if defined(__FreeBSD__) #include <sys/sysctl.h> @@ -123,6 +124,16 @@ String compact_path(StringView filename) return filename.str(); } +bool fd_readable(int fd) +{ + fd_set rfds; + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + + timeval tv{0,0}; + return select(fd+1, &rfds, nullptr, nullptr, &tv) == 1; +} + String read_fd(int fd, bool text) { String content; |
