diff options
author | isaacs <i@izs.me> | 2011-12-05 15:36:45 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-12-05 16:47:11 -0800 |
commit | cf20b6bf65bd037193d6e8b1b671c4659897861f (patch) | |
tree | 99dc0ef89117fdd90f2d8a3c33482451d0e18a3f /src/handle_wrap.cc | |
parent | 6f86b9cb70f4b4d9b214ef3533efbf389fa43824 (diff) | |
download | android-node-v8-cf20b6bf65bd037193d6e8b1b671c4659897861f.tar.gz android-node-v8-cf20b6bf65bd037193d6e8b1b671c4659897861f.tar.bz2 android-node-v8-cf20b6bf65bd037193d6e8b1b671c4659897861f.zip |
Fix #2257 pause/resume semantics for stdin
This makes it so that the stdin TTY-wrap stream gets ref'ed on
.resume() and unref'ed on .pause()
The semantics of the names "pause" and "resume" are a bit weird, but the
important thing is that this corrects an API change from 0.4 -> 0.6
which made it impossible to read from stdin multiple times, without
knowing when it might end up being closed. If no one has it open, this
lets the process die naturally.
LGTM'd by @ry
Diffstat (limited to 'src/handle_wrap.cc')
-rw-r--r-- | src/handle_wrap.cc | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 6e07643893..5b6594a3a9 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -64,8 +64,10 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) { UNWRAP - // Calling this function twice should never happen. - assert(wrap->unref == false); + // Calling unnecessarily is a no-op + if (wrap->unref) { + return v8::Undefined(); + } wrap->unref = true; uv_unref(uv_default_loop()); @@ -74,6 +76,24 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) { } +// Adds a reference to keep uv alive because of this thing. +Handle<Value> HandleWrap::Ref(const Arguments& args) { + HandleScope scope; + + UNWRAP + + // Calling multiple times is a no-op + if (!wrap->unref) { + return v8::Undefined(); + } + + wrap->unref = false; + uv_ref(uv_default_loop()); + + return v8::Undefined(); +} + + Handle<Value> HandleWrap::Close(const Arguments& args) { HandleScope scope; @@ -82,10 +102,8 @@ Handle<Value> HandleWrap::Close(const Arguments& args) { assert(!wrap->object_.IsEmpty()); uv_close(wrap->handle__, OnClose); - if (wrap->unref) { - uv_ref(uv_default_loop()); - wrap->unref = false; - } + + HandleWrap::Ref(args); wrap->StateChange(); |