forked from Iceber/iouring-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_data.go
62 lines (47 loc) · 1.21 KB
/
user_data.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
// +build linux
package iouring
import (
"unsafe"
)
type UserData struct {
id uint64
resulter chan<- Result
opcode uint8
holds []interface{}
request *request
}
func (data *UserData) SetResultResolver(resolver ResultResolver) {
data.request.resolver = resolver
}
func (data *UserData) SetRequestInfo(info interface{}) {
data.request.requestInfo = info
}
func (data *UserData) SetRequestCallback(callback RequestCallback) {
data.request.callback = callback
}
func (data *UserData) SetRequestBuffer(b0, b1 []byte) {
data.request.b0, data.request.b1 = b0, b1
}
func (data *UserData) SetRequestBuffers(bs [][]byte) {
data.request.bs = bs
}
func (data *UserData) Hold(vars ...interface{}) {
data.holds = append(data.holds, vars)
}
func (data *UserData) hold(vars ...interface{}) {
data.holds = vars
}
func (data *UserData) setOpcode(opcode uint8) {
data.opcode = opcode
data.request.opcode = opcode
}
// TODO(iceber): use sync.Poll
func makeUserData(iour *IOURing, ch chan<- Result) *UserData {
userData := &UserData{
resulter: ch,
request: &request{iour: iour, done: make(chan struct{})},
}
userData.id = uint64(uintptr(unsafe.Pointer(userData)))
userData.request.id = userData.id
return userData
}