-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge http2 stream & net socket #19527
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b037232
lib: merge stream handling code for http2 streams & net.Socket
aks- efa0f4f
lib: separate writev responsibilities from writeGeneric
aks- 19aedde
lib: fix calling of cb twice
aks- 5c8eb75
lib: extract streamId out of stream_base to caller
aks- 92e4f71
lib: add symbols instead of methods to hide impl details
aks- babe858
lib: remove unneeded lines
aks- 27818c4
lib: use Object.assign instead of apply
aks- 0144de4
lib: rename mixin StreamBase to StreamSharedMethods
aks- e4365d6
lib: use stream shared funcs as top level instead of properties of pr…
aks- 560635d
lib: mv lib/internal/stream_shared_methods.js lib/internal/stream_bas…
aks- 833c52a
lib: add comment for readability
aks- fcfd8d3
lib: refactor _writev in Http2Stream
aks- 43b912d
lib: rephrase comment
aks- 5055714
lib: revert usage of const,let for perf reasons
aks- File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use strict'; | ||
|
||
const { Buffer } = require('buffer'); | ||
const errors = require('internal/errors'); | ||
const { WriteWrap } = process.binding('stream_wrap'); | ||
|
||
const errnoException = errors.errnoException; | ||
|
||
function handleWriteReq(req, data, encoding) { | ||
const { handle } = req; | ||
|
||
switch (encoding) { | ||
case 'buffer': | ||
return handle.writeBuffer(req, data); | ||
case 'latin1': | ||
case 'binary': | ||
return handle.writeLatin1String(req, data); | ||
case 'utf8': | ||
case 'utf-8': | ||
return handle.writeUtf8String(req, data); | ||
case 'ascii': | ||
return handle.writeAsciiString(req, data); | ||
case 'ucs2': | ||
case 'ucs-2': | ||
case 'utf16le': | ||
case 'utf-16le': | ||
return handle.writeUcs2String(req, data); | ||
default: | ||
return handle.writeBuffer(req, Buffer.from(data, encoding)); | ||
} | ||
} | ||
|
||
function createWriteWrap(handle, oncomplete) { | ||
var req = new WriteWrap(); | ||
|
||
req.handle = handle; | ||
req.oncomplete = oncomplete; | ||
req.async = false; | ||
|
||
return req; | ||
} | ||
|
||
function writevGeneric(self, req, data, cb) { | ||
var allBuffers = data.allBuffers; | ||
var chunks; | ||
var 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++) { | ||
var entry = data[i]; | ||
chunks[i * 2] = entry.chunk; | ||
chunks[i * 2 + 1] = entry.encoding; | ||
} | ||
} | ||
var err = req.handle.writev(req, chunks, allBuffers); | ||
|
||
// Retain chunks | ||
if (err === 0) req._chunks = chunks; | ||
|
||
if (err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: it should be ok to use an |
||
return self.destroy(errnoException(err, 'write', req.error), cb); | ||
} | ||
|
||
function writeGeneric(self, req, data, encoding, cb) { | ||
var err = handleWriteReq(req, data, encoding); | ||
|
||
if (err) | ||
return self.destroy(errnoException(err, 'write', req.error), cb); | ||
} | ||
|
||
module.exports = { | ||
createWriteWrap, | ||
writevGeneric, | ||
writeGeneric | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have this done for
writev
too :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax done 👍