Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[tty] unref on pause, ref on resume

  • Loading branch information...
commit 374ff71fee93cea61871838e245873811128af45 1 parent 1a89c8d
@indutny authored
View
12 lib/tty.js
@@ -81,6 +81,8 @@ function ReadStream(fd) {
if (!stdinHandle) stdinHandle = this._handle;
this.on('newListener', onNewListener);
+
+ this.pause();
}
inherits(ReadStream, net.Socket);
exports.ReadStream = ReadStream;
@@ -310,6 +312,16 @@ ReadStream.prototype._emitKey = function(s) {
}
};
+ReadStream.prototype.pause = function pause() {
+ this._handle.unref();
+ net.Socket.prototype.pause.call(this);
+};
+
+ReadStream.prototype.resume = function resume() {
+ this._handle.ref();
+ net.Socket.prototype.resume.call(this);
+};
+
function WriteStream(fd) {
if (!(this instanceof WriteStream)) return new WriteStream(fd);
View
14 src/handle_wrap.cc
@@ -73,6 +73,20 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) {
return v8::Undefined();
}
+Handle<Value> HandleWrap::Ref(const Arguments& args) {
+ HandleScope scope;
+
+ UNWRAP
+
+ // Calling this function twice should never happen.
+ assert(wrap->unref == true);
+
+ wrap->unref = false;
+ uv_ref(uv_default_loop());
+
+ return v8::Undefined();
+}
+
Handle<Value> HandleWrap::Close(const Arguments& args) {
HandleScope scope;
View
1  src/handle_wrap.h
@@ -49,6 +49,7 @@ class HandleWrap {
static void Initialize(v8::Handle<v8::Object> target);
static v8::Handle<v8::Value> Close(const v8::Arguments& args);
static v8::Handle<v8::Value> Unref(const v8::Arguments& args);
+ static v8::Handle<v8::Value> Ref(const v8::Arguments& args);
protected:
HandleWrap(v8::Handle<v8::Object> object, uv_handle_t* handle);
View
1  src/tty_wrap.cc
@@ -69,6 +69,7 @@ class TTYWrap : StreamWrap {
NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close);
NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref);
+ NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref);
NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart);
NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop);
Please sign in to comment.
Something went wrong with that request. Please try again.