@ -999,6 +999,12 @@ exports.Server = Server;
function toNumber ( x ) { return ( x = Number ( x ) ) >= 0 ? x : false ; }
function toNumber ( x ) { return ( x = Number ( x ) ) >= 0 ? x : false ; }
function _ listen ( handle , backlog ) {
// Use a backlog of 512 entries. We pass 511 to the listen() call because
// the kernel does: backlogsize = roundup_pow_of_two(backlogsize + 1);
// which will thus give us a backlog of 512 entries.
return handle . listen ( backlog || 511 ) ;
}
var createServerHandle = exports . _ createServerHandle =
var createServerHandle = exports . _ createServerHandle =
function ( address , port , addressType , fd ) {
function ( address , port , addressType , fd ) {
@ -1046,6 +1052,17 @@ var createServerHandle = exports._createServerHandle =
return err ;
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 ;
return handle ;
} ;
} ;
@ -1054,6 +1071,8 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
debug ( 'listen2' , address , port , addressType , backlog ) ;
debug ( 'listen2' , address , port , addressType , backlog ) ;
var self = this ;
var self = this ;
var alreadyListening = false ;
// If there is not yet a handle, we need to create one and bind.
// 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.
// In the case of a server sent via IPC, we don't need to do this.
if ( ! self . _ handle ) {
if ( ! self . _ handle ) {
@ -1066,6 +1085,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
} ) ;
} ) ;
return ;
return ;
}
}
alreadyListening = ( process . platform === 'win32' ) ;
self . _ handle = rval ;
self . _ handle = rval ;
} else {
} else {
debug ( '_listen2: have a handle already' ) ;
debug ( '_listen2: have a handle already' ) ;
@ -1074,10 +1094,9 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
self . _ handle . onconnection = onconnection ;
self . _ handle . onconnection = onconnection ;
self . _ handle . owner = self ;
self . _ handle . owner = self ;
// Use a backlog of 512 entries. We pass 511 to the listen() call because
var err = 0 ;
// the kernel does: backlogsize = roundup_pow_of_two(backlogsize + 1);
if ( ! alreadyListening )
// which will thus give us a backlog of 512 entries.
err = _ listen ( self . _ handle , backlog ) ;
var err = self . _ handle . listen ( backlog || 511 ) ;
if ( err ) {
if ( err ) {
var ex = errnoException ( err , 'listen' ) ;
var ex = errnoException ( err , 'listen' ) ;