NAME
Hypersonic::WebSocket::Handler - XS WebSocket connection management (OO)
SYNOPSIS
use Hypersonic::WebSocket::Handler;
use XS::JIT::Builder;
use XS::JIT;
my $builder = XS::JIT::Builder->new;
Hypersonic::WebSocket::Handler->generate_c_code($builder, {
max_connections => 65536,
});
# Compile XS functions
XS::JIT->compile(
code => $builder->code,
name => 'Hypersonic::WebSocket::Handler',
functions => Hypersonic::WebSocket::Handler->get_xs_functions,
);
# Object-oriented API
my $conn = Hypersonic::WebSocket::Handler->new($fd, $ws);
$conn->send('Hello!');
$conn->send_binary($data);
$conn->close;
# Class methods
my $count = Hypersonic::WebSocket::Handler->count;
Hypersonic::WebSocket::Handler->broadcast('Message to all');
DESCRIPTION
Generates XS functions for WebSocket connection management via XS::JIT::Builder. All hot paths (connection registry, frame handling, broadcast) are in C.
Handler objects are blessed scalars containing the fd, created entirely in XS.
INSTANCE METHODS (XS)
- new($fd, $ws) - Create/register connection, returns blessed object
- fd() - Get the file descriptor
- state() - Get connection state (0=init, 1=open, 2=closing, 3=closed)
- is_open() - Check if connection is open
- ws() - Get the WebSocket object
- send($message) - Send text frame
- send_binary($data) - Send binary frame
- handle_data($data) - Process incoming frame, returns {opcode, data}
- close([$code]) - Close connection with optional code