-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathring_option.go
74 lines (64 loc) · 1.62 KB
/
ring_option.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
// +build linux
package iouring
import (
"time"
"golang.org/x/sys/unix"
)
// RingOption is an option for configuring a Ring.
type RingOption func(*Ring) error
// WithDebug is used to print additional debug information.
func WithDebug() RingOption {
return func(r *Ring) error {
r.debug = true
return nil
}
}
// WithEventFd is used to create an eventfd and register it to the Ring.
// The event fd can be accessed using the EventFd method.
func WithEventFd(initval uint, flags int, async bool) RingOption {
return func(r *Ring) error {
fd, err := unix.Eventfd(initval, flags)
if err != nil {
return err
}
r.eventFd = fd
if async {
return RegisterEventFdAsync(r.fd, fd)
}
return RegisterEventFd(r.fd, fd)
}
}
// WithFileRegistry is used to register a FileRegistry with the Ring. The
// registery can be accessed with the FileRegistry method on the ring.
func WithFileRegistry() RingOption {
return func(r *Ring) error {
r.fileReg = NewFileRegistry(r.fd)
return nil
}
}
// WithID is used to set the starting id for the monotonically increasing ID
// method.
func WithID(id uint64) RingOption {
return func(r *Ring) error {
r.idx = &id
return nil
}
}
// WithEnterErrHandler is used to handle errors on ring enter.
func WithEnterErrHandler(f func(error)) RingOption {
return func(r *Ring) error {
r.enterErrHandler = f
return nil
}
}
// WithDeadline is used to configure the deadline for submitting IO.
func WithDeadline(d time.Duration) RingOption {
return func(r *Ring) error {
r.deadline = d
s := newRingSubmitter(r, d)
// This is an ugly hack....
go s.run()
r.submitter = s
return nil
}
}