NAME

Hypersonic::Event::Poll - poll() event backend (portable fallback)

SYNOPSIS

use Hypersonic::Event;

my $backend = Hypersonic::Event->backend('poll');
# $backend is 'Hypersonic::Event::Poll'

DESCRIPTION

Hypersonic::Event::Poll is the poll()-based event backend for Hypersonic. It provides a portable fallback that works on all POSIX systems.

poll() has O(n) complexity where n is the number of file descriptors being watched. For servers with more than 1000 concurrent connections, prefer epoll (Linux) or kqueue (BSD/macOS).

METHODS

name

my $name = Hypersonic::Event::Poll->name;  # 'poll'

Returns the backend name.

available

if (Hypersonic::Event::Poll->available) { ... }

Returns true if this backend is available. poll() is available on all POSIX systems (Linux, macOS, BSD, Solaris, etc.) but not on Windows.

includes

Returns the C #include directives needed for poll.

defines

Returns the C #define directives for poll configuration.

event_struct

my $struct = Hypersonic::Event::Poll->event_struct;  # 'pollfd'

Returns the C struct name used for the events array.

gen_create($builder, $listen_fd_var)

Generates C code to initialize the pollfd array and add the listen socket.

gen_add($builder, $loop_var, $fd_var)

Generates C code to add a file descriptor to the pollfd array.

gen_del($builder, $loop_var, $fd_var)

Generates C code to remove a file descriptor from the pollfd array.

gen_wait($builder, $loop_var, $events_var, $count_var, $timeout_var)

Generates C code to wait for events using poll().

gen_get_fd($builder, $events_var, $index_var, $fd_var)

Generates C code to extract the file descriptor from a pollfd entry, skipping entries without events.

PERFORMANCE

poll() scans all file descriptors on each call, making it O(n) where n is the number of watched descriptors. This is slower than epoll/kqueue for large numbers of connections but is perfectly adequate for:

  • Development and testing

  • Low-concurrency servers (< 1000 connections)

  • Systems without epoll/kqueue support

AVAILABILITY

All POSIX systems: Linux, macOS, BSD, Solaris, AIX, HP-UX, etc. Not available on Windows (use Hypersonic::Event::Select instead).

SEE ALSO

Hypersonic::Event, Hypersonic::Event::Role, Hypersonic::Event::Epoll, Hypersonic::Event::Kqueue, Hypersonic::Event::Select

AUTHOR

LNATION <email@lnation.org>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.