NAME

Hypersonic::Socket - Low-level JIT-compiled socket functions for Hypersonic

SYNOPSIS

use Hypersonic::Socket;

my $listen_fd = Hypersonic::Socket::create_listen_socket(8080);
my $loop_fd   = Hypersonic::Socket::create_event_loop($listen_fd);

while (1) {
    my $events = Hypersonic::Socket::ev_poll($loop_fd, 1000);
    for my $event (@$events) {
        my ($fd, $flags) = @$event;
        # Handle event...
    }
}

DESCRIPTION

This module provides low-level XS functions for Hypersonic, compiled at runtime via XS::JIT. Platform-specific C code (kqueue on macOS/BSD, epoll on Linux) is generated and compiled on first use.

Note: These are XS functions, not Perl custom ops.

FUNCTIONS

create_listen_socket($port)

Create a non-blocking listening socket on the given port.

create_event_loop($listen_fd)

Create an epoll (Linux) or kqueue (macOS/BSD) event loop.

event_add($loop_fd, $fd)

Add a file descriptor to the event loop.

event_del($loop_fd, $fd)

Remove a file descriptor from the event loop.

ev_poll($loop_fd, $timeout_ms)

Wait for events. Returns an arrayref of [$fd, $flags] pairs.

http_accept($listen_fd)

Accept a new connection. Returns client fd or -1.

http_recv($fd)

Receive and parse an HTTP request. Returns [method, path, body, keep_alive, fd].

http_send($fd, $body, $content_type)

Send an HTTP response with the given body.

http_send_404($fd)

Send a 404 Not Found response.