Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lib: separate writev responsibilities from writeGeneric
  • Loading branch information
aks- committed Mar 23, 2018
commit efa0f4f81d907a9e3ae09d9185ac9297bfbbf385
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ class Http2Stream extends Duplex {
const req = new WriteWrap();
req.callback = cb;
this.createWriteWrap(req, streamId, handle, afterDoStreamWrite);
this.writeGeneric(req, null, data, encoding, cb);
this.writeGeneric(req, data, encoding, cb);

trackWriteState(this, req.bytes);
}
Expand Down
52 changes: 28 additions & 24 deletions lib/internal/streams/stream_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,37 @@ const StreamBaseMethods = {
req.async = false;
},

writeGeneric(req, writev, data, encoding, cb) {
const { handle, error } = req;
let err;

if (writev) {
const allBuffers = data.allBuffers;
let chunks;
let i;
if (allBuffers) {
chunks = data;
for (i = 0; i < data.length; i++)
data[i] = data[i].chunk;
} else {
chunks = new Array(data.length << 1);
for (i = 0; i < data.length; i++) {
const entry = data[i];
chunks[i * 2] = entry.chunk;
chunks[i * 2 + 1] = entry.encoding;
}
writevGeneric(req, data, cb) {
const { error } = req;
const allBuffers = data.allBuffers;
let chunks;
let i;
if (allBuffers) {
chunks = data;
for (i = 0; i < data.length; i++)
data[i] = data[i].chunk;
} else {
chunks = new Array(data.length << 1);
for (i = 0; i < data.length; i++) {
const entry = data[i];
chunks[i * 2] = entry.chunk;
chunks[i * 2 + 1] = entry.encoding;
}
err = this._handle.writev(req, chunks, allBuffers);
}
const err = this._handle.writev(req, chunks, allBuffers);

// Retain chunks
if (err === 0) req._chunks = chunks;
} else {
err = this._handleWriteReq(req, handle, data, encoding);
// Retain chunks
if (err === 0) req._chunks = chunks;

if (err) {
return this.destroy(errnoException(err, 'write', error), cb);
}
},

writeGeneric(req, data, encoding, cb) {
const { handle, error } = req;

const err = this._handleWriteReq(req, handle, data, encoding);

if (err) {
return this.destroy(errnoException(err, 'write', error), cb);
Expand Down
3 changes: 2 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,8 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
const req = new WriteWrap();
const handle = this._handle;
this.createWriteWrap(req, null, handle, afterWrite);
this.writeGeneric(req, writev, data, encoding, cb);
if (writev) this.writevGeneric(req, data, cb);
else this.writeGeneric(req, data, encoding, cb);

this._bytesDispatched += req.bytes;

Expand Down