kqueue_darwin.go - Overview
-
Overview This file implements the
IOMultiplexer
interface for Darwin-based systems usingkqueue
. It provides functionality to subscribe to events, poll for triggered events, and close the kqueue instance. -
Detailed Documentation
KQueue
type KQueue struct {
// fd stores the file descriptor of the kqueue instance
fd int
// kQEvents acts as a buffer for the events returned by the Kevent syscall
kQEvents []syscall.Kevent_t
// diceEvents stores the events after they are converted to the generic Event type
// and is returned to the caller
diceEvents []Event
}
Purpose:
Represents the kqueue implementation of the IOMultiplexer
interface. It holds the file descriptor, native kqueue events, and Dice events.
Fields:
fd
: The file descriptor of the kqueue instance (int).kQEvents
: A slice ofsyscall.Kevent_t
to store events returned by theKevent
syscall.diceEvents
: A slice ofEvent
to store converted events.
New
func New() (*KQueue, error)
Purpose:
Creates a new KQueue
instance.
Returns:
*KQueue
: A pointer to the newKQueue
instance.error
: An error if the kqueue creation fails or ifconfig.Config.MaxClients
is invalid.
Subscribe
func (kq *KQueue) Subscribe(event Event) error
Purpose:
Subscribes to the given event.
Parameters:
event
: TheEvent
to subscribe to.
Returns:
error
: An error if the subscription fails.
Poll
func (kq *KQueue) Poll(timeout time.Duration) ([]Event, error)
Purpose:
Polls for all the subscribed events simultaneously and returns the events that were triggered. It blocks until at least one event is triggered or the timeout is reached.
Parameters:
timeout
: The timeout duration.
Returns:
[]Event
: A slice of triggeredEvent
s.error
: An error if the polling fails.
Close
func (kq *KQueue) Close() error
Purpose:
Closes the KQueue
instance.
Returns:
error
: An error if closing the file descriptor fails.
-
Code Examples N/A
-
Getting Started Relevance YES