diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-03-03 10:43:14 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-03-03 13:34:09 +0300 |
commit | 67b5985c0800b3cfaef5947e2cb6ef61c8cf49f8 (patch) | |
tree | 9104da48ee7e9e3679126ba9460c0b9b2440f428 /lib/internal/net.js | |
parent | 4bfc03b57dfbf6ac245b56c62b718ccd68e12cd7 (diff) |
net: fix usage of writeBuffer in makeSyncWrite
The binding writeBuffer has been changed in
https://github.com/nodejs/node/pull/19041 and it now requires
the last argument to be a context object. makeSyncWrite
was not updated accordingly, resulting assertions on Windows.
This patch fixes the usage of writeBuffer there.
Also fix errors.uvException() so error.message are no longer
enumerable, this fixes the deepStrictEqual assertion on the
error object in test-stdout-close-catch.
PR-URL: https://github.com/nodejs/node/pull/19103
Refs: https://github.com/nodejs/node/pull/19041
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/internal/net.js')
-rw-r--r-- | lib/internal/net.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/internal/net.js b/lib/internal/net.js index adaa4475b02..9c2602b79e9 100644 --- a/lib/internal/net.js +++ b/lib/internal/net.js @@ -3,6 +3,7 @@ const Buffer = require('buffer').Buffer; const { isIPv6 } = process.binding('cares_wrap'); const { writeBuffer } = process.binding('fs'); +const errors = require('internal/errors'); const octet = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'; const re = new RegExp(`^${octet}[.]${octet}[.]${octet}[.]${octet}$`); @@ -33,13 +34,13 @@ function makeSyncWrite(fd) { this._bytesDispatched += chunk.length; - try { - writeBuffer(fd, chunk, 0, chunk.length, null); - } catch (ex) { + const ctx = {}; + writeBuffer(fd, chunk, 0, chunk.length, null, undefined, ctx); + if (ctx.errno !== undefined) { + const ex = errors.uvException(ctx); // Legacy: net writes have .code === .errno, whereas writeBuffer gives the // raw errno number in .errno. - if (typeof ex.code === 'string') - ex.errno = ex.code; + ex.errno = ex.code; return cb(ex); } cb(); |