Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KqueueConsole ¶
KqueueConsole acts like a console but registers its file descriptor with an kqueue fd and uses kqueue API to perform I/O.
func (*KqueueConsole) Read ¶
func (ec *KqueueConsole) Read(p []byte) (n int, err error)
Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered.
If the console's read returns EAGAIN or EIO, we assume that it's a temporary error because the other side went away and wait for the signal generated by kqueue event to continue.
func (*KqueueConsole) Shutdown ¶
func (ec *KqueueConsole) Shutdown(close func(int) error) error
Shutdown closes the file descriptor and signals call waiters for this fd. It accepts a callback which will be called with the console's fd. The callback typically will be used to do further cleanup such as unregister the console's fd from the kqueue interface. User should call Shutdown and wait for all I/O operation to be finished before closing the console.
func (*KqueueConsole) Write ¶
func (ec *KqueueConsole) Write(p []byte) (n int, err error)
Writes len(p) bytes from p to the console. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early.
If writes to the console returns EAGAIN or EIO, we assume that it's a temporary error because the other side went away and wait for the signal generated by kqueue event to continue.
type Kqueuer ¶
type Kqueuer struct {
// contains filtered or unexported fields
}
Kqueuer manages multiple kqueue consoles using edge-triggered kqueue api so we dont have to deal with repeated wake-up of KQUEUE. For more details, see: - https://github.com/systemd/systemd/pull/4262 - https://github.com/moby/moby/issues/27202
Example usage of Kqueuer and KqueueConsole can be as follow:
Kqueuer, _ := NewKqueuer()
KqueueConsole, _ := Kqueuer.Add(console)
go Kqueuer.Wait()
var (
b bytes.Buffer
wg sync.WaitGroup
)
wg.Add(1)
go func() {
io.Copy(&b, KqueueConsole)
wg.Done()
}()
// perform I/O on the console
KqueueConsole.Shutdown(Kqueuer.CloseConsole)
wg.Wait()
KqueueConsole.Close()
func NewKqueuer ¶
NewKqueuer returns an instance of Kqueuer with a valid kqueue fd.
func (*Kqueuer) Add ¶
func (e *Kqueuer) Add(console console.Console) (*KqueueConsole, error)
Add creates an epoll console based on the provided console. The console will be registered with kqueue (i.e. using edge-triggered notification) and its file descriptor will be set to non-blocking mode. After this, user should use the return console to perform I/O.
func (*Kqueuer) CloseConsole ¶
CloseConsole unregisters the console's file descriptor from kqueue interface