Waiting for Something (Screenplay)#
read() Not Implemented#
Use
straceto show whatcatdoes⟶
ENOSYS, likely (read()not implemented)
Implementing read() Naively#
read(), nonblocking version (see File Operations on Character Devices)implement same functionality as
MY_GET_ONE_EVENTsize check of buffer ⟶
-EINVAL(just likeread()on a timerfdGet one event, and copy that to the userspace buffer supplied by read.
Return 0 if nothing’s there
Discussion: What If Nothing’s There?#
0 is usually end of file ⟶
catterminatesEAGAINis normally returned in such casesbut file descriptor has to be marked non-blocking, by convention
Write userspace test program
test-read-events.cReads until EOF or error
⟶ return
-EAGAINif nothing’s thereCheck how test program behaves
Implementing O_NONBLOCK#
Check blocking-status of file descriptor
filp->f_flags & O_NONBLOCK
If non-blocking, enter the code that we have now
Else ⟶ wait, hm
Add parameter to
test-read-events.c:blocking/nonblockingTest the wait