set readable/writable for pipes
authorIgor Zinkovsky <igorzi@microsoft.com>
Fri, 10 Feb 2012 09:35:35 +0000 (01:35 -0800)
committerIgor Zinkovsky <igorzi@microsoft.com>
Fri, 10 Feb 2012 19:28:43 +0000 (11:28 -0800)
lib/net.js
src/pipe_wrap.cc
src/tcp_wrap.cc

index 48129a9c8b4fae924cd0b95ce7b5fde72ffbabea..e41e96ae1d386a9d7fb5ca9c1fb2d6d5d100be8b 100644 (file)
@@ -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');
 
index 1870837bcaea529c814f36467e33b54e87bd4220..6c3887d84f65fa0878610cffd40f1513bcf53571 100644 (file)
@@ -53,6 +53,7 @@ using v8::TryCatch;
 using v8::Context;
 using v8::Arguments;
 using v8::Integer;
+using v8::Boolean;
 
 Persistent<Function> 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<Value> argv[3] = {
+  Local<Value> argv[5] = {
     Integer::New(status),
     Local<Value>::New(wrap->object_),
-    Local<Value>::New(req_wrap->object_)
+    Local<Value>::New(req_wrap->object_),
+    Local<Value>::New(Boolean::New(readable)),
+    Local<Value>::New(Boolean::New(writable))
   };
 
-  MakeCallback(req_wrap->object_, "oncomplete", 3, argv);
+  MakeCallback(req_wrap->object_, "oncomplete", 5, argv);
 
   delete req_wrap;
 }
index b2b8c5cd56315fc8cc926889ffbac933616331ec..688d7d71902abc91cd328b043896275bbd539860 100644 (file)
@@ -396,13 +396,15 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
     SetErrno(uv_last_error(uv_default_loop()));
   }
 
-  Local<Value> argv[3] = {
+  Local<Value> argv[5] = {
     Integer::New(status),
     Local<Value>::New(wrap->object_),
-    Local<Value>::New(req_wrap->object_)
+    Local<Value>::New(req_wrap->object_),
+    Local<Value>::New(v8::True()),
+    Local<Value>::New(v8::True())
   };
 
-  MakeCallback(req_wrap->object_, "oncomplete", 3, argv);
+  MakeCallback(req_wrap->object_, "oncomplete", 5, argv);
 
   delete req_wrap;
 }