From 0785819e27951d25f7e20674d3886c630babe011 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 3 Oct 2019 21:06:46 +0200 Subject: [PATCH] quic: implement sendFD() support Fixes: https://github.com/nodejs/quic/issues/75 PR-URL: https://github.com/nodejs/quic/pull/150 Reviewed-By: James M Snell --- doc/api/quic.md | 50 ++++++++- lib/internal/quic/core.js | 95 +++++++++++++++- test/parallel/test-quic-send-fd.js | 102 ++++++++++++++++++ .../test-quic-send-file-close-before-open.js | 63 +++++++++++ .../test-quic-send-file-open-error-handled.js | 66 ++++++++++++ .../test-quic-send-file-open-error.js | 66 ++++++++++++ 6 files changed, 438 insertions(+), 4 deletions(-) create mode 100644 test/parallel/test-quic-send-fd.js create mode 100644 test/parallel/test-quic-send-file-close-before-open.js create mode 100644 test/parallel/test-quic-send-file-open-error-handled.js create mode 100644 test/parallel/test-quic-send-file-open-error.js diff --git a/doc/api/quic.md b/doc/api/quic.md index 80a45709f6..ecd008730e 100644 --- a/doc/api/quic.md +++ b/doc/api/quic.md @@ -943,7 +943,7 @@ socket.on('ready', () => { }); ``` -#### Call Results# +#### Call Results A call on a socket that is not ready to send or no longer open may throw a Not running Error. @@ -1106,6 +1106,54 @@ added: REPLACEME The `QuicServerSession` or `QuicClientSession`. +### quicstream.sendFD(fd[, options]) + + +* `fd` {number|FileHandle} A readable file descriptor. +* `options` {Object} + * `offset` {number} The offset position at which to begin reading. + Default: `-1`. + * `length` {number} The amount of data from the fd to send. + Default: `-1`. + +Instead of using a `Quicstream` as a writable stream, send data from a given file +descriptor. + +If `offset` is set to a non-negative number, reading starts from that position +and the file offset will not be advanced. +If `length` is set to a non-negative number, it gives the maximum number of +bytes that are read from the file. + +The file descriptor or `FileHandle` is not closed when the stream is closed, +so it will need to be closed manually once it is no longer needed. +Using the same file descriptor concurrently for multiple streams +is not supported and may result in data loss. Re-using a file descriptor +after a stream has finished is supported. + +### quicstream.sendFile(path[, options]) + + +* `path` {string|Buffer|URL} +* `options` {Object} + * `onError` {Function} Callback function invoked in the case of an + error before send. + * `offset` {number} The offset position at which to begin reading. + Default: `-1`. + * `length` {number} The amount of data from the fd to send. + Default: `-1`. + +Instead of using a `QuicStream` as a writable stream, send data from a given file +path. + +The `options.onError` callback will be called if the file could not be opened. +If `offset` is set to a non-negative number, reading starts from that position. +If `length` is set to a non-negative number, it gives the maximum number of +bytes that are read from the file. + ### quicstream.unidirectional