quic: remove unneeded quicstream.aborted and fixup docs
PR-URL: https://github.com/nodejs/node/pull/34351 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
a65296db2c
commit
83bf0d7e8c
@ -25,17 +25,9 @@ const { createQuicSocket } = require('net');
|
|||||||
// Create the QUIC UDP IPv4 socket bound to local IP port 1234
|
// Create the QUIC UDP IPv4 socket bound to local IP port 1234
|
||||||
const socket = createQuicSocket({ endpoint: { port: 1234 } });
|
const socket = createQuicSocket({ endpoint: { port: 1234 } });
|
||||||
|
|
||||||
socket.on('session', (session) => {
|
socket.on('session', async (session) => {
|
||||||
// A new server side session has been created!
|
// A new server side session has been created!
|
||||||
|
|
||||||
session.on('secure', () => {
|
|
||||||
// Once the TLS handshake is completed, we can
|
|
||||||
// open streams...
|
|
||||||
const uni = session.openStream({ halfOpen: true });
|
|
||||||
uni.write('hi ');
|
|
||||||
uni.end('from the server!');
|
|
||||||
});
|
|
||||||
|
|
||||||
// The peer opened a new stream!
|
// The peer opened a new stream!
|
||||||
session.on('stream', (stream) => {
|
session.on('stream', (stream) => {
|
||||||
// Let's say hello
|
// Let's say hello
|
||||||
@ -46,6 +38,10 @@ socket.on('session', (session) => {
|
|||||||
stream.on('data', console.log);
|
stream.on('data', console.log);
|
||||||
stream.on('end', () => console.log('stream ended'));
|
stream.on('end', () => console.log('stream ended'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const uni = await session.openStream({ halfOpen: true });
|
||||||
|
uni.write('hi ');
|
||||||
|
uni.end('from the server!');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tell the socket to operate as a server using the given
|
// Tell the socket to operate as a server using the given
|
||||||
@ -187,10 +183,10 @@ The `openStream()` method is used to create a new `QuicStream`:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
// Create a new bidirectional stream
|
// Create a new bidirectional stream
|
||||||
const stream1 = session.openStream();
|
const stream1 = await session.openStream();
|
||||||
|
|
||||||
// Create a new unidirectional stream
|
// Create a new unidirectional stream
|
||||||
const stream2 = session.openStream({ halfOpen: true });
|
const stream2 = await session.openStream({ halfOpen: true });
|
||||||
```
|
```
|
||||||
|
|
||||||
As suggested by the names, a bidirectional stream allows data to be sent on
|
As suggested by the names, a bidirectional stream allows data to be sent on
|
||||||
@ -1045,12 +1041,12 @@ added: REPLACEME
|
|||||||
* `defaultEncoding` {string} The default encoding that is used when no
|
* `defaultEncoding` {string} The default encoding that is used when no
|
||||||
encoding is specified as an argument to `quicstream.write()`. Default:
|
encoding is specified as an argument to `quicstream.write()`. Default:
|
||||||
`'utf8'`.
|
`'utf8'`.
|
||||||
* Returns: {QuicStream}
|
* Returns: {Promise} containing {QuicStream}
|
||||||
|
|
||||||
Returns a new `QuicStream`.
|
Returns a `Promise` that resolves a new `QuicStream`.
|
||||||
|
|
||||||
An error will be thrown if the `QuicSession` has been destroyed or is in the
|
The `Promise` will be rejected if the `QuicSession` has been destroyed or is in
|
||||||
process of a graceful shutdown.
|
the process of a graceful shutdown.
|
||||||
|
|
||||||
#### `quicsession.ping()`
|
#### `quicsession.ping()`
|
||||||
<!--YAML
|
<!--YAML
|
||||||
@ -2153,14 +2149,6 @@ stream('trailingHeaders', (headers) => {
|
|||||||
added: REPLACEME
|
added: REPLACEME
|
||||||
-->
|
-->
|
||||||
|
|
||||||
#### `quicstream.aborted`
|
|
||||||
<!-- YAML
|
|
||||||
added: REPLACEME
|
|
||||||
-->
|
|
||||||
* Type: {boolean}
|
|
||||||
|
|
||||||
True if dataflow on the `QuicStream` was prematurely terminated.
|
|
||||||
|
|
||||||
#### `quicstream.bidirectional`
|
#### `quicstream.bidirectional`
|
||||||
<!--YAML
|
<!--YAML
|
||||||
added: REPLACEME
|
added: REPLACEME
|
||||||
@ -2281,16 +2269,6 @@ added: REPLACEME
|
|||||||
|
|
||||||
The maximum received offset for this `QuicStream`.
|
The maximum received offset for this `QuicStream`.
|
||||||
|
|
||||||
#### `quicstream.pending`
|
|
||||||
<!-- YAML
|
|
||||||
added: REPLACEME
|
|
||||||
-->
|
|
||||||
|
|
||||||
* {boolean}
|
|
||||||
|
|
||||||
This property is `true` if the underlying session is not finished yet,
|
|
||||||
i.e. before the `'ready'` event is emitted.
|
|
||||||
|
|
||||||
#### `quicstream.pushStream(headers\[, options\])`
|
#### `quicstream.pushStream(headers\[, options\])`
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: REPLACEME
|
added: REPLACEME
|
||||||
|
@ -2534,7 +2534,6 @@ function streamOnPause() {
|
|||||||
class QuicStream extends Duplex {
|
class QuicStream extends Duplex {
|
||||||
[kInternalState] = {
|
[kInternalState] = {
|
||||||
closed: false,
|
closed: false,
|
||||||
aborted: false,
|
|
||||||
defaultEncoding: undefined,
|
defaultEncoding: undefined,
|
||||||
didRead: false,
|
didRead: false,
|
||||||
id: undefined,
|
id: undefined,
|
||||||
@ -2653,8 +2652,6 @@ class QuicStream extends Duplex {
|
|||||||
|
|
||||||
state.closed = true;
|
state.closed = true;
|
||||||
|
|
||||||
state.aborted = this.readable || this.writable;
|
|
||||||
|
|
||||||
// Trigger scheduling of the RESET_STREAM and STOP_SENDING frames
|
// Trigger scheduling of the RESET_STREAM and STOP_SENDING frames
|
||||||
// as appropriate. Notify ngtcp2 that the stream is to be shutdown.
|
// as appropriate. Notify ngtcp2 that the stream is to be shutdown.
|
||||||
// Once sent, the stream will be closed and destroyed as soon as
|
// Once sent, the stream will be closed and destroyed as soon as
|
||||||
@ -2702,10 +2699,6 @@ class QuicStream extends Duplex {
|
|||||||
// TODO(@jasnell): Implement this later
|
// TODO(@jasnell): Implement this later
|
||||||
}
|
}
|
||||||
|
|
||||||
get aborted() {
|
|
||||||
return this[kInternalState].aborted;
|
|
||||||
}
|
|
||||||
|
|
||||||
get serverInitiated() {
|
get serverInitiated() {
|
||||||
return !!(this[kInternalState].id & 0b01);
|
return !!(this[kInternalState].id & 0b01);
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,7 @@ const countdown = new Countdown(2, () => {
|
|||||||
server.on('session', common.mustCall(async (session) => {
|
server.on('session', common.mustCall(async (session) => {
|
||||||
const uni = await session.openStream({ halfOpen: true });
|
const uni = await session.openStream({ halfOpen: true });
|
||||||
uni.write('hi', common.expectsError());
|
uni.write('hi', common.expectsError());
|
||||||
uni.on('error', common.mustCall(() => {
|
uni.on('error', common.mustCall());
|
||||||
assert.strictEqual(uni.aborted, true);
|
|
||||||
}));
|
|
||||||
uni.on('data', common.mustNotCall());
|
uni.on('data', common.mustNotCall());
|
||||||
uni.on('close', common.mustCall());
|
uni.on('close', common.mustCall());
|
||||||
uni.close(3);
|
uni.close(3);
|
||||||
@ -56,9 +54,7 @@ const countdown = new Countdown(2, () => {
|
|||||||
const stream = await req.openStream();
|
const stream = await req.openStream();
|
||||||
stream.write('hello', common.expectsError());
|
stream.write('hello', common.expectsError());
|
||||||
stream.write('there', common.expectsError());
|
stream.write('there', common.expectsError());
|
||||||
stream.on('error', common.mustCall(() => {
|
stream.on('error', common.mustCall());
|
||||||
assert.strictEqual(stream.aborted, true);
|
|
||||||
}));
|
|
||||||
stream.on('end', common.mustNotCall());
|
stream.on('end', common.mustNotCall());
|
||||||
stream.on('close', common.mustCall(() => {
|
stream.on('close', common.mustCall(() => {
|
||||||
countdown.dec();
|
countdown.dec();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user