diff options
author | David du Colombier <0intro@gmail.com> | 2016-11-11 20:49:11 +0100 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-11-12 05:44:36 +0000 |
commit | adb384ad2cfbd742fb106b7ec2a65d4ad844c35e (patch) | |
tree | 4e0f7ff6c497cafae18822a2079fdb384b8b6996 /src/runtime/net_plan9.go | |
parent | 456f2f5cb8c2e06e7faba6ba298ffb65c7a19397 (diff) | |
download | go-adb384ad2cfbd742fb106b7ec2a65d4ad844c35e.tar.gz go-adb384ad2cfbd742fb106b7ec2a65d4ad844c35e.zip |
net: implement asynchonous cancelable I/O on Plan 9
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/31521
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/net_plan9.go')
-rw-r--r-- | src/runtime/net_plan9.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/runtime/net_plan9.go b/src/runtime/net_plan9.go new file mode 100644 index 0000000000..10fd089aea --- /dev/null +++ b/src/runtime/net_plan9.go @@ -0,0 +1,29 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package runtime + +import ( + _ "unsafe" +) + +//go:linkname runtime_ignoreHangup net.runtime_ignoreHangup +func runtime_ignoreHangup() { + getg().m.ignoreHangup = true +} + +//go:linkname runtime_unignoreHangup net.runtime_unignoreHangup +func runtime_unignoreHangup(sig string) { + getg().m.ignoreHangup = false +} + +func ignoredNote(note *byte) bool { + if note == nil { + return false + } + if gostringnocopy(note) != "hangup" { + return false + } + return getg().m.ignoreHangup +} |