forked from nodejs/node-v0.x-archive
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,62 @@ | ||
var assert =require('assert'); | ||
var net = require('net'); | ||
var IOWatcher = process.binding('io_watcher').IOWatcher; | ||
var net = require('net'); | ||
|
||
var stdout = new net.Stream(1); | ||
var w = stdout._writeWatcher; | ||
|
||
mb = 1024*1024; | ||
N = 50; | ||
expected = N * mb; | ||
nread = 0; | ||
|
||
// Create a pipe | ||
var fds = process.binding('net').pipe(); | ||
|
||
// Use writev/dumper to send data down the write end of the pipe, fds[1]. | ||
// This requires a IOWatcher. | ||
var w = new IOWatcher(); | ||
w.set(fds[1], false, false); | ||
|
||
// The read end, fds[0], will be used to count how much comes through. | ||
// This sets up a readable stream on fds[0]. | ||
var stream = new net.Stream(); | ||
stream.open(fds[0]); | ||
stream.readable = true; | ||
stream.resume(); | ||
|
||
|
||
// Count the data as it arrives on the read end of the pipe. | ||
stream.on('data', function (d) { | ||
nread += d.length; | ||
process.stdout.write("."); | ||
|
||
if (nread >= expected) { | ||
//w.stop(); | ||
// stream.destroy(); | ||
console.error("\ndone"); | ||
process.binding('net').close(fds[1]); | ||
} | ||
}); | ||
|
||
|
||
// Create out single 1mb buffer. | ||
b = Buffer(mb); | ||
for (var i = 0; i < mb; i++) { | ||
b[i] = 100; | ||
} | ||
|
||
|
||
// Fill the dumpQueue with N copies of that buffer. | ||
IOWatcher.dumpQueue.next = w; | ||
var bucket = w.buckets = { data: b }; | ||
|
||
for (var i = 0; i < 50; i++) { | ||
for (var i = 0; i < N-1; i++) { | ||
bucket = bucket.next = { data: b }; | ||
} | ||
|
||
/* Total size 50*(1024*1024) = 524288000 */ | ||
|
||
setTimeout(function () { | ||
// In the first 10 ms, we haven't pushed out the data. | ||
assert.ok(null !== IOWatcher.dumpQueue.next); | ||
}, 10); | ||
|
||
|
||
process.on('exit', function () { | ||
assert.ok(!IOWatcher.dumpQueue.next); | ||
console.log("nread: %d", nread); | ||
assert.equal(expected, nread); | ||
}); | ||
|
This file was deleted.
Oops, something went wrong.