Skip to content

Commit

Permalink
net: fix usage of writeBuffer in makeSyncWrite
Browse files Browse the repository at this point in the history
The binding writeBuffer has been changed in
nodejs#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.
  • Loading branch information
joyeecheung committed Mar 3, 2018
1 parent 4bfc03b commit babd2da
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/internal/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}$`);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit babd2da

Please sign in to comment.