]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll, internal/syscall/unix, net: enable writev on illumos
authorTobias Klauser <tklauser@distanz.ch>
Mon, 14 Sep 2020 09:06:39 +0000 (11:06 +0200)
committerTobias Klauser <tobias.klauser@gmail.com>
Tue, 15 Sep 2020 05:08:53 +0000 (05:08 +0000)
Illumos supports iovec read/write. Add the writev wrapper to
internal/syscall/unix and use it to implement internal/poll.writev for
net.(*netFD).writeBuffers.

Change-Id: Ie256c2f96aba8e61fb21991788789a049425f792
Reviewed-on: https://go-review.googlesource.com/c/go/+/254638
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Tobias Klauser <tobias.klauser@gmail.com>

src/internal/poll/fd_writev_illumos.go [new file with mode: 0644]
src/internal/poll/iovec_illumos.go [new file with mode: 0644]
src/internal/poll/iovec_unix.go [new file with mode: 0644]
src/internal/poll/writev.go
src/internal/syscall/unix/writev_illumos.go [new file with mode: 0644]
src/net/writev_test.go
src/net/writev_unix.go

diff --git a/src/internal/poll/fd_writev_illumos.go b/src/internal/poll/fd_writev_illumos.go
new file mode 100644 (file)
index 0000000..1fa47ab
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2020 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 illumos
+
+package poll
+
+import (
+       "internal/syscall/unix"
+       "syscall"
+)
+
+func writev(fd int, iovecs []syscall.Iovec) (uintptr, error) {
+       return unix.Writev(fd, iovecs)
+}
diff --git a/src/internal/poll/iovec_illumos.go b/src/internal/poll/iovec_illumos.go
new file mode 100644 (file)
index 0000000..0570674
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2020 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 illumos
+
+package poll
+
+import (
+       "syscall"
+       "unsafe"
+)
+
+func newIovecWithBase(base *byte) syscall.Iovec {
+       return syscall.Iovec{Base: (*int8)(unsafe.Pointer(base))}
+}
diff --git a/src/internal/poll/iovec_unix.go b/src/internal/poll/iovec_unix.go
new file mode 100644 (file)
index 0000000..6f98947
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2020 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 darwin dragonfly freebsd linux netbsd openbsd
+
+package poll
+
+import "syscall"
+
+func newIovecWithBase(base *byte) syscall.Iovec {
+       return syscall.Iovec{Base: base}
+}
index 305e2fd20942deda33b47fc99e97409cd558c0dc..0123fc33de720b228c1a49ce5482ad7fecfb96f8 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd illumos linux netbsd openbsd
 
 package poll
 
@@ -38,7 +38,7 @@ func (fd *FD) Writev(v *[][]byte) (int64, error) {
                        if len(chunk) == 0 {
                                continue
                        }
-                       iovecs = append(iovecs, syscall.Iovec{Base: &chunk[0]})
+                       iovecs = append(iovecs, newIovecWithBase(&chunk[0]))
                        if fd.IsStream && len(chunk) > 1<<30 {
                                iovecs[len(iovecs)-1].SetLen(1 << 30)
                                break // continue chunk on next writev
diff --git a/src/internal/syscall/unix/writev_illumos.go b/src/internal/syscall/unix/writev_illumos.go
new file mode 100644 (file)
index 0000000..eb7973d
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright 2020 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 illumos
+
+package unix
+
+import (
+       "syscall"
+       "unsafe"
+)
+
+//go:cgo_import_dynamic libc_writev writev "libc.so"
+
+//go:linkname procwritev libc_writev
+
+var procwritev uintptr
+
+func Writev(fd int, iovs []syscall.Iovec) (uintptr, error) {
+       var p *syscall.Iovec
+       if len(iovs) > 0 {
+               p = &iovs[0]
+       }
+       n, _, errno := syscall6(uintptr(unsafe.Pointer(&procwritev)), 3, uintptr(fd), uintptr(unsafe.Pointer(p)), uintptr(len(iovs)), 0, 0, 0)
+       if errno != 0 {
+               return 0, errno
+       }
+       return n, nil
+}
index c43be844189f7af7254b4e68409372139cade1e9..d6dce3cc6954a83ef25089ede626bf86f4ed3cdf 100644 (file)
@@ -154,7 +154,7 @@ func testBuffer_writeTo(t *testing.T, chunks int, useCopy bool) {
 
                var wantSum int
                switch runtime.GOOS {
-               case "android", "darwin", "dragonfly", "freebsd", "linux", "netbsd", "openbsd":
+               case "android", "darwin", "dragonfly", "freebsd", "illumos", "linux", "netbsd", "openbsd":
                        var wantMinCalls int
                        wantSum = want.Len()
                        v := chunks
index bf0fbf8a13611fedf6f72961fd7d9d36fa6c9634..8b20f42b34de630c36c1f88c53ee1845cbd84bbb 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin dragonfly freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd illumos linux netbsd openbsd
 
 package net