forked from lesismal/nbio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwritev_linux.go
More file actions
36 lines (31 loc) · 723 Bytes
/
writev_linux.go
File metadata and controls
36 lines (31 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2020 lesismal. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
//go:build linux
// +build linux
package nbio
import (
"syscall"
"unsafe"
)
//go:norace
func writev(c *Conn, bs [][]byte) (int, error) {
iovs := make([]syscall.Iovec, len(bs))[0:0]
for _, b := range bs {
if len(b) > 0 {
v := syscall.Iovec{}
v.SetLen(len(b))
v.Base = &b[0]
iovs = append(iovs, v)
}
}
if len(iovs) > 0 {
var _p0 = unsafe.Pointer(&iovs[0])
var n, _, err = syscall.Syscall(syscall.SYS_WRITEV, uintptr(c.fd), uintptr(_p0), uintptr(len(iovs)))
if err == 0 {
return int(n), nil
}
return int(n), err
}
return 0, nil
}