-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: add flow and buffer properties to streams
This adds computed properties to readable and writable streams to allow access to the readable buffer, the writable buffer, and flow state without accessing the readable or writable state. These are the only uses of readable and writable state in the docs so adding these work arounds allows them to be removed from the docs. This also updates net, http_client and http_server to use the new methods instead of manipulating readable and writable state directly. See: #445 PR-URL: #12855 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
9306de2
commit 4b0c875
Showing
13 changed files
with
118 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const PORT = common.PORT; | ||
const net = require('net'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [5, 1000] | ||
}); | ||
|
||
const reqData = 'GET / HTTP/1.1\r\n' + | ||
'Upgrade: WebSocket\r\n' + | ||
'Connection: Upgrade\r\n' + | ||
'\r\n' + | ||
'WjN}|M(6'; | ||
|
||
const resData = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' + | ||
'Upgrade: WebSocket\r\n' + | ||
'Connection: Upgrade\r\n' + | ||
'\r\n\r\n'; | ||
|
||
function main({ n }) { | ||
process.env.PORT = PORT; | ||
var server = require('../fixtures/simple-http-server.js') | ||
.listen(common.PORT) | ||
.on('listening', function() { | ||
bench.start(); | ||
doBench(server.address(), n, function() { | ||
bench.end(n); | ||
server.close(); | ||
}); | ||
}) | ||
.on('upgrade', function(req, socket, upgradeHead) { | ||
socket.resume(); | ||
socket.write(resData); | ||
socket.end(); | ||
}); | ||
} | ||
|
||
function doBench(address, count, done) { | ||
if (count === 0) { | ||
done(); | ||
return; | ||
} | ||
|
||
const conn = net.createConnection(address.port); | ||
conn.write(reqData); | ||
conn.resume(); | ||
|
||
conn.on('end', function() { | ||
doBench(address, count - 1, done); | ||
}); | ||
} |
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
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
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
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
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
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