Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[tty] unref on pause, ref on resume

  • Loading branch information...
commit 374ff71fee93cea61871838e245873811128af45 1 parent 1a89c8d
Fedor Indutny authored
12 lib/tty.js
@@ -81,6 +81,8 @@ function ReadStream(fd) {
81 81 if (!stdinHandle) stdinHandle = this._handle;
82 82
83 83 this.on('newListener', onNewListener);
  84 +
  85 + this.pause();
84 86 }
85 87 inherits(ReadStream, net.Socket);
86 88 exports.ReadStream = ReadStream;
@@ -310,6 +312,16 @@ ReadStream.prototype._emitKey = function(s) {
310 312 }
311 313 };
312 314
  315 +ReadStream.prototype.pause = function pause() {
  316 + this._handle.unref();
  317 + net.Socket.prototype.pause.call(this);
  318 +};
  319 +
  320 +ReadStream.prototype.resume = function resume() {
  321 + this._handle.ref();
  322 + net.Socket.prototype.resume.call(this);
  323 +};
  324 +
313 325
314 326 function WriteStream(fd) {
315 327 if (!(this instanceof WriteStream)) return new WriteStream(fd);
14 src/handle_wrap.cc
@@ -73,6 +73,20 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) {
73 73 return v8::Undefined();
74 74 }
75 75
  76 +Handle<Value> HandleWrap::Ref(const Arguments& args) {
  77 + HandleScope scope;
  78 +
  79 + UNWRAP
  80 +
  81 + // Calling this function twice should never happen.
  82 + assert(wrap->unref == true);
  83 +
  84 + wrap->unref = false;
  85 + uv_ref(uv_default_loop());
  86 +
  87 + return v8::Undefined();
  88 +}
  89 +
76 90
77 91 Handle<Value> HandleWrap::Close(const Arguments& args) {
78 92 HandleScope scope;
1  src/handle_wrap.h
@@ -49,6 +49,7 @@ class HandleWrap {
49 49 static void Initialize(v8::Handle<v8::Object> target);
50 50 static v8::Handle<v8::Value> Close(const v8::Arguments& args);
51 51 static v8::Handle<v8::Value> Unref(const v8::Arguments& args);
  52 + static v8::Handle<v8::Value> Ref(const v8::Arguments& args);
52 53
53 54 protected:
54 55 HandleWrap(v8::Handle<v8::Object> object, uv_handle_t* handle);
1  src/tty_wrap.cc
@@ -69,6 +69,7 @@ class TTYWrap : StreamWrap {
69 69
70 70 NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close);
71 71 NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref);
  72 + NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref);
72 73
73 74 NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart);
74 75 NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop);

0 comments on commit 374ff71

Please sign in to comment.
Something went wrong with that request. Please try again.