Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotAConsole = errors.New("provided file is not a console")
Functions ¶
func ClearONLCR ¶
ClearONLCR sets the necessary tty_ioctl(4)s to ensure that a pty pair created by us acts normally. In particular, a not-very-well-known default of Linux unix98 ptys is that they have +onlcr by default. While this isn't a problem for terminal emulators, because we relay data from the terminal we also relay that funky line discipline.
Types ¶
type Console ¶
type Console interface { io.Reader io.Writer io.Closer // Resize resizes the console to the provided window size Resize(WinSize) error // ResizeFrom resizes the calling console to the size of the // provided console ResizeFrom(Console) error // SetRaw sets the console in raw mode SetRaw() error // DisableEcho disables echo on the console DisableEcho() error // Reset restores the console to its orignal state Reset() error // Size returns the window size of the console Size() (WinSize, error) // Fd returns the console's file descriptor Fd() uintptr // Name returns the console's file name Name() string }
func ConsoleFromFile ¶
ConsoleFromFile returns a console using the provided file
type EpollConsole ¶
type EpollConsole struct { Console // contains filtered or unexported fields }
EpollConsole acts like a console but register its file descriptor with a epoll fd and uses epoll API to perform I/O.
func (*EpollConsole) Read ¶
func (ec *EpollConsole) 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 assumes that its a temporary error because the other side went away and wait for the signal generated by epoll event to continue.
func (*EpollConsole) Shutdown ¶
func (ec *EpollConsole) Shutdown(close func(int) error) error
Close closed the file descriptor and signal 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 epoll interface. User should call Shutdown and wait for all I/O operation to be finished before closing the console.
func (*EpollConsole) Write ¶
func (ec *EpollConsole) 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 assumes that its a temporary error because the other side went away and wait for the signal generated by epoll event to continue.
type Epoller ¶
type Epoller struct {
// contains filtered or unexported fields
}
Epoller manages multiple epoll consoles using edge-triggered epoll api so we dont have to deal with repeated wake-up of EPOLLER or EPOLLHUP. For more details, see: - https://github.com/systemd/systemd/pull/4262 - https://github.com/moby/moby/issues/27202
Example usage of Epoller and EpollConsole can be as follow:
epoller, _ := NewEpoller() epollConsole, _ := epoller.Add(console) go epoller.Wait() var ( b bytes.Buffer wg sync.WaitGroup ) wg.Add(1) go func() { io.Copy(&b, epollConsole) wg.Done() }() // perform I/O on the console epollConsole.Shutdown(epoller.CloseConsole) wg.Wait() epollConsole.Close()
func NewEpoller ¶
NewEpoller returns an instance of epoller with a valid epoll fd.
func (*Epoller) Add ¶
func (e *Epoller) Add(console Console) (*EpollConsole, error)
Add creates a epoll console based on the provided console. The console will be registered with EPOLLET (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 (*Epoller) CloseConsole ¶
Close unregister the console's file descriptor from epoll interface