github.com/iceber/iouring-go@v0.0.0-20230403020409-002cfd2e2a90/user_data.go (about) 1 // +build linux 2 3 package iouring 4 5 import ( 6 "unsafe" 7 ) 8 9 type UserData struct { 10 id uint64 11 12 resulter chan<- Result 13 opcode uint8 14 15 holds []interface{} 16 request *request 17 } 18 19 func (data *UserData) SetResultResolver(resolver ResultResolver) { 20 data.request.resolver = resolver 21 } 22 23 func (data *UserData) SetRequestInfo(info interface{}) { 24 data.request.requestInfo = info 25 } 26 27 func (data *UserData) SetRequestCallback(callback RequestCallback) { 28 data.request.callback = callback 29 } 30 31 func (data *UserData) SetRequestBuffer(b0, b1 []byte) { 32 data.request.b0, data.request.b1 = b0, b1 33 } 34 35 func (data *UserData) SetRequestBuffers(bs [][]byte) { 36 data.request.bs = bs 37 } 38 39 func (data *UserData) Hold(vars ...interface{}) { 40 data.holds = append(data.holds, vars) 41 } 42 43 func (data *UserData) hold(vars ...interface{}) { 44 data.holds = vars 45 } 46 47 func (data *UserData) setOpcode(opcode uint8) { 48 data.opcode = opcode 49 data.request.opcode = opcode 50 } 51 52 // TODO(iceber): use sync.Poll 53 func makeUserData(iour *IOURing, ch chan<- Result) *UserData { 54 userData := &UserData{ 55 resulter: ch, 56 request: &request{iour: iour, done: make(chan struct{})}, 57 } 58 59 userData.id = uint64(uintptr(unsafe.Pointer(userData))) 60 userData.request.id = userData.id 61 return userData 62 }