epoll_linux.go
epoll_linux.go - Overview
This file implements the IOMultiplexer
interface for Linux systems using epoll
. It provides functionality to create, subscribe to, poll for, and close an epoll
instance.
Detailed Documentation
Epoll
type Epoll struct {
fd int
ePollEvents []syscall.EpollEvent
diceEvents []Event
}
- Purpose: Represents an
epoll
instance for Linux-based systems.fd
: Stores the file descriptor of theepoll
instance.ePollEvents
: Acts as a buffer for events returned by theEpollWait
syscall.diceEvents
: Stores events after conversion to the genericEvent
type.
New
func New() (*Epoll, error)
- Purpose: Creates a new
Epoll
instance. - Returns:
*Epoll
: A pointer to the newEpoll
instance.error
: An error if the creation fails (e.g., due to invalidMaxClients
configuration orepoll
creation failure).
Subscribe
func (ep *Epoll) Subscribe(event Event) error
- Purpose: Subscribes to the given event.
- Parameters:
event
(Event
): The event to subscribe to.
- Returns:
error
: An error if the subscription fails (e.g., due toEpollCtl
failure).
Poll
func (ep *Epoll) Poll(timeout time.Duration) ([]Event, error)
- Purpose: Polls for subscribed events. It blocks until at least one event is triggered or the timeout is reached.
- Parameters:
timeout
(time.Duration
): The maximum time to wait for events.
- Returns:
[]Event
: A slice of triggered events.error
: An error if polling fails (e.g., due toEpollWait
failure).
Close
func (ep *Epoll) Close() error
- Purpose: Closes the
Epoll
instance. - Returns:
error
: An error if closing fails (e.g., due tosyscall.Close
failure).