EV-Websockets

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

        - Fixed conn->wsi not set during on_connect for adopted connections
        - Fixed premature close dropping unsent data on choked pipe
        - Fixed IPv6 Host header missing brackets (RFC 7230)
        - Fixed negative fd guard in fd_watcher functions
        - Fixed handshake_headers_map leak on aborted handshake
        - New examples: chat_server, proxy, backpressure

0.02    2026-03-31
        - on_handshake: server callback for per-connection response headers
          and connection rejection (403)
        - send_fragment: streaming fragmented writes (NO_FIN/CONTINUATION)
        - stash: per-connection metadata hashref
        - on_drain: callback when send queue empties
        - send_queue_size: query pending send bytes
        - connect_timeout: deadline for WebSocket handshake
        - Server protocol parameter on listen()
        - Broader client response header capture (Sec-WebSocket-Protocol,
          Location, WWW-Authenticate)
        - Server-side X-Forwarded-For in on_connect headers
        - O(1) fd watcher lookup (flat array indexed by fd)
        - Single-alloc send queue nodes (FAM)

README  view on Meta::CPAN

    Queue a Ping frame. $payload is optional; if supplied it is silently
    truncated to 125 bytes per RFC 6455 §5.5. Croaks if the connection is
    not open.

   send_pong([$payload])
    Queue a Pong frame. Same payload rules as "send_ping". Most peers send
    Pong automatically in response to Ping; you only need this to send an
    unsolicited Pong (e.g. as a one-way keepalive).

   send_fragment($data, $is_binary = 0, $is_final = 1)
    Send one fragment of a streaming message. The first call starts a new
    fragmented message (text or binary per $is_binary); subsequent calls
    send continuation frames. Set $is_final true on the last fragment.

        $conn->send_fragment("part1", 0, 0);   # text, not final
        $conn->send_fragment("part2", 0, 0);   # continuation, not final
        $conn->send_fragment("part3", 0, 1);   # continuation, final

    $is_binary is honoured only on the first fragment, which fixes the
    message type; it is ignored on continuation frames (they are always sent
    as continuations), per RFC 6455 §5.4.

    Use this only if you need to interleave outbound writes with other I/O
    while streaming a single message. For ordinary sends, prefer
    "send"/"send_binary".

   send_queue_size
    Returns the number of payload bytes currently queued for sending
    (excludes WebSocket framing overhead). Useful for backpressure
    monitoring; pair with "on_drain" to gate further sends. Returns 0 on a
    closed connection (it does not croak), so it is safe to poll from
    cleanup paths.

   stash

eg/backpressure.pl  view on Meta::CPAN

        $c->send("x" x $CHUNK_SIZE);
        $c->stash->{sent}++;
        $total_sent += $CHUNK_SIZE;
    }
}

my $port = $ctx->listen(
    port => 0,
    on_connect => sub {
        my ($c) = @_;
        print "Server: client connected, streaming $TARGET_MSGS chunks of ${\ ($CHUNK_SIZE/1024)}KB\n";
        $c->stash->{sent} = 0;
        $t0 = time;
        try_send($c);
    },
    on_drain => sub {
        my ($c) = @_;
        try_send($c);
    },
    on_close => sub {
        print "Server: client disconnected\n";

lib/EV/Websockets.pm  view on Meta::CPAN

open.

=head3 send_pong([$payload])

Queue a Pong frame. Same payload rules as C<send_ping>. Most peers send Pong
automatically in response to Ping; you only need this to send an unsolicited
Pong (e.g. as a one-way keepalive).

=head3 send_fragment($data, $is_binary = 0, $is_final = 1)

Send one fragment of a streaming message. The first call starts a new
fragmented message (text or binary per C<$is_binary>); subsequent calls send
continuation frames. Set C<$is_final> true on the last fragment.

    $conn->send_fragment("part1", 0, 0);   # text, not final
    $conn->send_fragment("part2", 0, 0);   # continuation, not final
    $conn->send_fragment("part3", 0, 1);   # continuation, final

C<$is_binary> is honoured only on the first fragment, which fixes the message
type; it is ignored on continuation frames (they are always sent as
continuations), per RFC 6455 §5.4.

Use this only if you need to interleave outbound writes with other I/O while
streaming a single message. For ordinary sends, prefer C<send>/C<send_binary>.

=head3 send_queue_size

Returns the number of payload bytes currently queued for sending (excludes
WebSocket framing overhead). Useful for backpressure monitoring; pair with
C<on_drain> to gate further sends. Returns C<0> on a closed connection (it
does not croak), so it is safe to poll from cleanup paths.

=head3 stash



( run in 2.121 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )