diff --git a/benchmark/buffers/buffer-read-float.js b/benchmark/buffers/buffer-read-float.js new file mode 100644 index 00000000000000..5dda2486c6711a --- /dev/null +++ b/benchmark/buffers/buffer-read-float.js @@ -0,0 +1,46 @@ +'use strict'; +const common = require('../common.js'); + +const bench = common.createBenchmark(main, { + noAssert: ['false', 'true'], + type: ['Double', 'Float'], + endian: ['BE', 'LE'], + value: ['zero', 'big', 'small', 'inf', 'nan'], + millions: [1] +}); + +function main(conf) { + const noAssert = conf.noAssert === 'true'; + const len = +conf.millions * 1e6; + const buff = Buffer.alloc(8); + const type = conf.type || 'Double'; + const endian = conf.endian; + const fn = `read${type}${endian}`; + const values = { + Double: { + zero: 0, + big: 2 ** 1023, + small: 2 ** -1074, + inf: Infinity, + nan: NaN, + }, + Float: { + zero: 0, + big: 2 ** 127, + small: 2 ** -149, + inf: Infinity, + nan: NaN, + }, + }; + const value = values[type][conf.value]; + + buff[`write${type}${endian}`](value, 0, noAssert); + const testFunction = new Function('buff', ` + for (var i = 0; i !== ${len}; i++) { + buff.${fn}(0, ${JSON.stringify(noAssert)}); + } + `); + bench.start(); + testFunction(buff); + bench.end(len / 1e6); +} diff --git a/doc/api/http.md b/doc/api/http.md index 9f06296e6e2584..928ed0d972b472 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -734,6 +734,11 @@ changes: description: The default action of calling `.destroy()` on the `socket` will no longer take place if there are listeners attached for `clientError`. + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/17672 + description: The rawPacket is the current buffer that just parsed. Adding + this buffer to the error object of clientError event is to make + it possible that developers can log the broken packet. --> * `exception` {Error} @@ -765,6 +770,12 @@ object, so any HTTP response sent, including response headers and payload, *must* be written directly to the `socket` object. Care must be taken to ensure the response is a properly formatted HTTP response message. +`err` is an instance of `Error` with two extra columns: + ++ `bytesParsed`: the bytes count of request packet that Node.js may have parsed + correctly; ++ `rawPacket`: the raw packet of current request. + ### Event: 'close'