Net-QUIC

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

    server_name => 'example.com',

    send => sub {
        my ($datagram) = @_;
        send_udp($datagram);
        return 1;
    },

    set_timeout => sub {
        my ($seconds) = @_;
        replace_timer($seconds);
    },
);

my $connection = $driver->connection;

$driver->start;
```

`start` tells Driver that the UDP transport is ready. The client can then
produce its first QUIC packet.

### What is ALPN?

ALPN is simply a short protocol name agreed on by the client and server.

For a custom protocol you might use:

```perl
alpn => 'my-protocol'
```

It prevents two unrelated protocols from accidentally using the same QUIC
connection.

### What is server_name?

`server_name` is the DNS name or IP address that the server certificate must
represent.

For example, the UDP peer can be a numeric address:

```text
192.0.2.20:4433
```

while certificate verification uses:

```perl
server_name => 'service.example.com'
```

## A server

A server Driver uses the same UDP/timer contract:

```perl
my $driver = Net::QUIC::Driver->server(
    alpn             => 'my-protocol',
    certificate_file => 'server-cert.pem',
    private_key_file => 'server-key.pem',

    send => sub {
        my ($datagram) = @_;
        send_udp($datagram);
        return 1;
    },

    set_timeout => sub {
        my ($seconds) = @_;
        replace_timer($seconds);
    },
);

$driver->start;
```

Feed received UDP packets into Driver:

```perl
$driver->receive($bytes, $local, $peer);
```

Pull newly created connections with:

```perl
while (my $connection = $driver->next_connection) {
    ...
}
```

One server Driver can manage many QUIC connections on one UDP socket.

## The event-loop contract

Net::QUIC deliberately does not choose an event loop.

The event loop owns:

- UDP I/O
- one replaceable one-shot timer

Driver needs two callbacks from the adapter:

```perl
send => sub {
    my ($datagram) = @_;

    # Send one complete UDP datagram.
    #
    # Return true if another datagram can be accepted immediately.
    # Return false if this datagram was accepted but output is now blocked.
},

set_timeout => sub {
    my ($seconds) = @_;

    # Replace the current one-shot QUIC timer.
    # undef means cancel it.
},
```



( run in 1.582 second using v1.01-cache-2.11-cpan-036bef1c656 )