Skip to content

Commit ae1fc49

Browse files
committed
1 parent a695065 commit ae1fc49

5 files changed

Lines changed: 33 additions & 35 deletions

File tree

src/node.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,8 @@ int main(int argc, char *argv[]) {
11601160
// so your next reading stop should be node::Load()!
11611161
node::Load(argc, argv);
11621162

1163+
node::Stdio::Flush();
1164+
11631165
#ifndef NDEBUG
11641166
// Clean up.
11651167
context.Dispose();

src/node_stdio.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ Close (const Arguments& args)
197197
return Undefined();
198198
}
199199

200+
void Stdio::Flush() {
201+
if (stdout_fd >= 0) {
202+
close(stdout_fd);
203+
stdout_fd = -1;
204+
}
205+
206+
if (stdout_coupling) {
207+
coupling_join(stdout_coupling);
208+
coupling_destroy(stdout_coupling);
209+
stdout_coupling = NULL;
210+
}
211+
}
212+
200213
void
201214
Stdio::Initialize (v8::Handle<v8::Object> target)
202215
{

src/node_stdio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace node {
1111
class Stdio {
1212
public:
1313
static void Initialize (v8::Handle<v8::Object> target);
14+
static void Flush ();
1415
};
1516

1617
} // namespace node

test/mjsunit/fixtures/print-chars.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@ for (var i = 0; i < n-1; i++) {
88
}
99

1010
puts(s); // \n is the nth char.
11-
12-
process.exit(0);

test/mjsunit/test-stdout-flush.js

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,27 @@ process.mixin(require("./common"));
22

33
var sub = path.join(fixturesDir, 'print-chars.js');
44

5-
completedTests = 0;
5+
n = 100000;
66

7-
function test (n, cb) {
8-
var child = process.createChildProcess(process.argv[0], [sub, n]);
7+
var child = process.createChildProcess(process.argv[0], [sub, n]);
98

10-
var count = 0;
9+
var count = 0;
1110

12-
child.addListener("error", function (data){
13-
if (data) {
14-
puts("parent stderr: " + data);
15-
assert.ok(false);
16-
}
17-
});
18-
19-
child.addListener("output", function (data){
20-
if (data) {
21-
count += data.length;
22-
}
23-
});
24-
25-
child.addListener("exit", function (data) {
26-
assert.equal(n, count);
27-
puts(n + " okay");
28-
completedTests++;
29-
if (cb) cb();
30-
});
31-
}
32-
33-
34-
35-
test(5000, function () {
36-
test(50000, function () {
37-
test(500000);
38-
});
11+
child.addListener("error", function (data){
12+
if (data) {
13+
puts("parent stderr: " + data);
14+
assert.ok(false);
15+
}
3916
});
4017

18+
child.addListener("output", function (data){
19+
if (data) {
20+
count += data.length;
21+
puts(count);
22+
}
23+
});
4124

42-
process.addListener('exit', function () {
43-
assert.equal(3, completedTests);
25+
child.addListener("exit", function (data) {
26+
assert.equal(n, count);
27+
puts("okay");
4428
});

0 commit comments

Comments
 (0)