@ -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' :
debug ( 'listen pipe fd=' + fd ) ;
// create a PipeWrap
handle = createPipe ( ) ;
handle . open ( fd ) ;
handle . readable = true ;
handle . writable = true ;
break ;
default :
// Not a fd we can listen on. This will trigger an error.
// Not a fd we can listen on. This will trigger an error.
debug ( 'listen invalid fd=' + fd + ' type= ' + typ e) ;
debug ( 'listen invalid fd=' + fd + ': ' + e . message ) ;
process . _ errno = 'EINVAL' ; // hack, callers expect that errno is set
process . _ errno = 'EINVAL' ; // hack, callers expect that errno is set
handle = null ;
return 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 ) {