-
Notifications
You must be signed in to change notification settings - Fork 1
/
async_unix_notbsd.go
96 lines (79 loc) · 1.65 KB
/
async_unix_notbsd.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// +build linux android
package asyncfs
import (
"fmt"
"os"
"syscall"
)
func openAsync(path string, flag int, perm os.FileMode) (*os.File, error) {
if c.asyncMode == asyncAio {
flag |= syscall.O_DIRECT
}
return os.OpenFile(path, flag, perm)
}
func (f *File) writeAsync(data []uint8) (int, error) {
if c.busy() {
return 0, ErrCtxBusy
}
f.lastSyncSeek = true
f.mtx.Lock()
defer f.mtx.Unlock()
var err error
switch c.asyncMode {
case asyncIoUring:
_, err = f.asyncWriteIoUring(data)
case asyncAio:
_, err = f.asyncWriteAio(data)
default:
return 0, fmt.Errorf("unknown async mode '%v'", c.asyncMode)
}
if err != nil {
return 0, err
}
f.lastAsyncOpState.complete = false
f.lastAsyncOpState.lastOp = OpWrite
return 0, nil
}
func (f *File) readAsync(data []uint8) (int, error) {
if c.busy() {
return 0, ErrCtxBusy
}
f.mtx.Lock()
defer f.mtx.Unlock()
f.lastSyncSeek = true
var err error
switch c.asyncMode {
case asyncIoUring:
_, err = f.asyncReadIoUring(data)
case asyncAio:
_, err = f.asyncReadAio(data)
default:
return 0, fmt.Errorf("unknown async mode '%v'", c.asyncMode)
}
if err != nil {
return 0, err
}
f.lastAsyncOpState.complete = false
f.lastAsyncOpState.lastOp = OpRead
return 0, nil
}
func (f *File) fillOpState() error {
var err error
switch c.asyncMode {
case asyncIoUring:
fillStatesIoUring(c)
case asyncAio:
err = fillStatesAio(c)
default:
err = fmt.Errorf("unknown async mode '%v'", c.asyncMode)
}
return err
}
func (f *File) close() error {
switch c.asyncMode {
case asyncIoUring, asyncAio:
return f.fd.Close()
default:
return fmt.Errorf("unknown async mode '%v'", c.asyncMode)
}
}