X Tutup
The Wayback Machine - https://web.archive.org/web/20220320025642/https://github.com/nodejs/node/commit/94372b124a
Skip to content
Permalink
Browse files
quic: refactor/improve/document QuicSocket listening event
PR-URL: #34247
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
jasnell committed Jul 9, 2020
1 parent afc9390 commit 94372b124a8c262d5104dc2a441d5af5e9355fd1
Showing with 84 additions and 1 deletion.
  1. +11 −0 doc/api/quic.md
  2. +7 −1 lib/internal/quic/core.js
  3. +33 −0 test/parallel/test-quic-server-listening-event-error-async.js
  4. +33 −0 test/parallel/test-quic-server-listening-event-error.js
@@ -1371,6 +1371,17 @@ Emitted before the `'close'` event if the `QuicSocket` was destroyed with an

The `'error'` event will not be emitted multiple times.

#### Event: `'listening'`
<!-- YAML
added: REPLACEME
-->

Emitted after `quicsocket.listen()` is called and the `QuicSocket` has started
listening for incoming `QuicServerSession`s. The callback is invoked with
no arguments.

The `'listening'` event will not be emitted multiple times.

#### Event: `'ready'`
<!-- YAML
added: REPLACEME
@@ -1166,7 +1166,13 @@ class QuicSocket extends EventEmitter {
port,
state.alpn,
options);
process.nextTick(emit.bind(this, 'listening'));
process.nextTick(() => {
try {
this.emit('listening');
} catch (error) {
this.destroy(error);
}
});
}

// When the QuicSocket listen() function is called, the first step is to bind
@@ -0,0 +1,33 @@
// Flags: --no-warnings
'use strict';

const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');

const assert = require('assert');
const {
key,
cert,
ca,
} = require('../common/quic');

const { createQuicSocket } = require('net');

const options = { key, cert, ca, alpn: 'zzz' };

const server = createQuicSocket({ server: options });

server.on('session', common.mustNotCall());

server.listen();

server.on('error', common.mustCall((error) => {
assert.strictEqual(error.message, 'boom');
}));

server.on('ready', common.mustCall());

server.on('listening', common.mustCall(async () => {
throw new Error('boom');
}));
@@ -0,0 +1,33 @@
// Flags: --no-warnings
'use strict';

const common = require('../common');
if (!common.hasQuic)
common.skip('missing quic');

const assert = require('assert');
const {
key,
cert,
ca,
} = require('../common/quic');

const { createQuicSocket } = require('net');

const options = { key, cert, ca, alpn: 'zzz' };

const server = createQuicSocket({ server: options });

server.on('session', common.mustNotCall());

server.listen();

server.on('error', common.mustCall((error) => {
assert.strictEqual(error.message, 'boom');
}));

server.on('ready', common.mustCall());

server.on('listening', common.mustCall(() => {
throw new Error('boom');
}));

0 comments on commit 94372b1

Please sign in to comment.
X Tutup