From c7771bc2ec74afb8b9e239c34c183c92e10acd87 Mon Sep 17 00:00:00 2001 From: Igor Zinkovsky Date: Fri, 10 Feb 2012 01:35:35 -0800 Subject: [PATCH] set readable/writable for pipes --- lib/net.js | 9 ++++++--- src/pipe_wrap.cc | 15 ++++++++++++--- src/tcp_wrap.cc | 8 +++++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/net.js b/lib/net.js index 48129a9c8..e41e96ae1 100644 --- a/lib/net.js +++ b/lib/net.js @@ -593,7 +593,7 @@ Socket.prototype.connect = function(port /* [host], [cb] */) { }; -function afterConnect(status, handle, req) { +function afterConnect(status, handle, req, readable, writable) { var self = handle.socket; // callback may come after call to destroy @@ -609,10 +609,13 @@ function afterConnect(status, handle, req) { self._connecting = false; if (status == 0) { - self.readable = self.writable = true; + self.readable = readable; + self.writable = writable; timers.active(self); - handle.readStart(); + if (self.readable) { + handle.readStart(); + } self.emit('connect'); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 1870837bc..6c3887d84 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -53,6 +53,7 @@ using v8::TryCatch; using v8::Context; using v8::Arguments; using v8::Integer; +using v8::Boolean; Persistent pipeConstructor; @@ -224,17 +225,25 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) { assert(req_wrap->object_.IsEmpty() == false); assert(wrap->object_.IsEmpty() == false); + bool readable, writable; + if (status) { SetErrno(uv_last_error(uv_default_loop())); + readable = writable = 0; + } else { + readable = uv_is_readable(req->handle) != 0; + writable = uv_is_writable(req->handle) != 0; } - Local argv[3] = { + Local argv[5] = { Integer::New(status), Local::New(wrap->object_), - Local::New(req_wrap->object_) + Local::New(req_wrap->object_), + Local::New(Boolean::New(readable)), + Local::New(Boolean::New(writable)) }; - MakeCallback(req_wrap->object_, "oncomplete", 3, argv); + MakeCallback(req_wrap->object_, "oncomplete", 5, argv); delete req_wrap; } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index b2b8c5cd5..688d7d719 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -396,13 +396,15 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) { SetErrno(uv_last_error(uv_default_loop())); } - Local argv[3] = { + Local argv[5] = { Integer::New(status), Local::New(wrap->object_), - Local::New(req_wrap->object_) + Local::New(req_wrap->object_), + Local::New(v8::True()), + Local::New(v8::True()) }; - MakeCallback(req_wrap->object_, "oncomplete", 3, argv); + MakeCallback(req_wrap->object_, "oncomplete", 5, argv); delete req_wrap; } -- 2.34.1