aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/nbpipe_pipe2.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-04-03 16:31:13 -0700
committerIan Lance Taylor <iant@golang.org>2019-10-20 21:15:55 +0000
commit3b0aa546d289390027ee1bf1a5e41f37f6131fa7 (patch)
tree631fafe6c7e524f3c27b5c58581bad68b0334390 /src/runtime/nbpipe_pipe2.go
parent504fce98ba3052135ec1f9564e06819f42cdbc86 (diff)
downloadgo-3b0aa546d289390027ee1bf1a5e41f37f6131fa7.tar.gz
go-3b0aa546d289390027ee1bf1a5e41f37f6131fa7.zip
runtime: define nonblockingPipe
This requires defining pipe, pipe2, and setNonblock for various platforms. The new function is currently only used on AIX. It will be used by later CLs in this series. Updates #27707 Change-Id: Id2f987b66b4c66a3ef40c22484ff1d14f58e9b31 Reviewed-on: https://go-review.googlesource.com/c/go/+/171822 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/nbpipe_pipe2.go')
-rw-r--r--src/runtime/nbpipe_pipe2.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/runtime/nbpipe_pipe2.go b/src/runtime/nbpipe_pipe2.go
new file mode 100644
index 0000000000..f4c862cbff
--- /dev/null
+++ b/src/runtime/nbpipe_pipe2.go
@@ -0,0 +1,25 @@
+// Copyright 2019 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.
+
+// +build freebsd linux netbsd openbsd
+
+package runtime
+
+func pipe() (r, w int32, errno int32)
+func pipe2(flags int32) (r, w int32, errno int32)
+
+func nonblockingPipe() (r, w int32, errno int32) {
+ r, w, errno = pipe2(_O_NONBLOCK | _O_CLOEXEC)
+ if errno == -_ENOSYS {
+ r, w, errno = pipe()
+ if errno != 0 {
+ return -1, -1, errno
+ }
+ closeonexec(r)
+ setNonblock(r)
+ closeonexec(w)
+ setNonblock(w)
+ }
+ return r, w, errno
+}