mirror of https://github.com/lukechilds/node.git
Browse Source
This will provide `bytesRead` data on consumed sockets. Fix: #3021 PR-URL: https://github.com/nodejs/node/pull/6284 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>process-exit-stdio-flushing
Fedor Indutny
9 years ago
5 changed files with 79 additions and 7 deletions
@ -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(); |
||||
|
}); |
Loading…
Reference in new issue