-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream_base: expose
bytesRead
getter
This will provide `bytesRead` data on consumed sockets. Fix: #3021 PR-URL: #6284 Reviewed-By: Ben Noordhuis <[email protected]>
- Loading branch information
1 parent
8ccfb87
commit 052d87c
Showing
5 changed files
with
79 additions
and
7 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
|
||
const big = Buffer.alloc(1024 * 1024); | ||
|
||
const server = net.createServer((socket) => { | ||
socket.end(big); | ||
server.close(); | ||
}).listen(common.PORT, () => { | ||
let prev = 0; | ||
|
||
function checkRaise(value) { | ||
assert(value > prev); | ||
prev = value; | ||
} | ||
|
||
const socket = net.connect(common.PORT, () => { | ||
socket.on('data', (chunk) => { | ||
checkRaise(socket.bytesRead); | ||
}); | ||
|
||
socket.on('end', common.mustCall(() => { | ||
assert.equal(socket.bytesRead, prev); | ||
assert.equal(big.length, prev); | ||
})); | ||
|
||
socket.on('close', common.mustCall(() => { | ||
assert(!socket._handle); | ||
assert.equal(socket.bytesRead, prev); | ||
assert.equal(big.length, prev); | ||
})); | ||
}); | ||
socket.end(); | ||
}); |