Revert "Cluster: fix shared handles on Windows"
authorFedor Indutny <fedor@indutny.com>
Thu, 31 Jul 2014 08:38:46 +0000 (12:38 +0400)
committerFedor Indutny <fedor@indutny.com>
Thu, 31 Jul 2014 08:38:46 +0000 (12:38 +0400)
This reverts commit 4e68a28e20b348f3519b359a17fcb941b235202b.

lib/net.js

index f379d8d..1877e42 100644 (file)
@@ -1080,6 +1080,17 @@ var createServerHandle = exports._createServerHandle =
     return err;
   }
 
+  if (process.platform === 'win32') {
+    // On Windows, we always listen to the socket before sending it to
+    // the worker (see uv_tcp_duplicate_socket). So we better do it here
+    // so that we can handle any bind-time or listen-time errors early.
+    err = _listen(handle);
+    if (err) {
+      handle.close();
+      return err;
+    }
+  }
+
   return handle;
 };
 
@@ -1088,6 +1099,8 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
   debug('listen2', address, port, addressType, backlog);
   var self = this;
 
+  var alreadyListening = false;
+
   // If there is not yet a handle, we need to create one and bind.
   // In the case of a server sent via IPC, we don't need to do this.
   if (!self._handle) {
@@ -1100,6 +1113,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
       });
       return;
     }
+    alreadyListening = (process.platform === 'win32');
     self._handle = rval;
   } else {
     debug('_listen2: have a handle already');
@@ -1108,7 +1122,9 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
   self._handle.onconnection = onconnection;
   self._handle.owner = self;
 
-  var err = _listen(self._handle, backlog);
+  var err = 0;
+  if (!alreadyListening)
+    err = _listen(self._handle, backlog);
 
   if (err) {
     var ex = errnoException(err, 'listen');