Skip to main content

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 the epoll instance.
    • ePollEvents: Acts as a buffer for events returned by the EpollWait syscall.
    • diceEvents: Stores events after conversion to the generic Event type.

New

func New() (*Epoll, error)
  • Purpose: Creates a new Epoll instance.
  • Returns:
    • *Epoll: A pointer to the new Epoll instance.
    • error: An error if the creation fails (e.g., due to invalid MaxClients configuration or epoll 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 to EpollCtl 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 to EpollWait failure).

Close

func (ep *Epoll) Close() error
  • Purpose: Closes the Epoll instance.
  • Returns:
    • error: An error if closing fails (e.g., due to syscall.Close failure).

Getting Started Relevance