Add 'opening' readyState
authorRyan Dahl <ry@tinyclouds.org>
Thu, 18 Mar 2010 21:33:42 +0000 (14:33 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 18 Mar 2010 21:33:42 +0000 (14:33 -0700)
lib/net.js

index 77949e0..ed74679 100644 (file)
@@ -4,10 +4,8 @@ var events = require("events");
 
 var debugLevel = 0;
 if ('NODE_DEBUG' in process.ENV) debugLevel = 1;
-function debug (x) {
-  if (debugLevel > 0) {
-    process.stdio.writeError(x + '\n');
-  }
+function debug () {
+  if (debugLevel > 0) sys.error.apply(this, arguments);
 }
 
 var binding = process.binding('net');
@@ -400,7 +398,9 @@ Object.defineProperty(Stream.prototype, 'readyState', {
       readyStateMessage = 'readyState is depricated. Use stream.readable or stream.writable';
       sys.error(readyStateMessage);
     }
-    if (this.readable && this.writable) {
+    if (this._resolving) {
+      return 'opening';
+    } else if (this.readable && this.writable) {
       return 'open';
     } else if (this.readable && !this.writable){
       return 'readOnly';
@@ -658,7 +658,9 @@ Stream.prototype.connect = function () {
     self.type = 'tcp';
     // TODO dns resolution on arguments[1]
     var port = arguments[0];
+    self._resolving = true;
     lookupDomainName(arguments[1], function (ip) {
+      self._resolving = false;
       doConnect(self, port, ip);
     });
   } else {