Waiting for Something (Screenplay)¶
read()
Not Implemented¶
Use
strace
to show whatcat
does⟶
ENOSYS
, likely (read()
not implemented)
Implementing read()
Naively¶
read()
, nonblocking version (see File Operations on Character Devices)implement same functionality as
MY_GET_ONE_EVENT
size 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 ⟶
cat
terminatesEAGAIN
is normally returned in such casesbut file descriptor has to be marked non-blocking, by convention
Write userspace test program
test-read-events.c
Reads until EOF or error
⟶ return
-EAGAIN
if 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
/nonblocking
Test the wait