File tree Expand file tree Collapse file tree 1 file changed +36
-2
lines changed Expand file tree Collapse file tree 1 file changed +36
-2
lines changed Original file line number Diff line number Diff line change 31
31
#if __has_include (< sys /event .h > )
32
32
#define HAS_SYS_EVENT_H 1
33
33
#include <sys/event.h>
34
+ #else
35
+ #include <sys/epoll.h>
36
+ #include <sys/eventfd.h>
34
37
#endif
35
38
#include <assert.h>
36
39
@@ -65,8 +68,39 @@ dispatch_test_check_evfilt_read_for_fd(int fd)
65
68
close (kq );
66
69
return r > 0 ;
67
70
#else
68
- // TODO: Need to write a real check for epoll-backend here
69
- return true;
71
+ struct stat sb ;
72
+ struct epoll_event ev , events [1 ];
73
+ int epollfd , numReady , r ;
74
+ int dummyfd = -1 ;
75
+
76
+ if (fstat (fd , & sb ) < 0 ) {
77
+ return false;
78
+ }
79
+
80
+ epollfd = epoll_create1 (0 );
81
+ assert (epollfd != -1 );
82
+
83
+ if (S_ISREG (sb .st_mode )) {
84
+ dummyfd = eventfd (1 , EFD_CLOEXEC | EFD_NONBLOCK ); // dummy eventfd that is always readable
85
+ fd = dummyfd ;
86
+ }
87
+
88
+ ev .events = EPOLLIN ;
89
+ ev .data .fd = fd ;
90
+ r = epoll_ctl (epollfd , EPOLL_CTL_ADD , fd , & ev );
91
+ assert (r != -1 );
92
+
93
+ numReady = epoll_wait (epollfd , events , 1 , 0 );
94
+ assert (numReady != -1 );
95
+
96
+ r = close (epollfd );
97
+ assert (r != -1 );
98
+ if (dummyfd != -1 ) {
99
+ r = close (dummyfd );
100
+ assert (r != -1 );
101
+ }
102
+
103
+ return numReady > 0 ;
70
104
#endif
71
105
}
72
106
You can’t perform that action at this time.
0 commit comments