forked from phuslu/log
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
async_linux.go
52 lines (48 loc) · 1023 Bytes
/
async_linux.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//go:build linux && (arm64 || amd64 || mips64 || mips64le || ppc64 || ppc64le || riscv64 || s390x || loong64)
package log
import (
"syscall"
)
func (w *AsyncWriter) writever() {
// https://github.com/golang/go/blob/master/src/internal/poll/writev.go#L29
const IOV_MAX = 1024
var es [IOV_MAX]*Entry
var iovs [IOV_MAX]syscall.Iovec
var err error
var quit bool
for !quit {
// wait an item from channel
es[0] = <-w.ch
if es[0] == nil {
break
}
iovs[0].Base = &es[0].buf[0]
iovs[0].Len = uint64(len(es[0].buf))
// drain the channel
length := len(w.ch)
if length > IOV_MAX-1 {
length = IOV_MAX - 1
}
n := 1
for n <= length {
es[n] = <-w.ch
if es[n] == nil {
quit = true
break
}
iovs[n].Base = &es[n].buf[0]
iovs[n].Len = uint64(len(es[n].buf))
n++
}
// writev
_, err = w.file.WriteV(iovs[:n])
// quit = err != nil
// return entries to pool
for i := 0; i < n; i++ {
epool.Put(es[i])
es[i] = nil
iovs[i].Base = nil
}
}
w.chClose <- err
}