@ -42,6 +42,15 @@ function createTCP() {
}
}
function createHandle ( fd ) {
var tty = process . binding ( 'tty_wrap' ) ;
var type = tty . guessHandleType ( fd ) ;
if ( type === 'PIPE' ) return createPipe ( ) ;
if ( type === 'TCP' ) return createTCP ( ) ;
throw new TypeError ( 'Unsupported fd type: ' + type ) ;
}
var debug ;
var debug ;
if ( process . env . NODE_DEBUG && /net/ . test ( process . env . NODE_DEBUG ) ) {
if ( process . env . NODE_DEBUG && /net/ . test ( process . env . NODE_DEBUG ) ) {
var pid = process . pid ;
var pid = process . pid ;
@ -144,7 +153,7 @@ function Socket(options) {
if ( options . handle ) {
if ( options . handle ) {
this . _ handle = options . handle ; // private
this . _ handle = options . handle ; // private
} else if ( typeof options . fd !== 'undefined' ) {
} else if ( typeof options . fd !== 'undefined' ) {
this . _ handle = createPipe ( ) ;
this . _ handle = createHandle ( options . fd ) ;
this . _ handle . open ( options . fd ) ;
this . _ handle . open ( options . fd ) ;
this . readable = options . readable !== false ;
this . readable = options . readable !== false ;
this . writable = options . writable !== false ;
this . writable = options . writable !== false ;
@ -930,26 +939,18 @@ var createServerHandle = exports._createServerHandle =
var handle ;
var handle ;
if ( typeof fd === 'number' && fd >= 0 ) {
if ( typeof fd === 'number' && fd >= 0 ) {
var tty_wrap = process . binding ( 'tty_wrap' ) ;
try {
var type = tty_wrap . guessHandleType ( fd ) ;
handle = createHandle ( fd ) ;
switch ( type ) {
}
case 'PIPE' :
catch ( e ) {
case 'TCP' :
// Not a fd we can listen on. This will trigger an error.
debug ( 'listen pipe fd=' + fd ) ;
debug ( 'listen invalid fd=' + fd + ': ' + e . message ) ;
// create a PipeWrap
process . _ errno = 'EINVAL' ; // hack, callers expect that errno is set
handle = createPipe ( ) ;
return null ;
handle . open ( fd ) ;
handle . readable = true ;
handle . writable = true ;
break ;
default :
// Not a fd we can listen on. This will trigger an error.
debug ( 'listen invalid fd=' + fd + ' type=' + type ) ;
process . _ errno = 'EINVAL' ; // hack, callers expect that errno is set
handle = null ;
break ;
}
}
handle . open ( fd ) ;
handle . readable = true ;
handle . writable = true ;
return handle ;
return handle ;
} else if ( port == - 1 && addressType == - 1 ) {
} else if ( port == - 1 && addressType == - 1 ) {