Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quic: another round of refactorings #34247

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
quic: refactor/improve/document QuicSocket listening event
  • Loading branch information
jasnell committed Jul 7, 2020
commit 89844585fd8b4e771b5e9b19a8fc50de0df87d3b
11 changes: 11 additions & 0 deletions doc/api/quic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-quic-server-listening-event-error-async.js
Original file line number Diff line number Diff line change
@@ -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');
}));
33 changes: 33 additions & 0 deletions test/parallel/test-quic-server-listening-event-error.js
Original file line number Diff line number Diff line change
@@ -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');
}));