Created
February 22, 2011 16:22
-
-
Save koichik/838904 to your computer and use it in GitHub Desktop.
Fix process.stdout.end() throws ENOTSOCK error.
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
From 2949f5b7c104b0dae213b2de2c00a8dbf557418c Mon Sep 17 00:00:00 2001 | |
From: koichik <[email protected]> | |
Date: Wed, 23 Feb 2011 12:03:49 +0900 | |
Subject: [PATCH 1/2] Reproduce process.stdout.end() throws ENOTSOCK error. | |
--- | |
test/disabled/test-tty-stdout-end.js | 14 ++++++++++++++ | |
1 files changed, 14 insertions(+), 0 deletions(-) | |
create mode 100644 test/disabled/test-tty-stdout-end.js | |
diff --git a/test/disabled/test-tty-stdout-end.js b/test/disabled/test-tty-stdout-end.js | |
new file mode 100644 | |
index 0000000..9b9f34f | |
--- /dev/null | |
+++ b/test/disabled/test-tty-stdout-end.js | |
@@ -0,0 +1,14 @@ | |
+// Can't test this when 'make test' doesn't assign a tty to the stdout. | |
+var common = require('../common'); | |
+var assert = require('assert'); | |
+var tty = require('tty'); | |
+ | |
+var closed = false; | |
+process.stdout.on('close', function() { | |
+ closed = true; | |
+}); | |
+process.on('exit', function() { | |
+ assert.ok(closed); | |
+}); | |
+ | |
+process.stdout.end(); | |
-- | |
1.7.1 | |
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
From f62f9f0606ac11b43a8dc22b3f6ce96071081665 Mon Sep 17 00:00:00 2001 | |
From: koichik <[email protected]> | |
Date: Wed, 23 Feb 2011 12:09:36 +0900 | |
Subject: [PATCH 2/2] Fix process.stdout.end() throws ENOTSOCK error. | |
--- | |
lib/tty_posix.js | 12 ++++++++++++ | |
test/disabled/test-tty-stdio.js | 12 ++++++++++++ | |
2 files changed, 24 insertions(+), 0 deletions(-) | |
create mode 100644 test/disabled/test-tty-stdio.js | |
diff --git a/lib/tty_posix.js b/lib/tty_posix.js | |
index 0bb0eb8..49879a9 100644 | |
--- a/lib/tty_posix.js | |
+++ b/lib/tty_posix.js | |
@@ -35,6 +35,12 @@ function ReadStream(fd) { | |
if (!(this instanceof ReadStream)) return new ReadStream(fd); | |
net.Socket.call(this, fd); | |
+ if (this._writeWatcher) { | |
+ this._writeWatcher.stop(); | |
+ this._writeWatcher = null; | |
+ } | |
+ this.writable = false; | |
+ | |
var self = this, | |
keypressListeners = this.listeners('keypress'); | |
@@ -285,6 +291,12 @@ ReadStream.prototype._emitKey = function(s) { | |
function WriteStream(fd) { | |
if (!(this instanceof WriteStream)) return new WriteStream(fd); | |
net.Socket.call(this, fd); | |
+ | |
+ if (this._readWatcher) { | |
+ this._readWatcher.stop(); | |
+ this._readWatcher = null; | |
+ } | |
+ this.readable = false; | |
} | |
inherits(WriteStream, net.Socket); | |
exports.WriteStream = WriteStream; | |
diff --git a/test/disabled/test-tty-stdio.js b/test/disabled/test-tty-stdio.js | |
new file mode 100644 | |
index 0000000..0d96395 | |
--- /dev/null | |
+++ b/test/disabled/test-tty-stdio.js | |
@@ -0,0 +1,12 @@ | |
+// Can't test this when 'make test' doesn't assign a tty to the stdout. | |
+var common = require('../common'); | |
+var assert = require('assert'); | |
+var tty = require('tty'); | |
+ | |
+assert.ok(process.stdin instanceof tty.ReadStream); | |
+assert.ok(process.stdin.readable); | |
+assert.ok(!process.stdin.writable); | |
+ | |
+assert.ok(process.stdout instanceof tty.WriteStream); | |
+assert.ok(!process.stdout.readable); | |
+assert.ok(process.stdout.writable); | |
-- | |
1.7.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment