• David du Colombier's avatar
    net: implement asynchonous cancelable I/O on Plan 9 · adb384ad
    David du Colombier authored
    This change is an experimental implementation of asynchronous
    cancelable I/O operations on Plan 9, which are required to
    implement deadlines.
    
    There are no asynchronous syscalls on Plan 9. I/O operations
    are performed with blocking pread and pwrite syscalls.
    
    Implementing deadlines in Go requires a way to interrupt
    I/O operations.
    
    It is possible to interrupt reads and writes on a TCP connection
    by forcing the closure of the TCP connection. This approach
    has been used successfully in CL 31390.
    
    However, we can't implement deadlines with this method, since
    we require to be able to reuse the connection after the timeout.
    
    On Plan 9, I/O operations are interrupted when the process
    receives a note. We can rely on this behavior to implement
    a more generic approach.
    
    When doing an I/O operation (read or write), we start the I/O in
    its own process, then wait for the result asynchronously. The
    process is able to handle the "hangup" note. When receiving the
    "hangup" note, the currently running I/O operation is canceled
    and the process returns.
    
    This way, deadlines can be implemented by sending an "hangup"
    note to the process running the blocking I/O operation, after
    the expiration of a timer.
    
    Fixes #11932.
    Fixes #17498.
    
    Change-Id: I414f72c7a9a4f9b8f9c09ed3b6c269f899d9b430
    Reviewed-on: https://go-review.googlesource.com/31521Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    adb384ad
os_plan9.go 9.18 KB